fdt.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Copyright 2007 Freescale Semiconductor, Inc.
  3. *
  4. * (C) Copyright 2000
  5. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <libfdt.h>
  27. #include <fdt_support.h>
  28. extern void ft_qe_setup(void *blob);
  29. #ifdef CONFIG_MP
  30. #include "mp.h"
  31. DECLARE_GLOBAL_DATA_PTR;
  32. void ft_fixup_cpu(void *blob, u64 memory_limit)
  33. {
  34. int off;
  35. ulong spin_tbl_addr = get_spin_addr();
  36. u32 bootpg, id = get_my_id();
  37. /* if we have 4G or more of memory, put the boot page at 4Gb-4k */
  38. if ((u64)gd->ram_size > 0xfffff000)
  39. bootpg = 0xfffff000;
  40. else
  41. bootpg = gd->ram_size - 4096;
  42. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  43. while (off != -FDT_ERR_NOTFOUND) {
  44. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  45. if (reg) {
  46. if (*reg == id) {
  47. fdt_setprop_string(blob, off, "status", "okay");
  48. } else {
  49. u32 val = *reg * 24 + spin_tbl_addr;
  50. val = cpu_to_fdt32(val);
  51. fdt_setprop_string(blob, off, "status",
  52. "disabled");
  53. fdt_setprop_string(blob, off, "enable-method",
  54. "spin-table");
  55. fdt_setprop(blob, off, "cpu-release-addr",
  56. &val, sizeof(val));
  57. }
  58. } else {
  59. printf ("cpu NULL\n");
  60. }
  61. off = fdt_node_offset_by_prop_value(blob, off,
  62. "device_type", "cpu", 4);
  63. }
  64. /* Reserve the boot page so OSes dont use it */
  65. if ((u64)bootpg < memory_limit) {
  66. off = fdt_add_mem_rsv(blob, bootpg, (u64)4096);
  67. if (off < 0)
  68. printf("%s: %s\n", __FUNCTION__, fdt_strerror(off));
  69. }
  70. }
  71. #endif
  72. #ifdef CONFIG_MP
  73. #include "mp.h"
  74. DECLARE_GLOBAL_DATA_PTR;
  75. void ft_fixup_cpu(void *blob, u64 memory_limit)
  76. {
  77. int off;
  78. ulong spin_tbl_addr = get_spin_addr();
  79. u32 bootpg, id = get_my_id();
  80. /* if we have 4G or more of memory, put the boot page at 4Gb-4k */
  81. if ((u64)gd->ram_size > 0xfffff000)
  82. bootpg = 0xfffff000;
  83. else
  84. bootpg = gd->ram_size - 4096;
  85. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  86. while (off != -FDT_ERR_NOTFOUND) {
  87. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  88. if (reg) {
  89. if (*reg == id) {
  90. fdt_setprop_string(blob, off, "status", "okay");
  91. } else {
  92. u32 val = *reg * 24 + spin_tbl_addr;
  93. val = cpu_to_fdt32(val);
  94. fdt_setprop_string(blob, off, "status",
  95. "disabled");
  96. fdt_setprop_string(blob, off, "enable-method",
  97. "spin-table");
  98. fdt_setprop(blob, off, "cpu-release-addr",
  99. &val, sizeof(val));
  100. }
  101. } else {
  102. printf ("cpu NULL\n");
  103. }
  104. off = fdt_node_offset_by_prop_value(blob, off,
  105. "device_type", "cpu", 4);
  106. }
  107. /* Reserve the boot page so OSes dont use it */
  108. if ((u64)bootpg < memory_limit) {
  109. off = fdt_add_mem_rsv(blob, bootpg, (u64)4096);
  110. if (off < 0)
  111. printf("%s: %s\n", __FUNCTION__, fdt_strerror(off));
  112. }
  113. }
  114. #endif
  115. void ft_cpu_setup(void *blob, bd_t *bd)
  116. {
  117. #if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\
  118. defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3)
  119. fdt_fixup_ethernet(blob, bd);
  120. #endif
  121. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  122. "timebase-frequency", bd->bi_busfreq / 8, 1);
  123. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  124. "bus-frequency", bd->bi_busfreq, 1);
  125. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  126. "clock-frequency", bd->bi_intfreq, 1);
  127. do_fixup_by_prop_u32(blob, "device_type", "soc", 4,
  128. "bus-frequency", bd->bi_busfreq, 1);
  129. #ifdef CONFIG_QE
  130. ft_qe_setup(blob);
  131. #endif
  132. #ifdef CFG_NS16550
  133. do_fixup_by_compat_u32(blob, "ns16550",
  134. "clock-frequency", bd->bi_busfreq, 1);
  135. #endif
  136. #ifdef CONFIG_CPM2
  137. do_fixup_by_compat_u32(blob, "fsl,cpm2-scc-uart",
  138. "current-speed", bd->bi_baudrate, 1);
  139. do_fixup_by_compat_u32(blob, "fsl,cpm2-brg",
  140. "clock-frequency", bd->bi_brgfreq, 1);
  141. #endif
  142. fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
  143. #ifdef CONFIG_MP
  144. ft_fixup_cpu(blob, (u64)bd->bi_memstart + (u64)bd->bi_memsize);
  145. #endif
  146. }