fdt.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <watchdog.h>
  9. #include <command.h>
  10. #include <asm/cache.h>
  11. #include <asm/ppc4xx.h>
  12. #ifdef CONFIG_OF_BOARD_SETUP
  13. #include <libfdt.h>
  14. #include <fdt_support.h>
  15. #include <asm/4xx_pcie.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. int __ft_board_setup(void *blob, bd_t *bd)
  18. {
  19. int rc;
  20. int i;
  21. u32 bxcr;
  22. u32 ranges[EBC_NUM_BANKS * 4];
  23. u32 *p = ranges;
  24. char ebc_path[] = "/plb/opb/ebc";
  25. ft_cpu_setup(blob, bd);
  26. /*
  27. * Read 4xx EBC bus bridge registers to get mappings of the
  28. * peripheral banks into the OPB/PLB address space
  29. */
  30. for (i = 0; i < EBC_NUM_BANKS; i++) {
  31. mtdcr(EBC0_CFGADDR, EBC_BXCR(i));
  32. bxcr = mfdcr(EBC0_CFGDATA);
  33. if ((bxcr & EBC_BXCR_BU_MASK) != EBC_BXCR_BU_NONE) {
  34. *p++ = i;
  35. *p++ = 0;
  36. *p++ = bxcr & EBC_BXCR_BAS_MASK;
  37. *p++ = EBC_BXCR_BANK_SIZE(bxcr);
  38. }
  39. }
  40. #ifdef CONFIG_FDT_FIXUP_NOR_FLASH_SIZE
  41. /* Update reg property in all nor flash nodes too */
  42. fdt_fixup_nor_flash_size(blob);
  43. #endif
  44. /* Some 405 PPC's have EBC as direct PLB child in the dts */
  45. if (fdt_path_offset(blob, ebc_path) < 0)
  46. strcpy(ebc_path, "/plb/ebc");
  47. rc = fdt_find_and_setprop(blob, ebc_path, "ranges", ranges,
  48. (p - ranges) * sizeof(u32), 1);
  49. if (rc) {
  50. printf("Unable to update property EBC mappings, err=%s\n",
  51. fdt_strerror(rc));
  52. }
  53. return 0;
  54. }
  55. int ft_board_setup(void *blob, bd_t *bd)
  56. __attribute__((weak, alias("__ft_board_setup")));
  57. /*
  58. * Fixup all PCIe nodes by setting the device_type property
  59. * to "pci-endpoint" instead is "pci" for endpoint ports.
  60. * This property will get checked later by the Linux driver
  61. * to properly configure the PCIe port in Linux (again).
  62. */
  63. void fdt_pcie_setup(void *blob)
  64. {
  65. const char *compat = "ibm,plb-pciex";
  66. const char *prop = "device_type";
  67. const char *prop_val = "pci-endpoint";
  68. const u32 *port;
  69. int no;
  70. int rc;
  71. /* Search first PCIe node */
  72. no = fdt_node_offset_by_compatible(blob, -1, compat);
  73. while (no != -FDT_ERR_NOTFOUND) {
  74. port = fdt_getprop(blob, no, "port", NULL);
  75. if (port == NULL) {
  76. printf("WARNING: could not find port property\n");
  77. } else {
  78. if (is_end_point(*port)) {
  79. rc = fdt_setprop(blob, no, prop, prop_val,
  80. strlen(prop_val) + 1);
  81. if (rc < 0)
  82. printf("WARNING: could not set %s for %s: %s.\n",
  83. prop, compat, fdt_strerror(rc));
  84. }
  85. }
  86. /* Jump to next PCIe node */
  87. no = fdt_node_offset_by_compatible(blob, no, compat);
  88. }
  89. }
  90. void ft_cpu_setup(void *blob, bd_t *bd)
  91. {
  92. sys_info_t sys_info;
  93. int off, ndepth = 0;
  94. get_sys_info(&sys_info);
  95. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "timebase-frequency",
  96. bd->bi_intfreq, 1);
  97. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "clock-frequency",
  98. bd->bi_intfreq, 1);
  99. do_fixup_by_path_u32(blob, "/plb", "clock-frequency", sys_info.freqPLB, 1);
  100. do_fixup_by_path_u32(blob, "/plb/opb", "clock-frequency", sys_info.freqOPB, 1);
  101. if (fdt_path_offset(blob, "/plb/opb/ebc") >= 0)
  102. do_fixup_by_path_u32(blob, "/plb/opb/ebc", "clock-frequency",
  103. sys_info.freqEBC, 1);
  104. else
  105. do_fixup_by_path_u32(blob, "/plb/ebc", "clock-frequency",
  106. sys_info.freqEBC, 1);
  107. fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
  108. /*
  109. * Fixup all UART clocks for CPU internal UARTs
  110. * (only these UARTs are definitely clocked by gd->arch.uart_clk)
  111. *
  112. * These UARTs are direct childs of /plb/opb. This code
  113. * does not touch any UARTs that are connected to the ebc.
  114. */
  115. off = fdt_path_offset(blob, "/plb/opb");
  116. while ((off = fdt_next_node(blob, off, &ndepth)) >= 0) {
  117. /*
  118. * process all sub nodes and stop when we are back
  119. * at the starting depth
  120. */
  121. if (ndepth <= 0)
  122. break;
  123. /* only update direct childs */
  124. if ((ndepth == 1) &&
  125. (fdt_node_check_compatible(blob, off, "ns16550") == 0))
  126. fdt_setprop(blob, off,
  127. "clock-frequency",
  128. (void *)&gd->arch.uart_clk, 4);
  129. }
  130. /*
  131. * Fixup all ethernet nodes
  132. * Note: aliases in the dts are required for this
  133. */
  134. fdt_fixup_ethernet(blob);
  135. /*
  136. * Fixup all available PCIe nodes by setting the device_type property
  137. */
  138. fdt_pcie_setup(blob);
  139. }
  140. #endif /* CONFIG_OF_BOARD_SETUP */