fdt.c 22 KB

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