fdt.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. /*
  2. * Copyright 2007-2011 Freescale Semiconductor, Inc.
  3. *
  4. * (C) Copyright 2000
  5. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <libfdt.h>
  11. #include <fdt_support.h>
  12. #include <asm/processor.h>
  13. #include <linux/ctype.h>
  14. #include <asm/io.h>
  15. #include <asm/fsl_portals.h>
  16. #ifdef CONFIG_FSL_ESDHC
  17. #include <fsl_esdhc.h>
  18. #endif
  19. #include "../../../../drivers/qe/qe.h" /* For struct qe_firmware */
  20. DECLARE_GLOBAL_DATA_PTR;
  21. extern void ft_qe_setup(void *blob);
  22. extern void ft_fixup_num_cores(void *blob);
  23. extern void ft_srio_setup(void *blob);
  24. #ifdef CONFIG_MP
  25. #include "mp.h"
  26. void ft_fixup_cpu(void *blob, u64 memory_limit)
  27. {
  28. int off;
  29. phys_addr_t spin_tbl_addr = get_spin_phys_addr();
  30. u32 bootpg = determine_mp_bootpg(NULL);
  31. u32 id = get_my_id();
  32. const char *enable_method;
  33. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  34. while (off != -FDT_ERR_NOTFOUND) {
  35. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  36. if (reg) {
  37. u32 phys_cpu_id = thread_to_core(*reg);
  38. u64 val = phys_cpu_id * SIZE_BOOT_ENTRY + spin_tbl_addr;
  39. val = cpu_to_fdt64(val);
  40. if (*reg == id) {
  41. fdt_setprop_string(blob, off, "status",
  42. "okay");
  43. } else {
  44. fdt_setprop_string(blob, off, "status",
  45. "disabled");
  46. }
  47. if (hold_cores_in_reset(0)) {
  48. #ifdef CONFIG_FSL_CORENET
  49. /* Cores held in reset, use BRR to release */
  50. enable_method = "fsl,brr-holdoff";
  51. #else
  52. /* Cores held in reset, use EEBPCR to release */
  53. enable_method = "fsl,eebpcr-holdoff";
  54. #endif
  55. } else {
  56. /* Cores out of reset and in a spin-loop */
  57. enable_method = "spin-table";
  58. fdt_setprop(blob, off, "cpu-release-addr",
  59. &val, sizeof(val));
  60. }
  61. fdt_setprop_string(blob, off, "enable-method",
  62. enable_method);
  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("Failed to reserve memory for bootpg: %s\n",
  74. fdt_strerror(off));
  75. }
  76. #ifndef CONFIG_MPC8xxx_DISABLE_BPTR
  77. /*
  78. * Reserve the default boot page so OSes dont use it.
  79. * The default boot page is always mapped to bootpg above using
  80. * boot page translation.
  81. */
  82. if (0xfffff000ull < memory_limit) {
  83. off = fdt_add_mem_rsv(blob, 0xfffff000ull, (u64)4096);
  84. if (off < 0) {
  85. printf("Failed to reserve memory for 0xfffff000: %s\n",
  86. fdt_strerror(off));
  87. }
  88. }
  89. #endif
  90. /* Reserve spin table page */
  91. if (spin_tbl_addr < memory_limit) {
  92. off = fdt_add_mem_rsv(blob,
  93. (spin_tbl_addr & ~0xffful), 4096);
  94. if (off < 0)
  95. printf("Failed to reserve memory for spin table: %s\n",
  96. fdt_strerror(off));
  97. }
  98. }
  99. #endif
  100. #ifdef CONFIG_SYS_FSL_CPC
  101. static inline void ft_fixup_l3cache(void *blob, int off)
  102. {
  103. u32 line_size, num_ways, size, num_sets;
  104. cpc_corenet_t *cpc = (void *)CONFIG_SYS_FSL_CPC_ADDR;
  105. u32 cfg0 = in_be32(&cpc->cpccfg0);
  106. size = CPC_CFG0_SZ_K(cfg0) * 1024 * CONFIG_SYS_NUM_CPC;
  107. num_ways = CPC_CFG0_NUM_WAYS(cfg0);
  108. line_size = CPC_CFG0_LINE_SZ(cfg0);
  109. num_sets = size / (line_size * num_ways);
  110. fdt_setprop(blob, off, "cache-unified", NULL, 0);
  111. fdt_setprop_cell(blob, off, "cache-block-size", line_size);
  112. fdt_setprop_cell(blob, off, "cache-size", size);
  113. fdt_setprop_cell(blob, off, "cache-sets", num_sets);
  114. fdt_setprop_cell(blob, off, "cache-level", 3);
  115. #ifdef CONFIG_SYS_CACHE_STASHING
  116. fdt_setprop_cell(blob, off, "cache-stash-id", 1);
  117. #endif
  118. }
  119. #else
  120. #define ft_fixup_l3cache(x, y)
  121. #endif
  122. #if defined(CONFIG_L2_CACHE)
  123. /* return size in kilobytes */
  124. static inline u32 l2cache_size(void)
  125. {
  126. volatile ccsr_l2cache_t *l2cache = (void *)CONFIG_SYS_MPC85xx_L2_ADDR;
  127. volatile u32 l2siz_field = (l2cache->l2ctl >> 28) & 0x3;
  128. u32 ver = SVR_SOC_VER(get_svr());
  129. switch (l2siz_field) {
  130. case 0x0:
  131. break;
  132. case 0x1:
  133. if (ver == SVR_8540 || ver == SVR_8560 ||
  134. ver == SVR_8541 || ver == SVR_8555)
  135. return 128;
  136. else
  137. return 256;
  138. break;
  139. case 0x2:
  140. if (ver == SVR_8540 || ver == SVR_8560 ||
  141. ver == SVR_8541 || ver == SVR_8555)
  142. return 256;
  143. else
  144. return 512;
  145. break;
  146. case 0x3:
  147. return 1024;
  148. break;
  149. }
  150. return 0;
  151. }
  152. static inline void ft_fixup_l2cache(void *blob)
  153. {
  154. int len, off;
  155. u32 *ph;
  156. struct cpu_type *cpu = identify_cpu(SVR_SOC_VER(get_svr()));
  157. const u32 line_size = 32;
  158. const u32 num_ways = 8;
  159. const u32 size = l2cache_size() * 1024;
  160. const u32 num_sets = size / (line_size * num_ways);
  161. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  162. if (off < 0) {
  163. debug("no cpu node fount\n");
  164. return;
  165. }
  166. ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0);
  167. if (ph == NULL) {
  168. debug("no next-level-cache property\n");
  169. return ;
  170. }
  171. off = fdt_node_offset_by_phandle(blob, *ph);
  172. if (off < 0) {
  173. printf("%s: %s\n", __func__, fdt_strerror(off));
  174. return ;
  175. }
  176. if (cpu) {
  177. char buf[40];
  178. if (isdigit(cpu->name[0])) {
  179. /* MPCxxxx, where xxxx == 4-digit number */
  180. len = sprintf(buf, "fsl,mpc%s-l2-cache-controller",
  181. cpu->name) + 1;
  182. } else {
  183. /* Pxxxx or Txxxx, where xxxx == 4-digit number */
  184. len = sprintf(buf, "fsl,%c%s-l2-cache-controller",
  185. tolower(cpu->name[0]), cpu->name + 1) + 1;
  186. }
  187. /*
  188. * append "cache" after the NULL character that the previous
  189. * sprintf wrote. This is how a device tree stores multiple
  190. * strings in a property.
  191. */
  192. len += sprintf(buf + len, "cache") + 1;
  193. fdt_setprop(blob, off, "compatible", buf, len);
  194. }
  195. fdt_setprop(blob, off, "cache-unified", NULL, 0);
  196. fdt_setprop_cell(blob, off, "cache-block-size", line_size);
  197. fdt_setprop_cell(blob, off, "cache-size", size);
  198. fdt_setprop_cell(blob, off, "cache-sets", num_sets);
  199. fdt_setprop_cell(blob, off, "cache-level", 2);
  200. /* we dont bother w/L3 since no platform of this type has one */
  201. }
  202. #elif defined(CONFIG_BACKSIDE_L2_CACHE) || \
  203. defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2)
  204. static inline void ft_fixup_l2cache(void *blob)
  205. {
  206. int off, l2_off, l3_off = -1;
  207. u32 *ph;
  208. #ifdef CONFIG_BACKSIDE_L2_CACHE
  209. u32 l2cfg0 = mfspr(SPRN_L2CFG0);
  210. #else
  211. struct ccsr_cluster_l2 *l2cache =
  212. (struct ccsr_cluster_l2 __iomem *)(CONFIG_SYS_FSL_CLUSTER_1_L2);
  213. u32 l2cfg0 = in_be32(&l2cache->l2cfg0);
  214. #endif
  215. u32 size, line_size, num_ways, num_sets;
  216. int has_l2 = 1;
  217. /* P2040/P2040E has no L2, so dont set any L2 props */
  218. if (SVR_SOC_VER(get_svr()) == SVR_P2040)
  219. has_l2 = 0;
  220. size = (l2cfg0 & 0x3fff) * 64 * 1024;
  221. num_ways = ((l2cfg0 >> 14) & 0x1f) + 1;
  222. line_size = (((l2cfg0 >> 23) & 0x3) + 1) * 32;
  223. num_sets = size / (line_size * num_ways);
  224. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  225. while (off != -FDT_ERR_NOTFOUND) {
  226. ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0);
  227. if (ph == NULL) {
  228. debug("no next-level-cache property\n");
  229. goto next;
  230. }
  231. l2_off = fdt_node_offset_by_phandle(blob, *ph);
  232. if (l2_off < 0) {
  233. printf("%s: %s\n", __func__, fdt_strerror(off));
  234. goto next;
  235. }
  236. if (has_l2) {
  237. #ifdef CONFIG_SYS_CACHE_STASHING
  238. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  239. #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
  240. /* Only initialize every eighth thread */
  241. if (reg && !((*reg) % 8))
  242. #else
  243. if (reg)
  244. #endif
  245. fdt_setprop_cell(blob, l2_off, "cache-stash-id",
  246. (*reg * 2) + 32 + 1);
  247. #endif
  248. fdt_setprop(blob, l2_off, "cache-unified", NULL, 0);
  249. fdt_setprop_cell(blob, l2_off, "cache-block-size",
  250. line_size);
  251. fdt_setprop_cell(blob, l2_off, "cache-size", size);
  252. fdt_setprop_cell(blob, l2_off, "cache-sets", num_sets);
  253. fdt_setprop_cell(blob, l2_off, "cache-level", 2);
  254. fdt_setprop(blob, l2_off, "compatible", "cache", 6);
  255. }
  256. if (l3_off < 0) {
  257. ph = (u32 *)fdt_getprop(blob, l2_off, "next-level-cache", 0);
  258. if (ph == NULL) {
  259. debug("no next-level-cache property\n");
  260. goto next;
  261. }
  262. l3_off = *ph;
  263. }
  264. next:
  265. off = fdt_node_offset_by_prop_value(blob, off,
  266. "device_type", "cpu", 4);
  267. }
  268. if (l3_off > 0) {
  269. l3_off = fdt_node_offset_by_phandle(blob, l3_off);
  270. if (l3_off < 0) {
  271. printf("%s: %s\n", __func__, fdt_strerror(off));
  272. return ;
  273. }
  274. ft_fixup_l3cache(blob, l3_off);
  275. }
  276. }
  277. #else
  278. #define ft_fixup_l2cache(x)
  279. #endif
  280. static inline void ft_fixup_cache(void *blob)
  281. {
  282. int off;
  283. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  284. while (off != -FDT_ERR_NOTFOUND) {
  285. u32 l1cfg0 = mfspr(SPRN_L1CFG0);
  286. u32 l1cfg1 = mfspr(SPRN_L1CFG1);
  287. u32 isize, iline_size, inum_sets, inum_ways;
  288. u32 dsize, dline_size, dnum_sets, dnum_ways;
  289. /* d-side config */
  290. dsize = (l1cfg0 & 0x7ff) * 1024;
  291. dnum_ways = ((l1cfg0 >> 11) & 0xff) + 1;
  292. dline_size = (((l1cfg0 >> 23) & 0x3) + 1) * 32;
  293. dnum_sets = dsize / (dline_size * dnum_ways);
  294. fdt_setprop_cell(blob, off, "d-cache-block-size", dline_size);
  295. fdt_setprop_cell(blob, off, "d-cache-size", dsize);
  296. fdt_setprop_cell(blob, off, "d-cache-sets", dnum_sets);
  297. #ifdef CONFIG_SYS_CACHE_STASHING
  298. {
  299. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  300. if (reg)
  301. fdt_setprop_cell(blob, off, "cache-stash-id",
  302. (*reg * 2) + 32 + 0);
  303. }
  304. #endif
  305. /* i-side config */
  306. isize = (l1cfg1 & 0x7ff) * 1024;
  307. inum_ways = ((l1cfg1 >> 11) & 0xff) + 1;
  308. iline_size = (((l1cfg1 >> 23) & 0x3) + 1) * 32;
  309. inum_sets = isize / (iline_size * inum_ways);
  310. fdt_setprop_cell(blob, off, "i-cache-block-size", iline_size);
  311. fdt_setprop_cell(blob, off, "i-cache-size", isize);
  312. fdt_setprop_cell(blob, off, "i-cache-sets", inum_sets);
  313. off = fdt_node_offset_by_prop_value(blob, off,
  314. "device_type", "cpu", 4);
  315. }
  316. ft_fixup_l2cache(blob);
  317. }
  318. void fdt_add_enet_stashing(void *fdt)
  319. {
  320. do_fixup_by_compat(fdt, "gianfar", "bd-stash", NULL, 0, 1);
  321. do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-len", 96, 1);
  322. do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-idx", 0, 1);
  323. do_fixup_by_compat(fdt, "fsl,etsec2", "bd-stash", NULL, 0, 1);
  324. do_fixup_by_compat_u32(fdt, "fsl,etsec2", "rx-stash-len", 96, 1);
  325. do_fixup_by_compat_u32(fdt, "fsl,etsec2", "rx-stash-idx", 0, 1);
  326. }
  327. #if defined(CONFIG_SYS_DPAA_FMAN) || defined(CONFIG_SYS_DPAA_PME)
  328. #ifdef CONFIG_SYS_DPAA_FMAN
  329. static void ft_fixup_clks(void *blob, const char *compat, u32 offset,
  330. unsigned long freq)
  331. {
  332. phys_addr_t phys = offset + CONFIG_SYS_CCSRBAR_PHYS;
  333. int off = fdt_node_offset_by_compat_reg(blob, compat, phys);
  334. if (off >= 0) {
  335. off = fdt_setprop_cell(blob, off, "clock-frequency", freq);
  336. if (off > 0)
  337. printf("WARNING enable to set clock-frequency "
  338. "for %s: %s\n", compat, fdt_strerror(off));
  339. }
  340. }
  341. #endif
  342. static void ft_fixup_dpaa_clks(void *blob)
  343. {
  344. sys_info_t sysinfo;
  345. get_sys_info(&sysinfo);
  346. #ifdef CONFIG_SYS_DPAA_FMAN
  347. ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM1_OFFSET,
  348. sysinfo.freqFMan[0]);
  349. #if (CONFIG_SYS_NUM_FMAN == 2)
  350. ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM2_OFFSET,
  351. sysinfo.freqFMan[1]);
  352. #endif
  353. #endif
  354. #ifdef CONFIG_SYS_DPAA_QBMAN
  355. do_fixup_by_compat_u32(blob, "fsl,qman",
  356. "clock-frequency", sysinfo.freqQMAN, 1);
  357. #endif
  358. #ifdef CONFIG_SYS_DPAA_PME
  359. do_fixup_by_compat_u32(blob, "fsl,pme",
  360. "clock-frequency", sysinfo.freqPME, 1);
  361. #endif
  362. }
  363. #else
  364. #define ft_fixup_dpaa_clks(x)
  365. #endif
  366. #ifdef CONFIG_QE
  367. static void ft_fixup_qe_snum(void *blob)
  368. {
  369. unsigned int svr;
  370. svr = mfspr(SPRN_SVR);
  371. if (SVR_SOC_VER(svr) == SVR_8569) {
  372. if(IS_SVR_REV(svr, 1, 0))
  373. do_fixup_by_compat_u32(blob, "fsl,qe",
  374. "fsl,qe-num-snums", 46, 1);
  375. else
  376. do_fixup_by_compat_u32(blob, "fsl,qe",
  377. "fsl,qe-num-snums", 76, 1);
  378. }
  379. }
  380. #endif
  381. /**
  382. * fdt_fixup_fman_firmware -- insert the Fman firmware into the device tree
  383. *
  384. * The binding for an Fman firmware node is documented in
  385. * Documentation/powerpc/dts-bindings/fsl/dpaa/fman.txt. This node contains
  386. * the actual Fman firmware binary data. The operating system is expected to
  387. * be able to parse the binary data to determine any attributes it needs.
  388. */
  389. #ifdef CONFIG_SYS_DPAA_FMAN
  390. void fdt_fixup_fman_firmware(void *blob)
  391. {
  392. int rc, fmnode, fwnode = -1;
  393. uint32_t phandle;
  394. struct qe_firmware *fmanfw;
  395. const struct qe_header *hdr;
  396. unsigned int length;
  397. uint32_t crc;
  398. const char *p;
  399. /* The first Fman we find will contain the actual firmware. */
  400. fmnode = fdt_node_offset_by_compatible(blob, -1, "fsl,fman");
  401. if (fmnode < 0)
  402. /* Exit silently if there are no Fman devices */
  403. return;
  404. /* If we already have a firmware node, then also exit silently. */
  405. if (fdt_node_offset_by_compatible(blob, -1, "fsl,fman-firmware") > 0)
  406. return;
  407. /* If the environment variable is not set, then exit silently */
  408. p = getenv("fman_ucode");
  409. if (!p)
  410. return;
  411. fmanfw = (struct qe_firmware *) simple_strtoul(p, NULL, 0);
  412. if (!fmanfw)
  413. return;
  414. hdr = &fmanfw->header;
  415. length = be32_to_cpu(hdr->length);
  416. /* Verify the firmware. */
  417. if ((hdr->magic[0] != 'Q') || (hdr->magic[1] != 'E') ||
  418. (hdr->magic[2] != 'F')) {
  419. printf("Data at %p is not an Fman firmware\n", fmanfw);
  420. return;
  421. }
  422. if (length > CONFIG_SYS_QE_FMAN_FW_LENGTH) {
  423. printf("Fman firmware at %p is too large (size=%u)\n",
  424. fmanfw, length);
  425. return;
  426. }
  427. length -= sizeof(u32); /* Subtract the size of the CRC */
  428. crc = be32_to_cpu(*(u32 *)((void *)fmanfw + length));
  429. if (crc != crc32_no_comp(0, (void *)fmanfw, length)) {
  430. printf("Fman firmware at %p has invalid CRC\n", fmanfw);
  431. return;
  432. }
  433. /* Increase the size of the fdt to make room for the node. */
  434. rc = fdt_increase_size(blob, fmanfw->header.length);
  435. if (rc < 0) {
  436. printf("Unable to make room for Fman firmware: %s\n",
  437. fdt_strerror(rc));
  438. return;
  439. }
  440. /* Create the firmware node. */
  441. fwnode = fdt_add_subnode(blob, fmnode, "fman-firmware");
  442. if (fwnode < 0) {
  443. char s[64];
  444. fdt_get_path(blob, fmnode, s, sizeof(s));
  445. printf("Could not add firmware node to %s: %s\n", s,
  446. fdt_strerror(fwnode));
  447. return;
  448. }
  449. rc = fdt_setprop_string(blob, fwnode, "compatible", "fsl,fman-firmware");
  450. if (rc < 0) {
  451. char s[64];
  452. fdt_get_path(blob, fwnode, s, sizeof(s));
  453. printf("Could not add compatible property to node %s: %s\n", s,
  454. fdt_strerror(rc));
  455. return;
  456. }
  457. phandle = fdt_create_phandle(blob, fwnode);
  458. if (!phandle) {
  459. char s[64];
  460. fdt_get_path(blob, fwnode, s, sizeof(s));
  461. printf("Could not add phandle property to node %s: %s\n", s,
  462. fdt_strerror(rc));
  463. return;
  464. }
  465. rc = fdt_setprop(blob, fwnode, "fsl,firmware", fmanfw, fmanfw->header.length);
  466. if (rc < 0) {
  467. char s[64];
  468. fdt_get_path(blob, fwnode, s, sizeof(s));
  469. printf("Could not add firmware property to node %s: %s\n", s,
  470. fdt_strerror(rc));
  471. return;
  472. }
  473. /* Find all other Fman nodes and point them to the firmware node. */
  474. while ((fmnode = fdt_node_offset_by_compatible(blob, fmnode, "fsl,fman")) > 0) {
  475. rc = fdt_setprop_cell(blob, fmnode, "fsl,firmware-phandle", phandle);
  476. if (rc < 0) {
  477. char s[64];
  478. fdt_get_path(blob, fmnode, s, sizeof(s));
  479. printf("Could not add pointer property to node %s: %s\n",
  480. s, fdt_strerror(rc));
  481. return;
  482. }
  483. }
  484. }
  485. #else
  486. #define fdt_fixup_fman_firmware(x)
  487. #endif
  488. #if defined(CONFIG_PPC_P4080)
  489. static void fdt_fixup_usb(void *fdt)
  490. {
  491. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  492. u32 rcwsr11 = in_be32(&gur->rcwsr[11]);
  493. int off;
  494. off = fdt_node_offset_by_compatible(fdt, -1, "fsl,mpc85xx-usb2-mph");
  495. if ((rcwsr11 & FSL_CORENET_RCWSR11_EC1) !=
  496. FSL_CORENET_RCWSR11_EC1_FM1_USB1)
  497. fdt_status_disabled(fdt, off);
  498. off = fdt_node_offset_by_compatible(fdt, -1, "fsl,mpc85xx-usb2-dr");
  499. if ((rcwsr11 & FSL_CORENET_RCWSR11_EC2) !=
  500. FSL_CORENET_RCWSR11_EC2_USB2)
  501. fdt_status_disabled(fdt, off);
  502. }
  503. #else
  504. #define fdt_fixup_usb(x)
  505. #endif
  506. void ft_cpu_setup(void *blob, bd_t *bd)
  507. {
  508. int off;
  509. int val;
  510. sys_info_t sysinfo;
  511. /* delete crypto node if not on an E-processor */
  512. if (!IS_E_PROCESSOR(get_svr()))
  513. fdt_fixup_crypto_node(blob, 0);
  514. #if CONFIG_SYS_FSL_SEC_COMPAT >= 4
  515. else {
  516. ccsr_sec_t __iomem *sec;
  517. sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR;
  518. fdt_fixup_crypto_node(blob, in_be32(&sec->secvid_ms));
  519. }
  520. #endif
  521. fdt_fixup_ethernet(blob);
  522. fdt_add_enet_stashing(blob);
  523. #ifndef CONFIG_FSL_TBCLK_EXTRA_DIV
  524. #define CONFIG_FSL_TBCLK_EXTRA_DIV 1
  525. #endif
  526. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  527. "timebase-frequency", get_tbclk() / CONFIG_FSL_TBCLK_EXTRA_DIV,
  528. 1);
  529. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  530. "bus-frequency", bd->bi_busfreq, 1);
  531. get_sys_info(&sysinfo);
  532. off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
  533. while (off != -FDT_ERR_NOTFOUND) {
  534. u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
  535. val = cpu_to_fdt32(sysinfo.freqProcessor[*reg]);
  536. fdt_setprop(blob, off, "clock-frequency", &val, 4);
  537. off = fdt_node_offset_by_prop_value(blob, off, "device_type",
  538. "cpu", 4);
  539. }
  540. do_fixup_by_prop_u32(blob, "device_type", "soc", 4,
  541. "bus-frequency", bd->bi_busfreq, 1);
  542. do_fixup_by_compat_u32(blob, "fsl,pq3-localbus",
  543. "bus-frequency", gd->arch.lbc_clk, 1);
  544. do_fixup_by_compat_u32(blob, "fsl,elbc",
  545. "bus-frequency", gd->arch.lbc_clk, 1);
  546. #ifdef CONFIG_QE
  547. ft_qe_setup(blob);
  548. ft_fixup_qe_snum(blob);
  549. #endif
  550. fdt_fixup_fman_firmware(blob);
  551. #ifdef CONFIG_SYS_NS16550
  552. do_fixup_by_compat_u32(blob, "ns16550",
  553. "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
  554. #endif
  555. #ifdef CONFIG_CPM2
  556. do_fixup_by_compat_u32(blob, "fsl,cpm2-scc-uart",
  557. "current-speed", bd->bi_baudrate, 1);
  558. do_fixup_by_compat_u32(blob, "fsl,cpm2-brg",
  559. "clock-frequency", bd->bi_brgfreq, 1);
  560. #endif
  561. #ifdef CONFIG_FSL_CORENET
  562. do_fixup_by_compat_u32(blob, "fsl,qoriq-clockgen-1.0",
  563. "clock-frequency", CONFIG_SYS_CLK_FREQ, 1);
  564. do_fixup_by_compat_u32(blob, "fsl,qoriq-clockgen-2.0",
  565. "clock-frequency", CONFIG_SYS_CLK_FREQ, 1);
  566. do_fixup_by_compat_u32(blob, "fsl,mpic",
  567. "clock-frequency", get_bus_freq(0)/2, 1);
  568. #else
  569. do_fixup_by_compat_u32(blob, "fsl,mpic",
  570. "clock-frequency", get_bus_freq(0), 1);
  571. #endif
  572. fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
  573. #ifdef CONFIG_MP
  574. ft_fixup_cpu(blob, (u64)bd->bi_memstart + (u64)bd->bi_memsize);
  575. ft_fixup_num_cores(blob);
  576. #endif
  577. ft_fixup_cache(blob);
  578. #if defined(CONFIG_FSL_ESDHC)
  579. fdt_fixup_esdhc(blob, bd);
  580. #endif
  581. ft_fixup_dpaa_clks(blob);
  582. #if defined(CONFIG_SYS_BMAN_MEM_PHYS)
  583. fdt_portal(blob, "fsl,bman-portal", "bman-portals",
  584. (u64)CONFIG_SYS_BMAN_MEM_PHYS,
  585. CONFIG_SYS_BMAN_MEM_SIZE);
  586. fdt_fixup_bportals(blob);
  587. #endif
  588. #if defined(CONFIG_SYS_QMAN_MEM_PHYS)
  589. fdt_portal(blob, "fsl,qman-portal", "qman-portals",
  590. (u64)CONFIG_SYS_QMAN_MEM_PHYS,
  591. CONFIG_SYS_QMAN_MEM_SIZE);
  592. fdt_fixup_qportals(blob);
  593. #endif
  594. #ifdef CONFIG_SYS_SRIO
  595. ft_srio_setup(blob);
  596. #endif
  597. /*
  598. * system-clock = CCB clock/2
  599. * Here gd->bus_clk = CCB clock
  600. * We are using the system clock as 1588 Timer reference
  601. * clock source select
  602. */
  603. do_fixup_by_compat_u32(blob, "fsl,gianfar-ptp-timer",
  604. "timer-frequency", gd->bus_clk/2, 1);
  605. /*
  606. * clock-freq should change to clock-frequency and
  607. * flexcan-v1.0 should change to p1010-flexcan respectively
  608. * in the future.
  609. */
  610. do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0",
  611. "clock_freq", gd->bus_clk/2, 1);
  612. do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0",
  613. "clock-frequency", gd->bus_clk/2, 1);
  614. do_fixup_by_compat_u32(blob, "fsl,p1010-flexcan",
  615. "clock-frequency", gd->bus_clk/2, 1);
  616. fdt_fixup_usb(blob);
  617. }
  618. /*
  619. * For some CCSR devices, we only have the virtual address, not the physical
  620. * address. This is because we map CCSR as a whole, so we typically don't need
  621. * a macro for the physical address of any device within CCSR. In this case,
  622. * we calculate the physical address of that device using it's the difference
  623. * between the virtual address of the device and the virtual address of the
  624. * beginning of CCSR.
  625. */
  626. #define CCSR_VIRT_TO_PHYS(x) \
  627. (CONFIG_SYS_CCSRBAR_PHYS + ((x) - CONFIG_SYS_CCSRBAR))
  628. static void msg(const char *name, uint64_t uaddr, uint64_t daddr)
  629. {
  630. printf("Warning: U-Boot configured %s at address %llx,\n"
  631. "but the device tree has it at %llx\n", name, uaddr, daddr);
  632. }
  633. /*
  634. * Verify the device tree
  635. *
  636. * This function compares several CONFIG_xxx macros that contain physical
  637. * addresses with the corresponding nodes in the device tree, to see if
  638. * the physical addresses are all correct. For example, if
  639. * CONFIG_SYS_NS16550_COM1 is defined, then it contains the virtual address
  640. * of the first UART. We convert this to a physical address and compare
  641. * that with the physical address of the first ns16550-compatible node
  642. * in the device tree. If they don't match, then we display a warning.
  643. *
  644. * Returns 1 on success, 0 on failure
  645. */
  646. int ft_verify_fdt(void *fdt)
  647. {
  648. uint64_t addr = 0;
  649. int aliases;
  650. int off;
  651. /* First check the CCSR base address */
  652. off = fdt_node_offset_by_prop_value(fdt, -1, "device_type", "soc", 4);
  653. if (off > 0)
  654. addr = fdt_get_base_address(fdt, off);
  655. if (!addr) {
  656. printf("Warning: could not determine base CCSR address in "
  657. "device tree\n");
  658. /* No point in checking anything else */
  659. return 0;
  660. }
  661. if (addr != CONFIG_SYS_CCSRBAR_PHYS) {
  662. msg("CCSR", CONFIG_SYS_CCSRBAR_PHYS, addr);
  663. /* No point in checking anything else */
  664. return 0;
  665. }
  666. /*
  667. * Check some nodes via aliases. We assume that U-Boot and the device
  668. * tree enumerate the devices equally. E.g. the first serial port in
  669. * U-Boot is the same as "serial0" in the device tree.
  670. */
  671. aliases = fdt_path_offset(fdt, "/aliases");
  672. if (aliases > 0) {
  673. #ifdef CONFIG_SYS_NS16550_COM1
  674. if (!fdt_verify_alias_address(fdt, aliases, "serial0",
  675. CCSR_VIRT_TO_PHYS(CONFIG_SYS_NS16550_COM1)))
  676. return 0;
  677. #endif
  678. #ifdef CONFIG_SYS_NS16550_COM2
  679. if (!fdt_verify_alias_address(fdt, aliases, "serial1",
  680. CCSR_VIRT_TO_PHYS(CONFIG_SYS_NS16550_COM2)))
  681. return 0;
  682. #endif
  683. }
  684. /*
  685. * The localbus node is typically a root node, even though the lbc
  686. * controller is part of CCSR. If we were to put the lbc node under
  687. * the SOC node, then the 'ranges' property in the lbc node would
  688. * translate through the 'ranges' property of the parent SOC node, and
  689. * we don't want that. Since it's a separate node, it's possible for
  690. * the 'reg' property to be wrong, so check it here. For now, we
  691. * only check for "fsl,elbc" nodes.
  692. */
  693. #ifdef CONFIG_SYS_LBC_ADDR
  694. off = fdt_node_offset_by_compatible(fdt, -1, "fsl,elbc");
  695. if (off > 0) {
  696. const fdt32_t *reg = fdt_getprop(fdt, off, "reg", NULL);
  697. if (reg) {
  698. uint64_t uaddr = CCSR_VIRT_TO_PHYS(CONFIG_SYS_LBC_ADDR);
  699. addr = fdt_translate_address(fdt, off, reg);
  700. if (uaddr != addr) {
  701. msg("the localbus", uaddr, addr);
  702. return 0;
  703. }
  704. }
  705. }
  706. #endif
  707. return 1;
  708. }