diff options
Diffstat (limited to 'arch/arm/plat-omap/omap_device.c')
-rw-r--r-- | arch/arm/plat-omap/omap_device.c | 313 |
1 files changed, 264 insertions, 49 deletions
diff --git a/arch/arm/plat-omap/omap_device.c b/arch/arm/plat-omap/omap_device.c index 26aee5cc1fc1..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> |
@@ -96,6 +98,20 @@ | |||
96 | 98 | ||
97 | static int omap_device_register(struct platform_device *pdev); | 99 | static int omap_device_register(struct platform_device *pdev); |
98 | static int omap_early_device_register(struct platform_device *pdev); | 100 | static int omap_early_device_register(struct platform_device *pdev); |
101 | static 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); | ||
105 | static void omap_device_delete(struct omap_device *od); | ||
106 | |||
107 | |||
108 | static 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 | }; | ||
99 | 115 | ||
100 | /* Private functions */ | 116 | /* Private functions */ |
101 | 117 | ||
@@ -303,6 +319,96 @@ static void _add_hwmod_clocks_clkdev(struct omap_device *od, | |||
303 | } | 319 | } |
304 | 320 | ||
305 | 321 | ||
322 | static 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 | */ | ||
339 | static 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 | |||
385 | odbfd_exit1: | ||
386 | kfree(hwmods); | ||
387 | odbfd_exit: | ||
388 | return ret; | ||
389 | } | ||
390 | |||
391 | static 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 | |||
306 | /* Public functions for use by core code */ | 412 | /* Public functions for use by core code */ |
307 | 413 | ||
308 | /** | 414 | /** |
@@ -389,6 +495,113 @@ static int omap_device_fill_resources(struct omap_device *od, | |||
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 | */ | ||
511 | static 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 | |||
583 | oda_exit3: | ||
584 | kfree(hwmods); | ||
585 | oda_exit2: | ||
586 | kfree(od); | ||
587 | oda_exit1: | ||
588 | dev_err(&pdev->dev, "omap_device: build failed (%d)\n", ret); | ||
589 | |||
590 | return ERR_PTR(ret); | ||
591 | } | ||
592 | |||
593 | static 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 |
@@ -447,9 +660,6 @@ struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id, | |||
447 | int ret = -ENOMEM; | 660 | int ret = -ENOMEM; |
448 | struct platform_device *pdev; | 661 | struct platform_device *pdev; |
449 | struct omap_device *od; | 662 | struct omap_device *od; |
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); |
@@ -463,67 +673,31 @@ struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id, | |||
463 | goto odbs_exit; | 673 | goto odbs_exit; |
464 | } | 674 | } |
465 | 675 | ||
466 | pr_debug("omap_device: %s: building with %d hwmods\n", pdev_name, | 676 | /* Set the dev_name early to allow dev_xxx in omap_device_alloc */ |
467 | oh_cnt); | 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 | od = kzalloc(sizeof(struct omap_device), GFP_KERNEL); | 682 | od = omap_device_alloc(pdev, ohs, oh_cnt, pm_lats, pm_lats_cnt); |
470 | if (!od) { | 683 | if (!od) |
471 | ret = -ENOMEM; | ||
472 | goto odbs_exit1; | 684 | goto odbs_exit1; |
473 | } | ||
474 | od->hwmods_cnt = oh_cnt; | ||
475 | |||
476 | hwmods = kzalloc(sizeof(struct omap_hwmod *) * oh_cnt, | ||
477 | GFP_KERNEL); | ||
478 | if (!hwmods) | ||
479 | goto odbs_exit2; | ||
480 | |||
481 | memcpy(hwmods, ohs, sizeof(struct omap_hwmod *) * oh_cnt); | ||
482 | od->hwmods = hwmods; | ||
483 | od->pdev = pdev; | ||
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 | ret = platform_device_add_resources(pdev, res, res_count); | ||
494 | kfree(res); | ||
495 | |||
496 | if (ret) | ||
497 | goto odbs_exit3; | ||
498 | } | ||
499 | 685 | ||
500 | ret = platform_device_add_data(pdev, pdata, pdata_len); | 686 | ret = platform_device_add_data(pdev, pdata, pdata_len); |
501 | if (ret) | 687 | if (ret) |
502 | goto odbs_exit3; | 688 | goto odbs_exit2; |
503 | |||
504 | pdev->archdata.od = od; | ||
505 | 689 | ||
506 | if (is_early_device) | 690 | if (is_early_device) |
507 | ret = omap_early_device_register(pdev); | 691 | ret = omap_early_device_register(pdev); |
508 | else | 692 | else |
509 | ret = omap_device_register(pdev); | 693 | ret = omap_device_register(pdev); |
510 | if (ret) | 694 | if (ret) |
511 | goto odbs_exit3; | 695 | goto odbs_exit2; |
512 | |||
513 | od->pm_lats = pm_lats; | ||
514 | od->pm_lats_cnt = pm_lats_cnt; | ||
515 | |||
516 | for (i = 0; i < oh_cnt; i++) { | ||
517 | hwmods[i]->od = od; | ||
518 | _add_hwmod_clocks_clkdev(od, hwmods[i]); | ||
519 | } | ||
520 | 696 | ||
521 | return pdev; | 697 | return pdev; |
522 | 698 | ||
523 | odbs_exit3: | ||
524 | kfree(hwmods); | ||
525 | odbs_exit2: | 699 | odbs_exit2: |
526 | kfree(od); | 700 | omap_device_delete(od); |
527 | odbs_exit1: | 701 | odbs_exit1: |
528 | platform_device_put(pdev); | 702 | platform_device_put(pdev); |
529 | odbs_exit: | 703 | odbs_exit: |
@@ -844,6 +1018,42 @@ void __iomem *omap_device_get_rt_va(struct omap_device *od) | |||
844 | return omap_hwmod_get_mpu_rt_va(od->hwmods[0]); | 1018 | return omap_hwmod_get_mpu_rt_va(od->hwmods[0]); |
845 | } | 1019 | } |
846 | 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 | */ | ||
1029 | struct 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 | } | ||
1055 | EXPORT_SYMBOL(omap_device_get_by_hwmod_name); | ||
1056 | |||
847 | /* | 1057 | /* |
848 | * Public functions intended for use in omap_device_pm_latency | 1058 | * Public functions intended for use in omap_device_pm_latency |
849 | * .activate_func and .deactivate_func function pointers | 1059 | * .activate_func and .deactivate_func function pointers |
@@ -924,8 +1134,13 @@ struct device omap_device_parent = { | |||
924 | .parent = &platform_bus, | 1134 | .parent = &platform_bus, |
925 | }; | 1135 | }; |
926 | 1136 | ||
1137 | static struct notifier_block platform_nb = { | ||
1138 | .notifier_call = _omap_device_notifier_call, | ||
1139 | }; | ||
1140 | |||
927 | static int __init omap_device_init(void) | 1141 | static int __init omap_device_init(void) |
928 | { | 1142 | { |
1143 | bus_register_notifier(&platform_bus_type, &platform_nb); | ||
929 | return device_register(&omap_device_parent); | 1144 | return device_register(&omap_device_parent); |
930 | } | 1145 | } |
931 | core_initcall(omap_device_init); | 1146 | core_initcall(omap_device_init); |