fdt.c 22 KB

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