fdt.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <watchdog.h>
  25. #include <command.h>
  26. #include <asm/cache.h>
  27. #include <ppc4xx.h>
  28. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  29. #include <libfdt.h>
  30. #include <libfdt_env.h>
  31. #include <fdt_support.h>
  32. #include <asm/4xx_pcie.h>
  33. DECLARE_GLOBAL_DATA_PTR;
  34. void __ft_board_setup(void *blob, bd_t *bd)
  35. {
  36. int rc;
  37. int i;
  38. u32 bxcr;
  39. u32 ranges[EBC_NUM_BANKS * 4];
  40. u32 *p = ranges;
  41. char *ebc_path = "/plb/opb/ebc";
  42. ft_cpu_setup(blob, bd);
  43. /*
  44. * Read 4xx EBC bus bridge registers to get mappings of the
  45. * peripheral banks into the OPB/PLB address space
  46. */
  47. for (i = 0; i < EBC_NUM_BANKS; i++) {
  48. mtdcr(ebccfga, EBC_BXCR(i));
  49. bxcr = mfdcr(ebccfgd);
  50. if ((bxcr & EBC_BXCR_BU_MASK) != EBC_BXCR_BU_NONE) {
  51. *p++ = i;
  52. *p++ = 0;
  53. *p++ = bxcr & EBC_BXCR_BAS_MASK;
  54. *p++ = EBC_BXCR_BANK_SIZE(bxcr);
  55. }
  56. }
  57. /* Some 405 PPC's have EBC as direct PLB child in the dts */
  58. if (fdt_path_offset(blob, "/plb/opb/ebc") < 0)
  59. strcpy(ebc_path, "/plb/ebc");
  60. rc = fdt_find_and_setprop(blob, ebc_path, "ranges", ranges,
  61. (p - ranges) * sizeof(u32), 1);
  62. if (rc) {
  63. printf("Unable to update property EBC mappings, err=%s\n",
  64. fdt_strerror(rc));
  65. }
  66. }
  67. void ft_board_setup(void *blob, bd_t *bd) __attribute__((weak, alias("__ft_board_setup")));
  68. /*
  69. * Fixup all PCIe nodes by setting the device_type property
  70. * to "pci-endpoint" instead is "pci" for endpoint ports.
  71. * This property will get checked later by the Linux driver
  72. * to properly configure the PCIe port in Linux (again).
  73. */
  74. void fdt_pcie_setup(void *blob)
  75. {
  76. const char *compat = "ibm,plb-pciex";
  77. const char *prop = "device_type";
  78. const char *prop_val = "pci-endpoint";
  79. const u32 *port;
  80. int no;
  81. int rc;
  82. /* Search first PCIe node */
  83. no = fdt_node_offset_by_compatible(blob, -1, compat);
  84. while (no != -FDT_ERR_NOTFOUND) {
  85. port = fdt_getprop(blob, no, "port", NULL);
  86. if (port == NULL) {
  87. printf("WARNING: could not find port property\n");
  88. } else {
  89. if (is_end_point(*port)) {
  90. rc = fdt_setprop(blob, no, prop, prop_val,
  91. strlen(prop_val) + 1);
  92. if (rc < 0)
  93. printf("WARNING: could not set %s for %s: %s.\n",
  94. prop, compat, fdt_strerror(rc));
  95. }
  96. }
  97. /* Jump to next PCIe node */
  98. no = fdt_node_offset_by_compatible(blob, no, compat);
  99. }
  100. }
  101. void ft_cpu_setup(void *blob, bd_t *bd)
  102. {
  103. sys_info_t sys_info;
  104. get_sys_info(&sys_info);
  105. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "timebase-frequency",
  106. bd->bi_intfreq, 1);
  107. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "clock-frequency",
  108. bd->bi_intfreq, 1);
  109. do_fixup_by_path_u32(blob, "/plb", "clock-frequency", sys_info.freqPLB, 1);
  110. do_fixup_by_path_u32(blob, "/plb/opb", "clock-frequency", sys_info.freqOPB, 1);
  111. if (fdt_path_offset(blob, "/plb/opb/ebc") >= 0)
  112. do_fixup_by_path_u32(blob, "/plb/opb/ebc", "clock-frequency",
  113. sys_info.freqEBC, 1);
  114. else
  115. do_fixup_by_path_u32(blob, "/plb/ebc", "clock-frequency",
  116. sys_info.freqEBC, 1);
  117. fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
  118. /*
  119. * Setup all baudrates for the UARTs
  120. */
  121. do_fixup_by_compat_u32(blob, "ns16550", "clock-frequency", gd->uart_clk, 1);
  122. /*
  123. * Fixup all ethernet nodes
  124. * Note: aliases in the dts are required for this
  125. */
  126. fdt_fixup_ethernet(blob);
  127. /*
  128. * Fixup all available PCIe nodes by setting the device_type property
  129. */
  130. fdt_pcie_setup(blob);
  131. }
  132. #endif /* CONFIG_OF_LIBFDT && CONFIG_OF_BOARD_SETUP */