fdt.c 13 KB

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