pmc.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2016 Atmel Corporation
  3. * Wenyou.Yang <wenyou.yang@atmel.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <clk-uclass.h>
  9. #include <dm/device.h>
  10. #include <dm/lists.h>
  11. #include <dm/root.h>
  12. #include <dm/util.h>
  13. #include "pmc.h"
  14. DECLARE_GLOBAL_DATA_PTR;
  15. static const struct udevice_id at91_pmc_match[] = {
  16. { .compatible = "atmel,sama5d2-pmc" },
  17. {}
  18. };
  19. U_BOOT_DRIVER(at91_pmc) = {
  20. .name = "at91-pmc",
  21. .id = UCLASS_SIMPLE_BUS,
  22. .of_match = at91_pmc_match,
  23. };
  24. /*---------------------------------------------------------*/
  25. int at91_pmc_core_probe(struct udevice *dev)
  26. {
  27. struct pmc_platdata *plat = dev_get_platdata(dev);
  28. dev = dev_get_parent(dev);
  29. plat->reg_base = (struct at91_pmc *)dev_get_addr_ptr(dev);
  30. return 0;
  31. }
  32. /**
  33. * at91_clk_sub_device_bind() - for the at91 clock driver
  34. * Recursively bind its children as clk devices.
  35. *
  36. * @return: 0 on success, or negative error code on failure
  37. */
  38. int at91_clk_sub_device_bind(struct udevice *dev, const char *drv_name)
  39. {
  40. const void *fdt = gd->fdt_blob;
  41. int offset = dev->of_offset;
  42. bool pre_reloc_only = !(gd->flags & GD_FLG_RELOC);
  43. const char *name;
  44. int ret;
  45. for (offset = fdt_first_subnode(fdt, offset);
  46. offset > 0;
  47. offset = fdt_next_subnode(fdt, offset)) {
  48. if (pre_reloc_only &&
  49. !dm_fdt_pre_reloc(fdt, offset))
  50. continue;
  51. /*
  52. * If this node has "compatible" property, this is not
  53. * a clock sub-node, but a normal device. skip.
  54. */
  55. fdt_get_property(fdt, offset, "compatible", &ret);
  56. if (ret >= 0)
  57. continue;
  58. if (ret != -FDT_ERR_NOTFOUND)
  59. return ret;
  60. name = fdt_get_name(fdt, offset, NULL);
  61. if (!name)
  62. return -EINVAL;
  63. ret = device_bind_driver_to_node(dev, drv_name, name,
  64. offset, NULL);
  65. if (ret)
  66. return ret;
  67. }
  68. return 0;
  69. }
  70. int at91_clk_of_xlate(struct clk *clk, struct fdtdec_phandle_args *args)
  71. {
  72. int periph;
  73. if (args->args_count) {
  74. debug("Invalid args_count: %d\n", args->args_count);
  75. return -EINVAL;
  76. }
  77. periph = fdtdec_get_uint(gd->fdt_blob, clk->dev->of_offset, "reg", -1);
  78. if (periph < 0)
  79. return -EINVAL;
  80. clk->id = periph;
  81. return 0;
  82. }
  83. int at91_clk_probe(struct udevice *dev)
  84. {
  85. struct udevice *dev_periph_container, *dev_pmc;
  86. struct pmc_platdata *plat = dev_get_platdata(dev);
  87. dev_periph_container = dev_get_parent(dev);
  88. dev_pmc = dev_get_parent(dev_periph_container);
  89. plat->reg_base = (struct at91_pmc *)dev_get_addr_ptr(dev_pmc);
  90. return 0;
  91. }