fdt.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. #include <asm/processor.h>
  29. #ifdef CONFIG_FSL_ESDHC
  30. #include <fsl_esdhc.h>
  31. #endif
  32. DECLARE_GLOBAL_DATA_PTR;
  33. extern void ft_qe_setup(void *blob);
  34. #ifdef CONFIG_MP
  35. #include "mp.h"
  36. void ft_fixup_cpu(void *blob, u64 memory_limit)
  37. {
  38. int off;
  39. ulong spin_tbl_addr = get_spin_addr();
  40. u32 bootpg = determine_mp_bootpg();
  41. u32 id = get_my_id();
  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. u64 val = *reg * SIZE_BOOT_ENTRY + 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. #define ft_fixup_l3cache(x, y)
  73. #if defined(CONFIG_L2_CACHE)
  74. /* return size in kilobytes */
  75. static inline u32 l2cache_size(void)
  76. {
  77. volatile ccsr_l2cache_t *l2cache = (void *)CONFIG_SYS_MPC85xx_L2_ADDR;
  78. volatile u32 l2siz_field = (l2cache->l2ctl >> 28) & 0x3;
  79. u32 ver = SVR_SOC_VER(get_svr());
  80. switch (l2siz_field) {
  81. case 0x0:
  82. break;
  83. case 0x1:
  84. if (ver == SVR_8540 || ver == SVR_8560 ||
  85. ver == SVR_8541 || ver == SVR_8541_E ||
  86. ver == SVR_8555 || ver == SVR_8555_E)
  87. return 128;
  88. else
  89. return 256;
  90. break;
  91. case 0x2:
  92. if (ver == SVR_8540 || ver == SVR_8560 ||
  93. ver == SVR_8541 || ver == SVR_8541_E ||
  94. ver == SVR_8555 || ver == SVR_8555_E)
  95. return 256;
  96. else
  97. return 512;
  98. break;
  99. case 0x3:
  100. return 1024;
  101. break;
  102. }
  103. return 0;
  104. }
  105. static inline void ft_fixup_l2cache(void *blob)
  106. {
  107. int len, off;
  108. u32 *ph;
  109. struct cpu_type *cpu = identify_cpu(SVR_SOC_VER(get_svr()));
  110. char compat_buf[38];
  111. const u32 line_size = 32;
  112. const u32 num_ways = 8;
  113. const u32 size = l2cache_size() * 1024;
  114. const u32 num_sets = size / (line_size * num_ways);
  115. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  116. if (off < 0) {
  117. debug("no cpu node fount\n");
  118. return;
  119. }
  120. ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0);
  121. if (ph == NULL) {
  122. debug("no next-level-cache property\n");
  123. return ;
  124. }
  125. off = fdt_node_offset_by_phandle(blob, *ph);
  126. if (off < 0) {
  127. printf("%s: %s\n", __func__, fdt_strerror(off));
  128. return ;
  129. }
  130. if (cpu) {
  131. len = sprintf(compat_buf, "fsl,mpc%s-l2-cache-controller",
  132. cpu->name);
  133. sprintf(&compat_buf[len + 1], "cache");
  134. }
  135. fdt_setprop(blob, off, "cache-unified", NULL, 0);
  136. fdt_setprop_cell(blob, off, "cache-block-size", line_size);
  137. fdt_setprop_cell(blob, off, "cache-size", size);
  138. fdt_setprop_cell(blob, off, "cache-sets", num_sets);
  139. fdt_setprop_cell(blob, off, "cache-level", 2);
  140. fdt_setprop(blob, off, "compatible", compat_buf, sizeof(compat_buf));
  141. /* we dont bother w/L3 since no platform of this type has one */
  142. }
  143. #elif defined(CONFIG_BACKSIDE_L2_CACHE)
  144. static inline void ft_fixup_l2cache(void *blob)
  145. {
  146. int off, l2_off, l3_off = -1;
  147. u32 *ph;
  148. u32 l2cfg0 = mfspr(SPRN_L2CFG0);
  149. u32 size, line_size, num_ways, num_sets;
  150. size = (l2cfg0 & 0x3fff) * 64 * 1024;
  151. num_ways = ((l2cfg0 >> 14) & 0x1f) + 1;
  152. line_size = (((l2cfg0 >> 23) & 0x3) + 1) * 32;
  153. num_sets = size / (line_size * num_ways);
  154. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  155. while (off != -FDT_ERR_NOTFOUND) {
  156. ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0);
  157. if (ph == NULL) {
  158. debug("no next-level-cache property\n");
  159. goto next;
  160. }
  161. l2_off = fdt_node_offset_by_phandle(blob, *ph);
  162. if (l2_off < 0) {
  163. printf("%s: %s\n", __func__, fdt_strerror(off));
  164. goto next;
  165. }
  166. fdt_setprop(blob, l2_off, "cache-unified", NULL, 0);
  167. fdt_setprop_cell(blob, l2_off, "cache-block-size", line_size);
  168. fdt_setprop_cell(blob, l2_off, "cache-size", size);
  169. fdt_setprop_cell(blob, l2_off, "cache-sets", num_sets);
  170. fdt_setprop_cell(blob, l2_off, "cache-level", 2);
  171. fdt_setprop(blob, l2_off, "compatible", "cache", 6);
  172. if (l3_off < 0) {
  173. ph = (u32 *)fdt_getprop(blob, l2_off, "next-level-cache", 0);
  174. if (ph == NULL) {
  175. debug("no next-level-cache property\n");
  176. goto next;
  177. }
  178. l3_off = *ph;
  179. }
  180. next:
  181. off = fdt_node_offset_by_prop_value(blob, off,
  182. "device_type", "cpu", 4);
  183. }
  184. if (l3_off > 0) {
  185. l3_off = fdt_node_offset_by_phandle(blob, l3_off);
  186. if (l3_off < 0) {
  187. printf("%s: %s\n", __func__, fdt_strerror(off));
  188. return ;
  189. }
  190. ft_fixup_l3cache(blob, l3_off);
  191. }
  192. }
  193. #else
  194. #define ft_fixup_l2cache(x)
  195. #endif
  196. static inline void ft_fixup_cache(void *blob)
  197. {
  198. int off;
  199. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  200. while (off != -FDT_ERR_NOTFOUND) {
  201. u32 l1cfg0 = mfspr(SPRN_L1CFG0);
  202. u32 l1cfg1 = mfspr(SPRN_L1CFG1);
  203. u32 isize, iline_size, inum_sets, inum_ways;
  204. u32 dsize, dline_size, dnum_sets, dnum_ways;
  205. /* d-side config */
  206. dsize = (l1cfg0 & 0x7ff) * 1024;
  207. dnum_ways = ((l1cfg0 >> 11) & 0xff) + 1;
  208. dline_size = (((l1cfg0 >> 23) & 0x3) + 1) * 32;
  209. dnum_sets = dsize / (dline_size * dnum_ways);
  210. fdt_setprop_cell(blob, off, "d-cache-block-size", dline_size);
  211. fdt_setprop_cell(blob, off, "d-cache-size", dsize);
  212. fdt_setprop_cell(blob, off, "d-cache-sets", dnum_sets);
  213. /* i-side config */
  214. isize = (l1cfg1 & 0x7ff) * 1024;
  215. inum_ways = ((l1cfg1 >> 11) & 0xff) + 1;
  216. iline_size = (((l1cfg1 >> 23) & 0x3) + 1) * 32;
  217. inum_sets = isize / (iline_size * inum_ways);
  218. fdt_setprop_cell(blob, off, "i-cache-block-size", iline_size);
  219. fdt_setprop_cell(blob, off, "i-cache-size", isize);
  220. fdt_setprop_cell(blob, off, "i-cache-sets", inum_sets);
  221. off = fdt_node_offset_by_prop_value(blob, off,
  222. "device_type", "cpu", 4);
  223. }
  224. ft_fixup_l2cache(blob);
  225. }
  226. void fdt_add_enet_stashing(void *fdt)
  227. {
  228. do_fixup_by_compat(fdt, "gianfar", "bd-stash", NULL, 0, 1);
  229. do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-len", 96, 1);
  230. do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-idx", 0, 1);
  231. }
  232. void ft_cpu_setup(void *blob, bd_t *bd)
  233. {
  234. int off;
  235. int val;
  236. sys_info_t sysinfo;
  237. /* delete crypto node if not on an E-processor */
  238. if (!IS_E_PROCESSOR(get_svr()))
  239. fdt_fixup_crypto_node(blob, 0);
  240. fdt_fixup_ethernet(blob);
  241. fdt_add_enet_stashing(blob);
  242. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  243. "timebase-frequency", bd->bi_busfreq / 8, 1);
  244. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  245. "bus-frequency", bd->bi_busfreq, 1);
  246. get_sys_info(&sysinfo);
  247. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  248. while (off != -FDT_ERR_NOTFOUND) {
  249. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  250. val = cpu_to_fdt32(sysinfo.freqProcessor[*reg]);
  251. fdt_setprop(blob, off, "clock-frequency", &val, 4);
  252. off = fdt_node_offset_by_prop_value(blob, off, "device_type",
  253. "cpu", 4);
  254. }
  255. do_fixup_by_prop_u32(blob, "device_type", "soc", 4,
  256. "bus-frequency", bd->bi_busfreq, 1);
  257. do_fixup_by_compat_u32(blob, "fsl,pq3-localbus",
  258. "bus-frequency", gd->lbc_clk, 1);
  259. do_fixup_by_compat_u32(blob, "fsl,elbc",
  260. "bus-frequency", gd->lbc_clk, 1);
  261. #ifdef CONFIG_QE
  262. ft_qe_setup(blob);
  263. #endif
  264. #ifdef CONFIG_SYS_NS16550
  265. do_fixup_by_compat_u32(blob, "ns16550",
  266. "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
  267. #endif
  268. #ifdef CONFIG_CPM2
  269. do_fixup_by_compat_u32(blob, "fsl,cpm2-scc-uart",
  270. "current-speed", bd->bi_baudrate, 1);
  271. do_fixup_by_compat_u32(blob, "fsl,cpm2-brg",
  272. "clock-frequency", bd->bi_brgfreq, 1);
  273. #endif
  274. fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
  275. #ifdef CONFIG_MP
  276. ft_fixup_cpu(blob, (u64)bd->bi_memstart + (u64)bd->bi_memsize);
  277. #endif
  278. ft_fixup_cache(blob);
  279. #if defined(CONFIG_FSL_ESDHC)
  280. fdt_fixup_esdhc(blob, bd);
  281. #endif
  282. }