fdt.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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. #include <asm/io.h>
  31. #include <asm/fsl_portals.h>
  32. #ifdef CONFIG_FSL_ESDHC
  33. #include <fsl_esdhc.h>
  34. #endif
  35. DECLARE_GLOBAL_DATA_PTR;
  36. extern void ft_qe_setup(void *blob);
  37. extern void ft_fixup_num_cores(void *blob);
  38. #ifdef CONFIG_MP
  39. #include "mp.h"
  40. void ft_fixup_cpu(void *blob, u64 memory_limit)
  41. {
  42. int off;
  43. ulong spin_tbl_addr = get_spin_phys_addr();
  44. u32 bootpg = determine_mp_bootpg();
  45. u32 id = get_my_id();
  46. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  47. while (off != -FDT_ERR_NOTFOUND) {
  48. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  49. if (reg) {
  50. u64 val = *reg * SIZE_BOOT_ENTRY + spin_tbl_addr;
  51. val = cpu_to_fdt32(val);
  52. if (*reg == id) {
  53. fdt_setprop_string(blob, off, "status",
  54. "okay");
  55. } else {
  56. fdt_setprop_string(blob, off, "status",
  57. "disabled");
  58. }
  59. fdt_setprop_string(blob, off, "enable-method",
  60. "spin-table");
  61. fdt_setprop(blob, off, "cpu-release-addr",
  62. &val, sizeof(val));
  63. } else {
  64. printf ("cpu NULL\n");
  65. }
  66. off = fdt_node_offset_by_prop_value(blob, off,
  67. "device_type", "cpu", 4);
  68. }
  69. /* Reserve the boot page so OSes dont use it */
  70. if ((u64)bootpg < memory_limit) {
  71. off = fdt_add_mem_rsv(blob, bootpg, (u64)4096);
  72. if (off < 0)
  73. printf("%s: %s\n", __FUNCTION__, fdt_strerror(off));
  74. }
  75. }
  76. #endif
  77. #ifdef CONFIG_SYS_FSL_CPC
  78. static inline void ft_fixup_l3cache(void *blob, int off)
  79. {
  80. u32 line_size, num_ways, size, num_sets;
  81. cpc_corenet_t *cpc = (void *)CONFIG_SYS_FSL_CPC_ADDR;
  82. u32 cfg0 = in_be32(&cpc->cpccfg0);
  83. size = CPC_CFG0_SZ_K(cfg0) * 1024 * CONFIG_SYS_NUM_CPC;
  84. num_ways = CPC_CFG0_NUM_WAYS(cfg0);
  85. line_size = CPC_CFG0_LINE_SZ(cfg0);
  86. num_sets = size / (line_size * num_ways);
  87. fdt_setprop(blob, off, "cache-unified", NULL, 0);
  88. fdt_setprop_cell(blob, off, "cache-block-size", line_size);
  89. fdt_setprop_cell(blob, off, "cache-size", size);
  90. fdt_setprop_cell(blob, off, "cache-sets", num_sets);
  91. fdt_setprop_cell(blob, off, "cache-level", 3);
  92. #ifdef CONFIG_SYS_CACHE_STASHING
  93. fdt_setprop_cell(blob, off, "cache-stash-id", 1);
  94. #endif
  95. }
  96. #else
  97. #define ft_fixup_l3cache(x, y)
  98. #endif
  99. #if defined(CONFIG_L2_CACHE)
  100. /* return size in kilobytes */
  101. static inline u32 l2cache_size(void)
  102. {
  103. volatile ccsr_l2cache_t *l2cache = (void *)CONFIG_SYS_MPC85xx_L2_ADDR;
  104. volatile u32 l2siz_field = (l2cache->l2ctl >> 28) & 0x3;
  105. u32 ver = SVR_SOC_VER(get_svr());
  106. switch (l2siz_field) {
  107. case 0x0:
  108. break;
  109. case 0x1:
  110. if (ver == SVR_8540 || ver == SVR_8560 ||
  111. ver == SVR_8541 || ver == SVR_8541_E ||
  112. ver == SVR_8555 || ver == SVR_8555_E)
  113. return 128;
  114. else
  115. return 256;
  116. break;
  117. case 0x2:
  118. if (ver == SVR_8540 || ver == SVR_8560 ||
  119. ver == SVR_8541 || ver == SVR_8541_E ||
  120. ver == SVR_8555 || ver == SVR_8555_E)
  121. return 256;
  122. else
  123. return 512;
  124. break;
  125. case 0x3:
  126. return 1024;
  127. break;
  128. }
  129. return 0;
  130. }
  131. static inline void ft_fixup_l2cache(void *blob)
  132. {
  133. int len, off;
  134. u32 *ph;
  135. struct cpu_type *cpu = identify_cpu(SVR_SOC_VER(get_svr()));
  136. char compat_buf[38];
  137. const u32 line_size = 32;
  138. const u32 num_ways = 8;
  139. const u32 size = l2cache_size() * 1024;
  140. const u32 num_sets = size / (line_size * num_ways);
  141. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  142. if (off < 0) {
  143. debug("no cpu node fount\n");
  144. return;
  145. }
  146. ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0);
  147. if (ph == NULL) {
  148. debug("no next-level-cache property\n");
  149. return ;
  150. }
  151. off = fdt_node_offset_by_phandle(blob, *ph);
  152. if (off < 0) {
  153. printf("%s: %s\n", __func__, fdt_strerror(off));
  154. return ;
  155. }
  156. if (cpu) {
  157. if (isdigit(cpu->name[0]))
  158. len = sprintf(compat_buf,
  159. "fsl,mpc%s-l2-cache-controller", cpu->name);
  160. else
  161. len = sprintf(compat_buf,
  162. "fsl,%c%s-l2-cache-controller",
  163. tolower(cpu->name[0]), cpu->name + 1);
  164. sprintf(&compat_buf[len + 1], "cache");
  165. }
  166. fdt_setprop(blob, off, "cache-unified", NULL, 0);
  167. fdt_setprop_cell(blob, off, "cache-block-size", line_size);
  168. fdt_setprop_cell(blob, off, "cache-size", size);
  169. fdt_setprop_cell(blob, off, "cache-sets", num_sets);
  170. fdt_setprop_cell(blob, off, "cache-level", 2);
  171. fdt_setprop(blob, off, "compatible", compat_buf, sizeof(compat_buf));
  172. /* we dont bother w/L3 since no platform of this type has one */
  173. }
  174. #elif defined(CONFIG_BACKSIDE_L2_CACHE)
  175. static inline void ft_fixup_l2cache(void *blob)
  176. {
  177. int off, l2_off, l3_off = -1;
  178. u32 *ph;
  179. u32 l2cfg0 = mfspr(SPRN_L2CFG0);
  180. u32 size, line_size, num_ways, num_sets;
  181. size = (l2cfg0 & 0x3fff) * 64 * 1024;
  182. num_ways = ((l2cfg0 >> 14) & 0x1f) + 1;
  183. line_size = (((l2cfg0 >> 23) & 0x3) + 1) * 32;
  184. num_sets = size / (line_size * num_ways);
  185. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  186. while (off != -FDT_ERR_NOTFOUND) {
  187. ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0);
  188. if (ph == NULL) {
  189. debug("no next-level-cache property\n");
  190. goto next;
  191. }
  192. l2_off = fdt_node_offset_by_phandle(blob, *ph);
  193. if (l2_off < 0) {
  194. printf("%s: %s\n", __func__, fdt_strerror(off));
  195. goto next;
  196. }
  197. #ifdef CONFIG_SYS_CACHE_STASHING
  198. {
  199. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  200. if (reg)
  201. fdt_setprop_cell(blob, l2_off, "cache-stash-id",
  202. (*reg * 2) + 32 + 1);
  203. }
  204. #endif
  205. fdt_setprop(blob, l2_off, "cache-unified", NULL, 0);
  206. fdt_setprop_cell(blob, l2_off, "cache-block-size", line_size);
  207. fdt_setprop_cell(blob, l2_off, "cache-size", size);
  208. fdt_setprop_cell(blob, l2_off, "cache-sets", num_sets);
  209. fdt_setprop_cell(blob, l2_off, "cache-level", 2);
  210. fdt_setprop(blob, l2_off, "compatible", "cache", 6);
  211. if (l3_off < 0) {
  212. ph = (u32 *)fdt_getprop(blob, l2_off, "next-level-cache", 0);
  213. if (ph == NULL) {
  214. debug("no next-level-cache property\n");
  215. goto next;
  216. }
  217. l3_off = *ph;
  218. }
  219. next:
  220. off = fdt_node_offset_by_prop_value(blob, off,
  221. "device_type", "cpu", 4);
  222. }
  223. if (l3_off > 0) {
  224. l3_off = fdt_node_offset_by_phandle(blob, l3_off);
  225. if (l3_off < 0) {
  226. printf("%s: %s\n", __func__, fdt_strerror(off));
  227. return ;
  228. }
  229. ft_fixup_l3cache(blob, l3_off);
  230. }
  231. }
  232. #else
  233. #define ft_fixup_l2cache(x)
  234. #endif
  235. static inline void ft_fixup_cache(void *blob)
  236. {
  237. int off;
  238. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  239. while (off != -FDT_ERR_NOTFOUND) {
  240. u32 l1cfg0 = mfspr(SPRN_L1CFG0);
  241. u32 l1cfg1 = mfspr(SPRN_L1CFG1);
  242. u32 isize, iline_size, inum_sets, inum_ways;
  243. u32 dsize, dline_size, dnum_sets, dnum_ways;
  244. /* d-side config */
  245. dsize = (l1cfg0 & 0x7ff) * 1024;
  246. dnum_ways = ((l1cfg0 >> 11) & 0xff) + 1;
  247. dline_size = (((l1cfg0 >> 23) & 0x3) + 1) * 32;
  248. dnum_sets = dsize / (dline_size * dnum_ways);
  249. fdt_setprop_cell(blob, off, "d-cache-block-size", dline_size);
  250. fdt_setprop_cell(blob, off, "d-cache-size", dsize);
  251. fdt_setprop_cell(blob, off, "d-cache-sets", dnum_sets);
  252. #ifdef CONFIG_SYS_CACHE_STASHING
  253. {
  254. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  255. if (reg)
  256. fdt_setprop_cell(blob, off, "cache-stash-id",
  257. (*reg * 2) + 32 + 0);
  258. }
  259. #endif
  260. /* i-side config */
  261. isize = (l1cfg1 & 0x7ff) * 1024;
  262. inum_ways = ((l1cfg1 >> 11) & 0xff) + 1;
  263. iline_size = (((l1cfg1 >> 23) & 0x3) + 1) * 32;
  264. inum_sets = isize / (iline_size * inum_ways);
  265. fdt_setprop_cell(blob, off, "i-cache-block-size", iline_size);
  266. fdt_setprop_cell(blob, off, "i-cache-size", isize);
  267. fdt_setprop_cell(blob, off, "i-cache-sets", inum_sets);
  268. off = fdt_node_offset_by_prop_value(blob, off,
  269. "device_type", "cpu", 4);
  270. }
  271. ft_fixup_l2cache(blob);
  272. }
  273. void fdt_add_enet_stashing(void *fdt)
  274. {
  275. do_fixup_by_compat(fdt, "gianfar", "bd-stash", NULL, 0, 1);
  276. do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-len", 96, 1);
  277. do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-idx", 0, 1);
  278. }
  279. #if defined(CONFIG_SYS_DPAA_FMAN) || defined(CONFIG_SYS_DPAA_PME)
  280. static void ft_fixup_clks(void *blob, const char *compat, u32 offset,
  281. unsigned long freq)
  282. {
  283. phys_addr_t phys = offset + CONFIG_SYS_CCSRBAR_PHYS;
  284. int off = fdt_node_offset_by_compat_reg(blob, compat, phys);
  285. if (off >= 0) {
  286. off = fdt_setprop_cell(blob, off, "clock-frequency", freq);
  287. if (off > 0)
  288. printf("WARNING enable to set clock-frequency "
  289. "for %s: %s\n", compat, fdt_strerror(off));
  290. }
  291. }
  292. static void ft_fixup_dpaa_clks(void *blob)
  293. {
  294. sys_info_t sysinfo;
  295. get_sys_info(&sysinfo);
  296. ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM1_OFFSET,
  297. sysinfo.freqFMan[0]);
  298. #if (CONFIG_SYS_NUM_FMAN == 2)
  299. ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM2_OFFSET,
  300. sysinfo.freqFMan[1]);
  301. #endif
  302. #ifdef CONFIG_SYS_DPAA_PME
  303. do_fixup_by_compat_u32(blob, "fsl,pme",
  304. "clock-frequency", sysinfo.freqPME, 1);
  305. #endif
  306. }
  307. #else
  308. #define ft_fixup_dpaa_clks(x)
  309. #endif
  310. #ifdef CONFIG_QE
  311. static void ft_fixup_qe_snum(void *blob)
  312. {
  313. unsigned int svr;
  314. svr = mfspr(SPRN_SVR);
  315. if (SVR_SOC_VER(svr) == SVR_8569_E) {
  316. if(IS_SVR_REV(svr, 1, 0))
  317. do_fixup_by_compat_u32(blob, "fsl,qe",
  318. "fsl,qe-num-snums", 46, 1);
  319. else
  320. do_fixup_by_compat_u32(blob, "fsl,qe",
  321. "fsl,qe-num-snums", 76, 1);
  322. }
  323. }
  324. #endif
  325. void ft_cpu_setup(void *blob, bd_t *bd)
  326. {
  327. int off;
  328. int val;
  329. sys_info_t sysinfo;
  330. /* delete crypto node if not on an E-processor */
  331. if (!IS_E_PROCESSOR(get_svr()))
  332. fdt_fixup_crypto_node(blob, 0);
  333. fdt_fixup_ethernet(blob);
  334. fdt_add_enet_stashing(blob);
  335. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  336. "timebase-frequency", get_tbclk(), 1);
  337. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  338. "bus-frequency", bd->bi_busfreq, 1);
  339. get_sys_info(&sysinfo);
  340. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  341. while (off != -FDT_ERR_NOTFOUND) {
  342. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  343. val = cpu_to_fdt32(sysinfo.freqProcessor[*reg]);
  344. fdt_setprop(blob, off, "clock-frequency", &val, 4);
  345. off = fdt_node_offset_by_prop_value(blob, off, "device_type",
  346. "cpu", 4);
  347. }
  348. do_fixup_by_prop_u32(blob, "device_type", "soc", 4,
  349. "bus-frequency", bd->bi_busfreq, 1);
  350. do_fixup_by_compat_u32(blob, "fsl,pq3-localbus",
  351. "bus-frequency", gd->lbc_clk, 1);
  352. do_fixup_by_compat_u32(blob, "fsl,elbc",
  353. "bus-frequency", gd->lbc_clk, 1);
  354. #ifdef CONFIG_QE
  355. ft_qe_setup(blob);
  356. ft_fixup_qe_snum(blob);
  357. #endif
  358. #ifdef CONFIG_SYS_NS16550
  359. do_fixup_by_compat_u32(blob, "ns16550",
  360. "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
  361. #endif
  362. #ifdef CONFIG_CPM2
  363. do_fixup_by_compat_u32(blob, "fsl,cpm2-scc-uart",
  364. "current-speed", bd->bi_baudrate, 1);
  365. do_fixup_by_compat_u32(blob, "fsl,cpm2-brg",
  366. "clock-frequency", bd->bi_brgfreq, 1);
  367. #endif
  368. #ifdef CONFIG_FSL_CORENET
  369. do_fixup_by_compat_u32(blob, "fsl,qoriq-clockgen-1.0",
  370. "clock-frequency", CONFIG_SYS_CLK_FREQ, 1);
  371. #endif
  372. fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
  373. #ifdef CONFIG_MP
  374. ft_fixup_cpu(blob, (u64)bd->bi_memstart + (u64)bd->bi_memsize);
  375. ft_fixup_num_cores(blob);
  376. #endif
  377. ft_fixup_cache(blob);
  378. #if defined(CONFIG_FSL_ESDHC)
  379. fdt_fixup_esdhc(blob, bd);
  380. #endif
  381. ft_fixup_dpaa_clks(blob);
  382. #if defined(CONFIG_SYS_BMAN_MEM_PHYS)
  383. fdt_portal(blob, "fsl,bman-portal", "bman-portals",
  384. (u64)CONFIG_SYS_BMAN_MEM_PHYS,
  385. CONFIG_SYS_BMAN_MEM_SIZE);
  386. #endif
  387. #if defined(CONFIG_SYS_QMAN_MEM_PHYS)
  388. fdt_portal(blob, "fsl,qman-portal", "qman-portals",
  389. (u64)CONFIG_SYS_QMAN_MEM_PHYS,
  390. CONFIG_SYS_QMAN_MEM_SIZE);
  391. fdt_fixup_qportals(blob);
  392. #endif
  393. }