fdt.c 9.1 KB

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