fdt.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * (C) Copyright 2007
  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. /* define DEBUG for debugging output (obviously ;-)) */
  24. #if 0
  25. #define DEBUG
  26. #endif
  27. #include <common.h>
  28. #include <watchdog.h>
  29. #include <command.h>
  30. #include <asm/cache.h>
  31. #include <ppc4xx.h>
  32. #if defined(CONFIG_OF_LIBFDT)
  33. #include <libfdt.h>
  34. #include <libfdt_env.h>
  35. #include <fdt_support.h>
  36. DECLARE_GLOBAL_DATA_PTR;
  37. /*
  38. * The aliases needed for this generic etherne MAC address
  39. * fixup function are not in place yet. So don't use this
  40. * approach for now. This will be enabled later.
  41. */
  42. #undef USES_FDT_ALIASES
  43. #ifndef USES_FDT_ALIASES
  44. static void do_fixup_macaddr(void *fdt, int offset, const void *val, int i)
  45. {
  46. int rc;
  47. debug("Updating node EMAC%d\n", i);
  48. rc = fdt_setprop(fdt, offset, "mac-address", val, 6);
  49. if (rc)
  50. printf("Unable to update property %s, err=%s\n",
  51. "mac-address", fdt_strerror(rc));
  52. rc = fdt_setprop(fdt, offset, "local-mac-address", val, 6);
  53. if (rc)
  54. printf("Unable to update property %s, err=%s\n",
  55. "local-mac-address", fdt_strerror(rc));
  56. }
  57. #endif /* USES_FDT_ALIASES */
  58. void ft_cpu_setup(void *blob, bd_t *bd)
  59. {
  60. char *cpu_path = "/cpus/" OF_CPU;
  61. sys_info_t sys_info;
  62. int offset;
  63. int i;
  64. get_sys_info(&sys_info);
  65. do_fixup_by_path_u32(blob, cpu_path, "timebase-frequency", bd->bi_intfreq, 1);
  66. do_fixup_by_path_u32(blob, cpu_path, "clock-frequency", bd->bi_intfreq, 1);
  67. do_fixup_by_path_u32(blob, "/plb", "clock-frequency", sys_info.freqPLB, 1);
  68. do_fixup_by_path_u32(blob, "/plb/opb", "clock-frequency", sys_info.freqOPB, 1);
  69. do_fixup_by_path_u32(blob, "/plb/opb/ebc", "clock-frequency",
  70. sys_info.freqEBC, 1);
  71. fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
  72. /*
  73. * Setup all baudrates for the UARTs
  74. */
  75. do_fixup_by_compat_u32(blob, "ns16550", "clock-frequency", gd->uart_clk, 1);
  76. #ifdef USES_FDT_ALIASES
  77. /*
  78. * The aliases needed for this generic etherne MAC address
  79. * fixup function are not in place yet. So don't use this
  80. * approach for now. This will be enabled later.
  81. */
  82. fdt_fixup_ethernet(blob, bd);
  83. #else
  84. offset = -1;
  85. for (i = 0; i < 4; i++) {
  86. /*
  87. * FIXME: This will cause problems with emac3 compatible
  88. * devices, like on 405GP. But hopefully when we deal
  89. * with those devices, the aliases stuff will be in
  90. * place.
  91. */
  92. offset = fdt_node_offset_by_compatible(blob, offset, "ibm,emac4");
  93. if (offset < 0)
  94. break;
  95. switch (i) {
  96. case 0:
  97. do_fixup_macaddr(blob, offset, bd->bi_enetaddr, 0);
  98. break;
  99. #ifdef CONFIG_HAS_ETH1
  100. case 1:
  101. do_fixup_macaddr(blob, offset, bd->bi_enet1addr, 1);
  102. break;
  103. #endif
  104. #ifdef CONFIG_HAS_ETH2
  105. case 2:
  106. do_fixup_macaddr(blob, offset, bd->bi_enet2addr, 2);
  107. break;
  108. #endif
  109. #ifdef CONFIG_HAS_ETH3
  110. case 3:
  111. do_fixup_macaddr(blob, offset, bd->bi_enet3addr, 3);
  112. break;
  113. #endif
  114. }
  115. }
  116. #endif /* USES_FDT_ALIASES */
  117. }
  118. #endif /* CONFIG_OF_LIBFDT */