fdt.c 22 KB

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