of_rtc.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Instantiate mmio-mapped RTC chips based on device tree information
  4. *
  5. * Copyright 2007 David Gibson <dwg@au1.ibm.com>, IBM Corporation.
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/of.h>
  9. #include <linux/init.h>
  10. #include <linux/of_address.h>
  11. #include <linux/of_platform.h>
  12. #include <linux/slab.h>
  13. static __initdata struct {
  14. const char *compatible;
  15. char *plat_name;
  16. } of_rtc_table[] = {
  17. { "ds1743-nvram", "rtc-ds1742" },
  18. };
  19. void __init of_instantiate_rtc(void)
  20. {
  21. struct device_node *node;
  22. int err;
  23. int i;
  24. for (i = 0; i < ARRAY_SIZE(of_rtc_table); i++) {
  25. char *plat_name = of_rtc_table[i].plat_name;
  26. for_each_compatible_node(node, NULL,
  27. of_rtc_table[i].compatible) {
  28. struct resource *res;
  29. res = kmalloc(sizeof(*res), GFP_KERNEL);
  30. if (!res) {
  31. printk(KERN_ERR "OF RTC: Out of memory "
  32. "allocating resource structure for %pOF\n",
  33. node);
  34. continue;
  35. }
  36. err = of_address_to_resource(node, 0, res);
  37. if (err) {
  38. printk(KERN_ERR "OF RTC: Error "
  39. "translating resources for %pOF\n",
  40. node);
  41. continue;
  42. }
  43. printk(KERN_INFO "OF_RTC: %pOF is a %s @ 0x%llx-0x%llx\n",
  44. node, plat_name,
  45. (unsigned long long)res->start,
  46. (unsigned long long)res->end);
  47. platform_device_register_simple(plat_name, -1, res, 1);
  48. }
  49. }
  50. }