fdt.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. /*
  2. * Copyright 2007-2010 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. #ifdef CONFIG_SYS_CACHE_STASHING
  174. {
  175. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  176. if (reg)
  177. fdt_setprop_cell(blob, l2_off, "cache-stash-id",
  178. (*reg * 2) + 32 + 1);
  179. }
  180. #endif
  181. fdt_setprop(blob, l2_off, "cache-unified", NULL, 0);
  182. fdt_setprop_cell(blob, l2_off, "cache-block-size", line_size);
  183. fdt_setprop_cell(blob, l2_off, "cache-size", size);
  184. fdt_setprop_cell(blob, l2_off, "cache-sets", num_sets);
  185. fdt_setprop_cell(blob, l2_off, "cache-level", 2);
  186. fdt_setprop(blob, l2_off, "compatible", "cache", 6);
  187. if (l3_off < 0) {
  188. ph = (u32 *)fdt_getprop(blob, l2_off, "next-level-cache", 0);
  189. if (ph == NULL) {
  190. debug("no next-level-cache property\n");
  191. goto next;
  192. }
  193. l3_off = *ph;
  194. }
  195. next:
  196. off = fdt_node_offset_by_prop_value(blob, off,
  197. "device_type", "cpu", 4);
  198. }
  199. if (l3_off > 0) {
  200. l3_off = fdt_node_offset_by_phandle(blob, l3_off);
  201. if (l3_off < 0) {
  202. printf("%s: %s\n", __func__, fdt_strerror(off));
  203. return ;
  204. }
  205. ft_fixup_l3cache(blob, l3_off);
  206. }
  207. }
  208. #else
  209. #define ft_fixup_l2cache(x)
  210. #endif
  211. static inline void ft_fixup_cache(void *blob)
  212. {
  213. int off;
  214. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  215. while (off != -FDT_ERR_NOTFOUND) {
  216. u32 l1cfg0 = mfspr(SPRN_L1CFG0);
  217. u32 l1cfg1 = mfspr(SPRN_L1CFG1);
  218. u32 isize, iline_size, inum_sets, inum_ways;
  219. u32 dsize, dline_size, dnum_sets, dnum_ways;
  220. /* d-side config */
  221. dsize = (l1cfg0 & 0x7ff) * 1024;
  222. dnum_ways = ((l1cfg0 >> 11) & 0xff) + 1;
  223. dline_size = (((l1cfg0 >> 23) & 0x3) + 1) * 32;
  224. dnum_sets = dsize / (dline_size * dnum_ways);
  225. fdt_setprop_cell(blob, off, "d-cache-block-size", dline_size);
  226. fdt_setprop_cell(blob, off, "d-cache-size", dsize);
  227. fdt_setprop_cell(blob, off, "d-cache-sets", dnum_sets);
  228. #ifdef CONFIG_SYS_CACHE_STASHING
  229. {
  230. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  231. if (reg)
  232. fdt_setprop_cell(blob, off, "cache-stash-id",
  233. (*reg * 2) + 32 + 0);
  234. }
  235. #endif
  236. /* i-side config */
  237. isize = (l1cfg1 & 0x7ff) * 1024;
  238. inum_ways = ((l1cfg1 >> 11) & 0xff) + 1;
  239. iline_size = (((l1cfg1 >> 23) & 0x3) + 1) * 32;
  240. inum_sets = isize / (iline_size * inum_ways);
  241. fdt_setprop_cell(blob, off, "i-cache-block-size", iline_size);
  242. fdt_setprop_cell(blob, off, "i-cache-size", isize);
  243. fdt_setprop_cell(blob, off, "i-cache-sets", inum_sets);
  244. off = fdt_node_offset_by_prop_value(blob, off,
  245. "device_type", "cpu", 4);
  246. }
  247. ft_fixup_l2cache(blob);
  248. }
  249. void fdt_add_enet_stashing(void *fdt)
  250. {
  251. do_fixup_by_compat(fdt, "gianfar", "bd-stash", NULL, 0, 1);
  252. do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-len", 96, 1);
  253. do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-idx", 0, 1);
  254. }
  255. #if defined(CONFIG_SYS_DPAA_FMAN) || defined(CONFIG_SYS_DPAA_PME)
  256. static void ft_fixup_clks(void *blob, const char *compat, u32 offset,
  257. unsigned long freq)
  258. {
  259. phys_addr_t phys = offset + CONFIG_SYS_CCSRBAR_PHYS;
  260. int off = fdt_node_offset_by_compat_reg(blob, compat, phys);
  261. if (off >= 0) {
  262. off = fdt_setprop_cell(blob, off, "clock-frequency", freq);
  263. if (off > 0)
  264. printf("WARNING enable to set clock-frequency "
  265. "for %s: %s\n", compat, fdt_strerror(off));
  266. }
  267. }
  268. static void ft_fixup_dpaa_clks(void *blob)
  269. {
  270. sys_info_t sysinfo;
  271. get_sys_info(&sysinfo);
  272. ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM1_OFFSET,
  273. sysinfo.freqFMan[0]);
  274. #if (CONFIG_SYS_NUM_FMAN == 2)
  275. ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM2_OFFSET,
  276. sysinfo.freqFMan[1]);
  277. #endif
  278. #ifdef CONFIG_SYS_DPAA_PME
  279. do_fixup_by_compat_u32(blob, "fsl,pme",
  280. "clock-frequency", sysinfo.freqPME, 1);
  281. #endif
  282. }
  283. #else
  284. #define ft_fixup_dpaa_clks(x)
  285. #endif
  286. #ifdef CONFIG_QE
  287. static void ft_fixup_qe_snum(void *blob)
  288. {
  289. unsigned int svr;
  290. svr = mfspr(SPRN_SVR);
  291. if (SVR_SOC_VER(svr) == SVR_8569_E) {
  292. if(IS_SVR_REV(svr, 1, 0))
  293. do_fixup_by_compat_u32(blob, "fsl,qe",
  294. "fsl,qe-num-snums", 46, 1);
  295. else
  296. do_fixup_by_compat_u32(blob, "fsl,qe",
  297. "fsl,qe-num-snums", 76, 1);
  298. }
  299. }
  300. #endif
  301. void ft_cpu_setup(void *blob, bd_t *bd)
  302. {
  303. int off;
  304. int val;
  305. sys_info_t sysinfo;
  306. /* delete crypto node if not on an E-processor */
  307. if (!IS_E_PROCESSOR(get_svr()))
  308. fdt_fixup_crypto_node(blob, 0);
  309. fdt_fixup_ethernet(blob);
  310. fdt_add_enet_stashing(blob);
  311. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  312. "timebase-frequency", get_tbclk(), 1);
  313. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  314. "bus-frequency", bd->bi_busfreq, 1);
  315. get_sys_info(&sysinfo);
  316. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  317. while (off != -FDT_ERR_NOTFOUND) {
  318. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  319. val = cpu_to_fdt32(sysinfo.freqProcessor[*reg]);
  320. fdt_setprop(blob, off, "clock-frequency", &val, 4);
  321. off = fdt_node_offset_by_prop_value(blob, off, "device_type",
  322. "cpu", 4);
  323. }
  324. do_fixup_by_prop_u32(blob, "device_type", "soc", 4,
  325. "bus-frequency", bd->bi_busfreq, 1);
  326. do_fixup_by_compat_u32(blob, "fsl,pq3-localbus",
  327. "bus-frequency", gd->lbc_clk, 1);
  328. do_fixup_by_compat_u32(blob, "fsl,elbc",
  329. "bus-frequency", gd->lbc_clk, 1);
  330. #ifdef CONFIG_QE
  331. ft_qe_setup(blob);
  332. ft_fixup_qe_snum(blob);
  333. #endif
  334. #ifdef CONFIG_SYS_NS16550
  335. do_fixup_by_compat_u32(blob, "ns16550",
  336. "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
  337. #endif
  338. #ifdef CONFIG_CPM2
  339. do_fixup_by_compat_u32(blob, "fsl,cpm2-scc-uart",
  340. "current-speed", bd->bi_baudrate, 1);
  341. do_fixup_by_compat_u32(blob, "fsl,cpm2-brg",
  342. "clock-frequency", bd->bi_brgfreq, 1);
  343. #endif
  344. #ifdef CONFIG_FSL_CORENET
  345. do_fixup_by_compat_u32(blob, "fsl,qoriq-clockgen-1.0",
  346. "clock-frequency", CONFIG_SYS_CLK_FREQ, 1);
  347. #endif
  348. fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
  349. #ifdef CONFIG_MP
  350. ft_fixup_cpu(blob, (u64)bd->bi_memstart + (u64)bd->bi_memsize);
  351. ft_fixup_num_cores(blob);
  352. #endif
  353. ft_fixup_cache(blob);
  354. #if defined(CONFIG_FSL_ESDHC)
  355. fdt_fixup_esdhc(blob, bd);
  356. #endif
  357. ft_fixup_dpaa_clks(blob);
  358. }