fdt.c 13 KB

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