fdt.c 12 KB

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