base-address.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. //
  3. // Copyright (C) 2019 Socionext Inc.
  4. // Author: Masahiro Yamada <yamada.masahiro@socionext.com>
  5. #include <dm/of.h>
  6. #include <fdt_support.h>
  7. #include <linux/errno.h>
  8. #include <linux/io.h>
  9. #include <linux/libfdt.h>
  10. #include <linux/sizes.h>
  11. #include <asm/global_data.h>
  12. #include "base-address.h"
  13. #include "sc64-regs.h"
  14. #include "sg-regs.h"
  15. /*
  16. * Dummy initializers are needed to allocate these to .data section instead of
  17. * .bss section. The .bss section is unusable before relocation because the
  18. * .bss section and DT share the same address. Without the initializers,
  19. * DT would be broken.
  20. */
  21. void __iomem *sc_base = (void *)0xdeadbeef;
  22. void __iomem *sg_base = (void *)0xdeadbeef;
  23. static u64 uniphier_base_address_get(const char *compat_tail)
  24. {
  25. DECLARE_GLOBAL_DATA_PTR;
  26. const void *fdt = gd->fdt_blob;
  27. int offset, len, i;
  28. const char *str;
  29. for (offset = fdt_next_node(fdt, 0, NULL);
  30. offset >= 0;
  31. offset = fdt_next_node(fdt, offset, NULL)) {
  32. for (i = 0;
  33. (str = fdt_stringlist_get(fdt, offset, "compatible", i, &len));
  34. i++) {
  35. if (!memcmp(compat_tail,
  36. str + len - strlen(compat_tail),
  37. strlen(compat_tail)))
  38. return fdt_get_base_address(fdt, offset);
  39. }
  40. }
  41. return OF_BAD_ADDR;
  42. }
  43. int uniphier_base_address_init(void)
  44. {
  45. u64 base;
  46. base = uniphier_base_address_get("-soc-glue");
  47. if (base == OF_BAD_ADDR)
  48. return -EINVAL;
  49. sg_base = ioremap(base, SZ_8K);
  50. base = uniphier_base_address_get("-sysctrl");
  51. if (base == OF_BAD_ADDR)
  52. return -EINVAL;
  53. sc_base = ioremap(base, SZ_64K);
  54. return 0;
  55. }