of_rtc.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 <[email protected]>, 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. #include <asm/prom.h>
  14. static __initdata struct {
  15. const char *compatible;
  16. char *plat_name;
  17. } of_rtc_table[] = {
  18. { "ds1743-nvram", "rtc-ds1742" },
  19. };
  20. void __init of_instantiate_rtc(void)
  21. {
  22. struct device_node *node;
  23. int err;
  24. int i;
  25. for (i = 0; i < ARRAY_SIZE(of_rtc_table); i++) {
  26. char *plat_name = of_rtc_table[i].plat_name;
  27. for_each_compatible_node(node, NULL,
  28. of_rtc_table[i].compatible) {
  29. struct resource *res;
  30. res = kmalloc(sizeof(*res), GFP_KERNEL);
  31. if (!res) {
  32. printk(KERN_ERR "OF RTC: Out of memory "
  33. "allocating resource structure for %pOF\n",
  34. node);
  35. continue;
  36. }
  37. err = of_address_to_resource(node, 0, res);
  38. if (err) {
  39. printk(KERN_ERR "OF RTC: Error "
  40. "translating resources for %pOF\n",
  41. node);
  42. continue;
  43. }
  44. printk(KERN_INFO "OF_RTC: %pOF is a %s @ 0x%llx-0x%llx\n",
  45. node, plat_name,
  46. (unsigned long long)res->start,
  47. (unsigned long long)res->end);
  48. platform_device_register_simple(plat_name, -1, res, 1);
  49. }
  50. }
  51. }