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 "pmc.h"
  13. DECLARE_GLOBAL_DATA_PTR;
  14. static const struct udevice_id at91_pmc_match[] = {
  15. { .compatible = "atmel,sama5d2-pmc" },
  16. {}
  17. };
  18. U_BOOT_DRIVER(at91_pmc) = {
  19. .name = "at91-pmc",
  20. .id = UCLASS_SIMPLE_BUS,
  21. .of_match = at91_pmc_match,
  22. };
  23. /*---------------------------------------------------------*/
  24. int at91_pmc_core_probe(struct udevice *dev)
  25. {
  26. struct pmc_platdata *plat = dev_get_platdata(dev);
  27. dev = dev_get_parent(dev);
  28. plat->reg_base = (struct at91_pmc *)dev_get_addr_ptr(dev);
  29. return 0;
  30. }
  31. /**
  32. * at91_clk_sub_device_bind() - for the at91 clock driver
  33. * Recursively bind its children as clk devices.
  34. *
  35. * @return: 0 on success, or negative error code on failure
  36. */
  37. int at91_clk_sub_device_bind(struct udevice *dev, const char *drv_name)
  38. {
  39. const void *fdt = gd->fdt_blob;
  40. int offset = dev_of_offset(dev);
  41. bool pre_reloc_only = !(gd->flags & GD_FLG_RELOC);
  42. const char *name;
  43. int ret;
  44. for (offset = fdt_first_subnode(fdt, offset);
  45. offset > 0;
  46. offset = fdt_next_subnode(fdt, offset)) {
  47. if (pre_reloc_only &&
  48. !fdt_getprop(fdt, offset, "u-boot,dm-pre-reloc", NULL))
  49. continue;
  50. /*
  51. * If this node has "compatible" property, this is not
  52. * a clock sub-node, but a normal device. skip.
  53. */
  54. fdt_get_property(fdt, offset, "compatible", &ret);
  55. if (ret >= 0)
  56. continue;
  57. if (ret != -FDT_ERR_NOTFOUND)
  58. return ret;
  59. name = fdt_get_name(fdt, offset, NULL);
  60. if (!name)
  61. return -EINVAL;
  62. ret = device_bind_driver_to_node(dev, drv_name, name,
  63. offset, NULL);
  64. if (ret)
  65. return ret;
  66. }
  67. return 0;
  68. }
  69. int at91_clk_of_xlate(struct clk *clk, struct fdtdec_phandle_args *args)
  70. {
  71. int periph;
  72. if (args->args_count) {
  73. debug("Invalid args_count: %d\n", args->args_count);
  74. return -EINVAL;
  75. }
  76. periph = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(clk->dev), "reg",
  77. -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. }