xref: /openbmc/u-boot/arch/powerpc/cpu/mpc85xx/fdt.c (revision 028dbb8db1d18c5835ab34659f9ef7a516571524)
1a47a12beSStefan Roese /*
2a09b9b68SKumar Gala  * Copyright 2007-2011 Freescale Semiconductor, Inc.
3a47a12beSStefan Roese  *
4a47a12beSStefan Roese  * (C) Copyright 2000
5a47a12beSStefan Roese  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6a47a12beSStefan Roese  *
71a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
8a47a12beSStefan Roese  */
9a47a12beSStefan Roese 
10a47a12beSStefan Roese #include <common.h>
11a47a12beSStefan Roese #include <libfdt.h>
12a47a12beSStefan Roese #include <fdt_support.h>
13a47a12beSStefan Roese #include <asm/processor.h>
14a47a12beSStefan Roese #include <linux/ctype.h>
156aba33e9SKumar Gala #include <asm/io.h>
16db977abfSKumar Gala #include <asm/fsl_portals.h>
17377ffcfaSSandeep Singh #include <hwconfig.h>
18a47a12beSStefan Roese #ifdef CONFIG_FSL_ESDHC
19a47a12beSStefan Roese #include <fsl_esdhc.h>
20a47a12beSStefan Roese #endif
21ffadc441STimur Tabi #include "../../../../drivers/qe/qe.h"		/* For struct qe_firmware */
22a47a12beSStefan Roese 
23a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR;
24a47a12beSStefan Roese 
25a47a12beSStefan Roese extern void ft_qe_setup(void *blob);
26a47a12beSStefan Roese extern void ft_fixup_num_cores(void *blob);
27a09b9b68SKumar Gala extern void ft_srio_setup(void *blob);
28a47a12beSStefan Roese 
29a47a12beSStefan Roese #ifdef CONFIG_MP
30a47a12beSStefan Roese #include "mp.h"
31a47a12beSStefan Roese 
32a47a12beSStefan Roese void ft_fixup_cpu(void *blob, u64 memory_limit)
33a47a12beSStefan Roese {
34a47a12beSStefan Roese 	int off;
35ffd06e02SYork Sun 	phys_addr_t spin_tbl_addr = get_spin_phys_addr();
36eb539412SYork Sun 	u32 bootpg = determine_mp_bootpg(NULL);
37a47a12beSStefan Roese 	u32 id = get_my_id();
389d64c6bbSAaron Sierra 	const char *enable_method;
39377ffcfaSSandeep Singh #if defined(T1040_TDM_QUIRK_CCSR_BASE)
40377ffcfaSSandeep Singh 	int ret;
41377ffcfaSSandeep Singh 	int tdm_hwconfig_enabled = 0;
42377ffcfaSSandeep Singh 	char buffer[HWCONFIG_BUFFER_SIZE] = {0};
43377ffcfaSSandeep Singh #endif
44a47a12beSStefan Roese 
45a47a12beSStefan Roese 	off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
46a47a12beSStefan Roese 	while (off != -FDT_ERR_NOTFOUND) {
47a47a12beSStefan Roese 		u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
48a47a12beSStefan Roese 
49a47a12beSStefan Roese 		if (reg) {
50709389b6SYork Sun 			u32 phys_cpu_id = thread_to_core(*reg);
51709389b6SYork Sun 			u64 val = phys_cpu_id * SIZE_BOOT_ENTRY + spin_tbl_addr;
52709389b6SYork Sun 			val = cpu_to_fdt64(val);
53b80d3054SMatthew McClintock 			if (*reg == id) {
54b80d3054SMatthew McClintock 				fdt_setprop_string(blob, off, "status",
55b80d3054SMatthew McClintock 								"okay");
56b80d3054SMatthew McClintock 			} else {
57a47a12beSStefan Roese 				fdt_setprop_string(blob, off, "status",
58a47a12beSStefan Roese 								"disabled");
59b80d3054SMatthew McClintock 			}
609d64c6bbSAaron Sierra 
619d64c6bbSAaron Sierra 			if (hold_cores_in_reset(0)) {
629d64c6bbSAaron Sierra #ifdef CONFIG_FSL_CORENET
639d64c6bbSAaron Sierra 				/* Cores held in reset, use BRR to release */
649d64c6bbSAaron Sierra 				enable_method = "fsl,brr-holdoff";
659d64c6bbSAaron Sierra #else
669d64c6bbSAaron Sierra 				/* Cores held in reset, use EEBPCR to release */
679d64c6bbSAaron Sierra 				enable_method = "fsl,eebpcr-holdoff";
689d64c6bbSAaron Sierra #endif
699d64c6bbSAaron Sierra 			} else {
709d64c6bbSAaron Sierra 				/* Cores out of reset and in a spin-loop */
719d64c6bbSAaron Sierra 				enable_method = "spin-table";
729d64c6bbSAaron Sierra 
73a47a12beSStefan Roese 				fdt_setprop(blob, off, "cpu-release-addr",
74a47a12beSStefan Roese 						&val, sizeof(val));
759d64c6bbSAaron Sierra 			}
769d64c6bbSAaron Sierra 
779d64c6bbSAaron Sierra 			fdt_setprop_string(blob, off, "enable-method",
789d64c6bbSAaron Sierra 							enable_method);
79a47a12beSStefan Roese 		} else {
80a47a12beSStefan Roese 			printf ("cpu NULL\n");
81a47a12beSStefan Roese 		}
82a47a12beSStefan Roese 		off = fdt_node_offset_by_prop_value(blob, off,
83a47a12beSStefan Roese 				"device_type", "cpu", 4);
84a47a12beSStefan Roese 	}
85a47a12beSStefan Roese 
86377ffcfaSSandeep Singh #if defined(T1040_TDM_QUIRK_CCSR_BASE)
87377ffcfaSSandeep Singh #define	CONFIG_MEM_HOLE_16M	0x1000000
88377ffcfaSSandeep Singh 	/*
89377ffcfaSSandeep Singh 	 * Extract hwconfig from environment.
90377ffcfaSSandeep Singh 	 * Search for tdm entry in hwconfig.
91377ffcfaSSandeep Singh 	 */
92377ffcfaSSandeep Singh 	ret = getenv_f("hwconfig", buffer, sizeof(buffer));
93377ffcfaSSandeep Singh 	if (ret > 0)
94377ffcfaSSandeep Singh 		tdm_hwconfig_enabled = hwconfig_f("tdm", buffer);
95377ffcfaSSandeep Singh 
96377ffcfaSSandeep Singh 	/* Reserve the memory hole created by TDM LAW, so OSes dont use it */
97377ffcfaSSandeep Singh 	if (tdm_hwconfig_enabled) {
98377ffcfaSSandeep Singh 		off = fdt_add_mem_rsv(blob, T1040_TDM_QUIRK_CCSR_BASE,
99377ffcfaSSandeep Singh 				      CONFIG_MEM_HOLE_16M);
100377ffcfaSSandeep Singh 		if (off < 0)
101377ffcfaSSandeep Singh 			printf("Failed  to reserve memory for tdm: %s\n",
102377ffcfaSSandeep Singh 			       fdt_strerror(off));
103377ffcfaSSandeep Singh 	}
104377ffcfaSSandeep Singh #endif
105377ffcfaSSandeep Singh 
106a47a12beSStefan Roese 	/* Reserve the boot page so OSes dont use it */
107a47a12beSStefan Roese 	if ((u64)bootpg < memory_limit) {
108a47a12beSStefan Roese 		off = fdt_add_mem_rsv(blob, bootpg, (u64)4096);
109a47a12beSStefan Roese 		if (off < 0)
110ffd06e02SYork Sun 			printf("Failed to reserve memory for bootpg: %s\n",
111ffd06e02SYork Sun 				fdt_strerror(off));
112ffd06e02SYork Sun 	}
1132d9f26b6SYork Sun 
1142d9f26b6SYork Sun #ifndef CONFIG_MPC8xxx_DISABLE_BPTR
1152d9f26b6SYork Sun 	/*
1162d9f26b6SYork Sun 	 * Reserve the default boot page so OSes dont use it.
1172d9f26b6SYork Sun 	 * The default boot page is always mapped to bootpg above using
1182d9f26b6SYork Sun 	 * boot page translation.
1192d9f26b6SYork Sun 	 */
1202d9f26b6SYork Sun 	if (0xfffff000ull < memory_limit) {
1212d9f26b6SYork Sun 		off = fdt_add_mem_rsv(blob, 0xfffff000ull, (u64)4096);
1222d9f26b6SYork Sun 		if (off < 0) {
1232d9f26b6SYork Sun 			printf("Failed to reserve memory for 0xfffff000: %s\n",
1242d9f26b6SYork Sun 				fdt_strerror(off));
1252d9f26b6SYork Sun 		}
1262d9f26b6SYork Sun 	}
1272d9f26b6SYork Sun #endif
1282d9f26b6SYork Sun 
129ffd06e02SYork Sun 	/* Reserve spin table page */
130ffd06e02SYork Sun 	if (spin_tbl_addr < memory_limit) {
131ffd06e02SYork Sun 		off = fdt_add_mem_rsv(blob,
132ffd06e02SYork Sun 			(spin_tbl_addr & ~0xffful), 4096);
133ffd06e02SYork Sun 		if (off < 0)
134ffd06e02SYork Sun 			printf("Failed to reserve memory for spin table: %s\n",
135ffd06e02SYork Sun 				fdt_strerror(off));
136a47a12beSStefan Roese 	}
137ce249d95STang Yuantian #ifdef CONFIG_DEEP_SLEEP
138ce249d95STang Yuantian #ifdef CONFIG_SPL_MMC_BOOT
139ce249d95STang Yuantian 	off = fdt_add_mem_rsv(blob, CONFIG_SYS_MMC_U_BOOT_START,
140ce249d95STang Yuantian 		CONFIG_SYS_MMC_U_BOOT_SIZE);
141ce249d95STang Yuantian 	if (off < 0)
142ce249d95STang Yuantian 		printf("Failed to reserve memory for SD deep sleep: %s\n",
143ce249d95STang Yuantian 		       fdt_strerror(off));
144ce249d95STang Yuantian #elif defined(CONFIG_SPL_SPI_BOOT)
145ce249d95STang Yuantian 	off = fdt_add_mem_rsv(blob, CONFIG_SYS_SPI_FLASH_U_BOOT_START,
146ce249d95STang Yuantian 		CONFIG_SYS_SPI_FLASH_U_BOOT_SIZE);
147ce249d95STang Yuantian 	if (off < 0)
148ce249d95STang Yuantian 		printf("Failed to reserve memory for SPI deep sleep: %s\n",
149ce249d95STang Yuantian 		       fdt_strerror(off));
150ce249d95STang Yuantian #endif
151ce249d95STang Yuantian #endif
152a47a12beSStefan Roese }
153a47a12beSStefan Roese #endif
154a47a12beSStefan Roese 
1556aba33e9SKumar Gala #ifdef CONFIG_SYS_FSL_CPC
1566aba33e9SKumar Gala static inline void ft_fixup_l3cache(void *blob, int off)
1576aba33e9SKumar Gala {
1586aba33e9SKumar Gala 	u32 line_size, num_ways, size, num_sets;
1596aba33e9SKumar Gala 	cpc_corenet_t *cpc = (void *)CONFIG_SYS_FSL_CPC_ADDR;
1606aba33e9SKumar Gala 	u32 cfg0 = in_be32(&cpc->cpccfg0);
1616aba33e9SKumar Gala 
1626aba33e9SKumar Gala 	size = CPC_CFG0_SZ_K(cfg0) * 1024 * CONFIG_SYS_NUM_CPC;
1636aba33e9SKumar Gala 	num_ways = CPC_CFG0_NUM_WAYS(cfg0);
1646aba33e9SKumar Gala 	line_size = CPC_CFG0_LINE_SZ(cfg0);
1656aba33e9SKumar Gala 	num_sets = size / (line_size * num_ways);
1666aba33e9SKumar Gala 
1676aba33e9SKumar Gala 	fdt_setprop(blob, off, "cache-unified", NULL, 0);
1686aba33e9SKumar Gala 	fdt_setprop_cell(blob, off, "cache-block-size", line_size);
1696aba33e9SKumar Gala 	fdt_setprop_cell(blob, off, "cache-size", size);
1706aba33e9SKumar Gala 	fdt_setprop_cell(blob, off, "cache-sets", num_sets);
1716aba33e9SKumar Gala 	fdt_setprop_cell(blob, off, "cache-level", 3);
1726aba33e9SKumar Gala #ifdef CONFIG_SYS_CACHE_STASHING
1736aba33e9SKumar Gala 	fdt_setprop_cell(blob, off, "cache-stash-id", 1);
1746aba33e9SKumar Gala #endif
1756aba33e9SKumar Gala }
1766aba33e9SKumar Gala #else
177a47a12beSStefan Roese #define ft_fixup_l3cache(x, y)
1786aba33e9SKumar Gala #endif
179a47a12beSStefan Roese 
180a47a12beSStefan Roese #if defined(CONFIG_L2_CACHE)
181a47a12beSStefan Roese /* return size in kilobytes */
182a47a12beSStefan Roese static inline u32 l2cache_size(void)
183a47a12beSStefan Roese {
184a47a12beSStefan Roese 	volatile ccsr_l2cache_t *l2cache = (void *)CONFIG_SYS_MPC85xx_L2_ADDR;
185a47a12beSStefan Roese 	volatile u32 l2siz_field = (l2cache->l2ctl >> 28) & 0x3;
186a47a12beSStefan Roese 	u32 ver = SVR_SOC_VER(get_svr());
187a47a12beSStefan Roese 
188a47a12beSStefan Roese 	switch (l2siz_field) {
189a47a12beSStefan Roese 	case 0x0:
190a47a12beSStefan Roese 		break;
191a47a12beSStefan Roese 	case 0x1:
192a47a12beSStefan Roese 		if (ver == SVR_8540 || ver == SVR_8560   ||
19348f6a5c3SYork Sun 		    ver == SVR_8541 || ver == SVR_8555)
194a47a12beSStefan Roese 			return 128;
195a47a12beSStefan Roese 		else
196a47a12beSStefan Roese 			return 256;
197a47a12beSStefan Roese 		break;
198a47a12beSStefan Roese 	case 0x2:
199a47a12beSStefan Roese 		if (ver == SVR_8540 || ver == SVR_8560   ||
20048f6a5c3SYork Sun 		    ver == SVR_8541 || ver == SVR_8555)
201a47a12beSStefan Roese 			return 256;
202a47a12beSStefan Roese 		else
203a47a12beSStefan Roese 			return 512;
204a47a12beSStefan Roese 		break;
205a47a12beSStefan Roese 	case 0x3:
206a47a12beSStefan Roese 		return 1024;
207a47a12beSStefan Roese 		break;
208a47a12beSStefan Roese 	}
209a47a12beSStefan Roese 
210a47a12beSStefan Roese 	return 0;
211a47a12beSStefan Roese }
212a47a12beSStefan Roese 
213a47a12beSStefan Roese static inline void ft_fixup_l2cache(void *blob)
214a47a12beSStefan Roese {
215a47a12beSStefan Roese 	int len, off;
216a47a12beSStefan Roese 	u32 *ph;
217a47a12beSStefan Roese 	struct cpu_type *cpu = identify_cpu(SVR_SOC_VER(get_svr()));
218a47a12beSStefan Roese 
219a47a12beSStefan Roese 	const u32 line_size = 32;
220a47a12beSStefan Roese 	const u32 num_ways = 8;
221a47a12beSStefan Roese 	const u32 size = l2cache_size() * 1024;
222a47a12beSStefan Roese 	const u32 num_sets = size / (line_size * num_ways);
223a47a12beSStefan Roese 
224a47a12beSStefan Roese 	off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
225a47a12beSStefan Roese 	if (off < 0) {
226a47a12beSStefan Roese 		debug("no cpu node fount\n");
227a47a12beSStefan Roese 		return;
228a47a12beSStefan Roese 	}
229a47a12beSStefan Roese 
230a47a12beSStefan Roese 	ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0);
231a47a12beSStefan Roese 
232a47a12beSStefan Roese 	if (ph == NULL) {
233a47a12beSStefan Roese 		debug("no next-level-cache property\n");
234a47a12beSStefan Roese 		return ;
235a47a12beSStefan Roese 	}
236a47a12beSStefan Roese 
237a47a12beSStefan Roese 	off = fdt_node_offset_by_phandle(blob, *ph);
238a47a12beSStefan Roese 	if (off < 0) {
239a47a12beSStefan Roese 		printf("%s: %s\n", __func__, fdt_strerror(off));
240a47a12beSStefan Roese 		return ;
241a47a12beSStefan Roese 	}
242a47a12beSStefan Roese 
243a47a12beSStefan Roese 	if (cpu) {
244ee4756d4STimur Tabi 		char buf[40];
245a47a12beSStefan Roese 
246ee4756d4STimur Tabi 		if (isdigit(cpu->name[0])) {
247ee4756d4STimur Tabi 			/* MPCxxxx, where xxxx == 4-digit number */
248ee4756d4STimur Tabi 			len = sprintf(buf, "fsl,mpc%s-l2-cache-controller",
249ee4756d4STimur Tabi 				cpu->name) + 1;
250ee4756d4STimur Tabi 		} else {
251ee4756d4STimur Tabi 			/* Pxxxx or Txxxx, where xxxx == 4-digit number */
252ee4756d4STimur Tabi 			len = sprintf(buf, "fsl,%c%s-l2-cache-controller",
253ee4756d4STimur Tabi 				tolower(cpu->name[0]), cpu->name + 1) + 1;
254ee4756d4STimur Tabi 		}
255ee4756d4STimur Tabi 
256ee4756d4STimur Tabi 		/*
257ee4756d4STimur Tabi 		 * append "cache" after the NULL character that the previous
258ee4756d4STimur Tabi 		 * sprintf wrote.  This is how a device tree stores multiple
259ee4756d4STimur Tabi 		 * strings in a property.
260ee4756d4STimur Tabi 		 */
261ee4756d4STimur Tabi 		len += sprintf(buf + len, "cache") + 1;
262ee4756d4STimur Tabi 
263ee4756d4STimur Tabi 		fdt_setprop(blob, off, "compatible", buf, len);
264a47a12beSStefan Roese 	}
265a47a12beSStefan Roese 	fdt_setprop(blob, off, "cache-unified", NULL, 0);
266a47a12beSStefan Roese 	fdt_setprop_cell(blob, off, "cache-block-size", line_size);
267a47a12beSStefan Roese 	fdt_setprop_cell(blob, off, "cache-size", size);
268a47a12beSStefan Roese 	fdt_setprop_cell(blob, off, "cache-sets", num_sets);
269a47a12beSStefan Roese 	fdt_setprop_cell(blob, off, "cache-level", 2);
270a47a12beSStefan Roese 
271a47a12beSStefan Roese 	/* we dont bother w/L3 since no platform of this type has one */
272a47a12beSStefan Roese }
2736d2b9da1SYork Sun #elif defined(CONFIG_BACKSIDE_L2_CACHE) || \
2746d2b9da1SYork Sun 	defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2)
275a47a12beSStefan Roese static inline void ft_fixup_l2cache(void *blob)
276a47a12beSStefan Roese {
277a47a12beSStefan Roese 	int off, l2_off, l3_off = -1;
278a47a12beSStefan Roese 	u32 *ph;
2796d2b9da1SYork Sun #ifdef	CONFIG_BACKSIDE_L2_CACHE
280a47a12beSStefan Roese 	u32 l2cfg0 = mfspr(SPRN_L2CFG0);
2816d2b9da1SYork Sun #else
2826d2b9da1SYork Sun 	struct ccsr_cluster_l2 *l2cache =
2836d2b9da1SYork Sun 		(struct ccsr_cluster_l2 __iomem *)(CONFIG_SYS_FSL_CLUSTER_1_L2);
2846d2b9da1SYork Sun 	u32 l2cfg0 = in_be32(&l2cache->l2cfg0);
2856d2b9da1SYork Sun #endif
286a47a12beSStefan Roese 	u32 size, line_size, num_ways, num_sets;
287acf3f8daSKumar Gala 	int has_l2 = 1;
288acf3f8daSKumar Gala 
289acf3f8daSKumar Gala 	/* P2040/P2040E has no L2, so dont set any L2 props */
29048f6a5c3SYork Sun 	if (SVR_SOC_VER(get_svr()) == SVR_P2040)
291acf3f8daSKumar Gala 		has_l2 = 0;
292a47a12beSStefan Roese 
293a47a12beSStefan Roese 	size = (l2cfg0 & 0x3fff) * 64 * 1024;
294a47a12beSStefan Roese 	num_ways = ((l2cfg0 >> 14) & 0x1f) + 1;
295a47a12beSStefan Roese 	line_size = (((l2cfg0 >> 23) & 0x3) + 1) * 32;
296a47a12beSStefan Roese 	num_sets = size / (line_size * num_ways);
297a47a12beSStefan Roese 
298a47a12beSStefan Roese 	off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
299a47a12beSStefan Roese 
300a47a12beSStefan Roese 	while (off != -FDT_ERR_NOTFOUND) {
301a47a12beSStefan Roese 		ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0);
302a47a12beSStefan Roese 
303a47a12beSStefan Roese 		if (ph == NULL) {
304a47a12beSStefan Roese 			debug("no next-level-cache property\n");
305a47a12beSStefan Roese 			goto next;
306a47a12beSStefan Roese 		}
307a47a12beSStefan Roese 
308a47a12beSStefan Roese 		l2_off = fdt_node_offset_by_phandle(blob, *ph);
309a47a12beSStefan Roese 		if (l2_off < 0) {
310a47a12beSStefan Roese 			printf("%s: %s\n", __func__, fdt_strerror(off));
311a47a12beSStefan Roese 			goto next;
312a47a12beSStefan Roese 		}
313a47a12beSStefan Roese 
314acf3f8daSKumar Gala 		if (has_l2) {
315a47a12beSStefan Roese #ifdef CONFIG_SYS_CACHE_STASHING
316a47a12beSStefan Roese 			u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
317e9827468SPrabhakar Kushwaha #if defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500)
3186d2b9da1SYork Sun 			/* Only initialize every eighth thread */
3198d451a71SScott Wood 			if (reg && !((*reg) % 8)) {
3208d451a71SScott Wood 				fdt_setprop_cell(blob, l2_off, "cache-stash-id",
3218d451a71SScott Wood 						 (*reg / 4) + 32 + 1);
3228d451a71SScott Wood 			}
3236d2b9da1SYork Sun #else
3248d451a71SScott Wood 			if (reg) {
325a47a12beSStefan Roese 				fdt_setprop_cell(blob, l2_off, "cache-stash-id",
326a47a12beSStefan Roese 						 (*reg * 2) + 32 + 1);
3278d451a71SScott Wood 			}
3288d451a71SScott Wood #endif
329a47a12beSStefan Roese #endif
330a47a12beSStefan Roese 
331a47a12beSStefan Roese 			fdt_setprop(blob, l2_off, "cache-unified", NULL, 0);
332acf3f8daSKumar Gala 			fdt_setprop_cell(blob, l2_off, "cache-block-size",
333acf3f8daSKumar Gala 						line_size);
334a47a12beSStefan Roese 			fdt_setprop_cell(blob, l2_off, "cache-size", size);
335a47a12beSStefan Roese 			fdt_setprop_cell(blob, l2_off, "cache-sets", num_sets);
336a47a12beSStefan Roese 			fdt_setprop_cell(blob, l2_off, "cache-level", 2);
337a47a12beSStefan Roese 			fdt_setprop(blob, l2_off, "compatible", "cache", 6);
338acf3f8daSKumar Gala 		}
339a47a12beSStefan Roese 
340a47a12beSStefan Roese 		if (l3_off < 0) {
341a47a12beSStefan Roese 			ph = (u32 *)fdt_getprop(blob, l2_off, "next-level-cache", 0);
342a47a12beSStefan Roese 
343a47a12beSStefan Roese 			if (ph == NULL) {
344a47a12beSStefan Roese 				debug("no next-level-cache property\n");
345a47a12beSStefan Roese 				goto next;
346a47a12beSStefan Roese 			}
347a47a12beSStefan Roese 			l3_off = *ph;
348a47a12beSStefan Roese 		}
349a47a12beSStefan Roese next:
350a47a12beSStefan Roese 		off = fdt_node_offset_by_prop_value(blob, off,
351a47a12beSStefan Roese 				"device_type", "cpu", 4);
352a47a12beSStefan Roese 	}
353a47a12beSStefan Roese 	if (l3_off > 0) {
354a47a12beSStefan Roese 		l3_off = fdt_node_offset_by_phandle(blob, l3_off);
355a47a12beSStefan Roese 		if (l3_off < 0) {
356a47a12beSStefan Roese 			printf("%s: %s\n", __func__, fdt_strerror(off));
357a47a12beSStefan Roese 			return ;
358a47a12beSStefan Roese 		}
359a47a12beSStefan Roese 		ft_fixup_l3cache(blob, l3_off);
360a47a12beSStefan Roese 	}
361a47a12beSStefan Roese }
362a47a12beSStefan Roese #else
363a47a12beSStefan Roese #define ft_fixup_l2cache(x)
364a47a12beSStefan Roese #endif
365a47a12beSStefan Roese 
366a47a12beSStefan Roese static inline void ft_fixup_cache(void *blob)
367a47a12beSStefan Roese {
368a47a12beSStefan Roese 	int off;
369a47a12beSStefan Roese 
370a47a12beSStefan Roese 	off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
371a47a12beSStefan Roese 
372a47a12beSStefan Roese 	while (off != -FDT_ERR_NOTFOUND) {
373a47a12beSStefan Roese 		u32 l1cfg0 = mfspr(SPRN_L1CFG0);
374a47a12beSStefan Roese 		u32 l1cfg1 = mfspr(SPRN_L1CFG1);
375a47a12beSStefan Roese 		u32 isize, iline_size, inum_sets, inum_ways;
376a47a12beSStefan Roese 		u32 dsize, dline_size, dnum_sets, dnum_ways;
377a47a12beSStefan Roese 
378a47a12beSStefan Roese 		/* d-side config */
379a47a12beSStefan Roese 		dsize = (l1cfg0 & 0x7ff) * 1024;
380a47a12beSStefan Roese 		dnum_ways = ((l1cfg0 >> 11) & 0xff) + 1;
381a47a12beSStefan Roese 		dline_size = (((l1cfg0 >> 23) & 0x3) + 1) * 32;
382a47a12beSStefan Roese 		dnum_sets = dsize / (dline_size * dnum_ways);
383a47a12beSStefan Roese 
384a47a12beSStefan Roese 		fdt_setprop_cell(blob, off, "d-cache-block-size", dline_size);
385a47a12beSStefan Roese 		fdt_setprop_cell(blob, off, "d-cache-size", dsize);
386a47a12beSStefan Roese 		fdt_setprop_cell(blob, off, "d-cache-sets", dnum_sets);
387a47a12beSStefan Roese 
388a47a12beSStefan Roese #ifdef CONFIG_SYS_CACHE_STASHING
389a47a12beSStefan Roese 		{
390a47a12beSStefan Roese 			u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
391a47a12beSStefan Roese 			if (reg)
392a47a12beSStefan Roese 				fdt_setprop_cell(blob, off, "cache-stash-id",
393a47a12beSStefan Roese 					 (*reg * 2) + 32 + 0);
394a47a12beSStefan Roese 		}
395a47a12beSStefan Roese #endif
396a47a12beSStefan Roese 
397a47a12beSStefan Roese 		/* i-side config */
398a47a12beSStefan Roese 		isize = (l1cfg1 & 0x7ff) * 1024;
399a47a12beSStefan Roese 		inum_ways = ((l1cfg1 >> 11) & 0xff) + 1;
400a47a12beSStefan Roese 		iline_size = (((l1cfg1 >> 23) & 0x3) + 1) * 32;
401a47a12beSStefan Roese 		inum_sets = isize / (iline_size * inum_ways);
402a47a12beSStefan Roese 
403a47a12beSStefan Roese 		fdt_setprop_cell(blob, off, "i-cache-block-size", iline_size);
404a47a12beSStefan Roese 		fdt_setprop_cell(blob, off, "i-cache-size", isize);
405a47a12beSStefan Roese 		fdt_setprop_cell(blob, off, "i-cache-sets", inum_sets);
406a47a12beSStefan Roese 
407a47a12beSStefan Roese 		off = fdt_node_offset_by_prop_value(blob, off,
408a47a12beSStefan Roese 				"device_type", "cpu", 4);
409a47a12beSStefan Roese 	}
410a47a12beSStefan Roese 
411a47a12beSStefan Roese 	ft_fixup_l2cache(blob);
412a47a12beSStefan Roese }
413a47a12beSStefan Roese 
414a47a12beSStefan Roese 
415a47a12beSStefan Roese void fdt_add_enet_stashing(void *fdt)
416a47a12beSStefan Roese {
417a47a12beSStefan Roese 	do_fixup_by_compat(fdt, "gianfar", "bd-stash", NULL, 0, 1);
418a47a12beSStefan Roese 
419a47a12beSStefan Roese 	do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-len", 96, 1);
420a47a12beSStefan Roese 
421a47a12beSStefan Roese 	do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-idx", 0, 1);
422eea9a123SPankaj Chauhan 	do_fixup_by_compat(fdt, "fsl,etsec2", "bd-stash", NULL, 0, 1);
423eea9a123SPankaj Chauhan 	do_fixup_by_compat_u32(fdt, "fsl,etsec2", "rx-stash-len", 96, 1);
424eea9a123SPankaj Chauhan 	do_fixup_by_compat_u32(fdt, "fsl,etsec2", "rx-stash-idx", 0, 1);
425a47a12beSStefan Roese }
426a47a12beSStefan Roese 
427a47a12beSStefan Roese #if defined(CONFIG_SYS_DPAA_FMAN) || defined(CONFIG_SYS_DPAA_PME)
428e2d0f255SKumar Gala #ifdef CONFIG_SYS_DPAA_FMAN
4291b942f74SKumar Gala static void ft_fixup_clks(void *blob, const char *compat, u32 offset,
4301b942f74SKumar Gala 			  unsigned long freq)
431a47a12beSStefan Roese {
4321b942f74SKumar Gala 	phys_addr_t phys = offset + CONFIG_SYS_CCSRBAR_PHYS;
4331b942f74SKumar Gala 	int off = fdt_node_offset_by_compat_reg(blob, compat, phys);
434a47a12beSStefan Roese 
435a47a12beSStefan Roese 	if (off >= 0) {
436a47a12beSStefan Roese 		off = fdt_setprop_cell(blob, off, "clock-frequency", freq);
437a47a12beSStefan Roese 		if (off > 0)
438a47a12beSStefan Roese 			printf("WARNING enable to set clock-frequency "
4391b942f74SKumar Gala 				"for %s: %s\n", compat, fdt_strerror(off));
440a47a12beSStefan Roese 	}
441a47a12beSStefan Roese }
442e2d0f255SKumar Gala #endif
443a47a12beSStefan Roese 
444a47a12beSStefan Roese static void ft_fixup_dpaa_clks(void *blob)
445a47a12beSStefan Roese {
446a47a12beSStefan Roese 	sys_info_t sysinfo;
447a47a12beSStefan Roese 
448a47a12beSStefan Roese 	get_sys_info(&sysinfo);
449e2d0f255SKumar Gala #ifdef CONFIG_SYS_DPAA_FMAN
4501b942f74SKumar Gala 	ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM1_OFFSET,
451997399faSPrabhakar Kushwaha 			sysinfo.freq_fman[0]);
452a47a12beSStefan Roese 
453a47a12beSStefan Roese #if (CONFIG_SYS_NUM_FMAN == 2)
4541b942f74SKumar Gala 	ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM2_OFFSET,
455997399faSPrabhakar Kushwaha 			sysinfo.freq_fman[1]);
456a47a12beSStefan Roese #endif
457e2d0f255SKumar Gala #endif
458a47a12beSStefan Roese 
459990e1a8cSHaiying Wang #ifdef CONFIG_SYS_DPAA_QBMAN
460990e1a8cSHaiying Wang 	do_fixup_by_compat_u32(blob, "fsl,qman",
461997399faSPrabhakar Kushwaha 			"clock-frequency", sysinfo.freq_qman, 1);
462990e1a8cSHaiying Wang #endif
463990e1a8cSHaiying Wang 
464a47a12beSStefan Roese #ifdef CONFIG_SYS_DPAA_PME
4651b942f74SKumar Gala 	do_fixup_by_compat_u32(blob, "fsl,pme",
466997399faSPrabhakar Kushwaha 		"clock-frequency", sysinfo.freq_pme, 1);
467a47a12beSStefan Roese #endif
468a47a12beSStefan Roese }
469a47a12beSStefan Roese #else
470a47a12beSStefan Roese #define ft_fixup_dpaa_clks(x)
471a47a12beSStefan Roese #endif
472a47a12beSStefan Roese 
473a47a12beSStefan Roese #ifdef CONFIG_QE
474a47a12beSStefan Roese static void ft_fixup_qe_snum(void *blob)
475a47a12beSStefan Roese {
476a47a12beSStefan Roese 	unsigned int svr;
477a47a12beSStefan Roese 
478a47a12beSStefan Roese 	svr = mfspr(SPRN_SVR);
47948f6a5c3SYork Sun 	if (SVR_SOC_VER(svr) == SVR_8569) {
480a47a12beSStefan Roese 		if(IS_SVR_REV(svr, 1, 0))
481a47a12beSStefan Roese 			do_fixup_by_compat_u32(blob, "fsl,qe",
482a47a12beSStefan Roese 				"fsl,qe-num-snums", 46, 1);
483a47a12beSStefan Roese 		else
484a47a12beSStefan Roese 			do_fixup_by_compat_u32(blob, "fsl,qe",
485a47a12beSStefan Roese 				"fsl,qe-num-snums", 76, 1);
486a47a12beSStefan Roese 	}
487a47a12beSStefan Roese }
488a47a12beSStefan Roese #endif
489a47a12beSStefan Roese 
490ffadc441STimur Tabi /**
491ffadc441STimur Tabi  * fdt_fixup_fman_firmware -- insert the Fman firmware into the device tree
492ffadc441STimur Tabi  *
493ffadc441STimur Tabi  * The binding for an Fman firmware node is documented in
494ffadc441STimur Tabi  * Documentation/powerpc/dts-bindings/fsl/dpaa/fman.txt.  This node contains
495ffadc441STimur Tabi  * the actual Fman firmware binary data.  The operating system is expected to
496ffadc441STimur Tabi  * be able to parse the binary data to determine any attributes it needs.
497ffadc441STimur Tabi  */
498ffadc441STimur Tabi #ifdef CONFIG_SYS_DPAA_FMAN
499ffadc441STimur Tabi void fdt_fixup_fman_firmware(void *blob)
500ffadc441STimur Tabi {
501ffadc441STimur Tabi 	int rc, fmnode, fwnode = -1;
502ffadc441STimur Tabi 	uint32_t phandle;
503ffadc441STimur Tabi 	struct qe_firmware *fmanfw;
504ffadc441STimur Tabi 	const struct qe_header *hdr;
505ffadc441STimur Tabi 	unsigned int length;
506ffadc441STimur Tabi 	uint32_t crc;
507ffadc441STimur Tabi 	const char *p;
508ffadc441STimur Tabi 
509ffadc441STimur Tabi 	/* The first Fman we find will contain the actual firmware. */
510ffadc441STimur Tabi 	fmnode = fdt_node_offset_by_compatible(blob, -1, "fsl,fman");
511ffadc441STimur Tabi 	if (fmnode < 0)
512ffadc441STimur Tabi 		/* Exit silently if there are no Fman devices */
513ffadc441STimur Tabi 		return;
514ffadc441STimur Tabi 
515ffadc441STimur Tabi 	/* If we already have a firmware node, then also exit silently. */
516ffadc441STimur Tabi 	if (fdt_node_offset_by_compatible(blob, -1, "fsl,fman-firmware") > 0)
517ffadc441STimur Tabi 		return;
518ffadc441STimur Tabi 
519ffadc441STimur Tabi 	/* If the environment variable is not set, then exit silently */
520ffadc441STimur Tabi 	p = getenv("fman_ucode");
521ffadc441STimur Tabi 	if (!p)
522ffadc441STimur Tabi 		return;
523ffadc441STimur Tabi 
524e6394e9eSНиколай Пузанов 	fmanfw = (struct qe_firmware *) simple_strtoul(p, NULL, 16);
525ffadc441STimur Tabi 	if (!fmanfw)
526ffadc441STimur Tabi 		return;
527ffadc441STimur Tabi 
528ffadc441STimur Tabi 	hdr = &fmanfw->header;
529ffadc441STimur Tabi 	length = be32_to_cpu(hdr->length);
530ffadc441STimur Tabi 
531ffadc441STimur Tabi 	/* Verify the firmware. */
532ffadc441STimur Tabi 	if ((hdr->magic[0] != 'Q') || (hdr->magic[1] != 'E') ||
533ffadc441STimur Tabi 		(hdr->magic[2] != 'F')) {
534ffadc441STimur Tabi 		printf("Data at %p is not an Fman firmware\n", fmanfw);
535ffadc441STimur Tabi 		return;
536ffadc441STimur Tabi 	}
537ffadc441STimur Tabi 
538f2717b47STimur Tabi 	if (length > CONFIG_SYS_QE_FMAN_FW_LENGTH) {
539ffadc441STimur Tabi 		printf("Fman firmware at %p is too large (size=%u)\n",
540ffadc441STimur Tabi 		       fmanfw, length);
541ffadc441STimur Tabi 		return;
542ffadc441STimur Tabi 	}
543ffadc441STimur Tabi 
544ffadc441STimur Tabi 	length -= sizeof(u32);	/* Subtract the size of the CRC */
545ffadc441STimur Tabi 	crc = be32_to_cpu(*(u32 *)((void *)fmanfw + length));
546ffadc441STimur Tabi 	if (crc != crc32_no_comp(0, (void *)fmanfw, length)) {
547ffadc441STimur Tabi 		printf("Fman firmware at %p has invalid CRC\n", fmanfw);
548ffadc441STimur Tabi 		return;
549ffadc441STimur Tabi 	}
550ffadc441STimur Tabi 
551ffadc441STimur Tabi 	/* Increase the size of the fdt to make room for the node. */
552ffadc441STimur Tabi 	rc = fdt_increase_size(blob, fmanfw->header.length);
553ffadc441STimur Tabi 	if (rc < 0) {
554ffadc441STimur Tabi 		printf("Unable to make room for Fman firmware: %s\n",
555ffadc441STimur Tabi 			fdt_strerror(rc));
556ffadc441STimur Tabi 		return;
557ffadc441STimur Tabi 	}
558ffadc441STimur Tabi 
559ffadc441STimur Tabi 	/* Create the firmware node. */
560ffadc441STimur Tabi 	fwnode = fdt_add_subnode(blob, fmnode, "fman-firmware");
561ffadc441STimur Tabi 	if (fwnode < 0) {
562ffadc441STimur Tabi 		char s[64];
563ffadc441STimur Tabi 		fdt_get_path(blob, fmnode, s, sizeof(s));
564ffadc441STimur Tabi 		printf("Could not add firmware node to %s: %s\n", s,
565ffadc441STimur Tabi 		       fdt_strerror(fwnode));
566ffadc441STimur Tabi 		return;
567ffadc441STimur Tabi 	}
568ffadc441STimur Tabi 	rc = fdt_setprop_string(blob, fwnode, "compatible", "fsl,fman-firmware");
569ffadc441STimur Tabi 	if (rc < 0) {
570ffadc441STimur Tabi 		char s[64];
571ffadc441STimur Tabi 		fdt_get_path(blob, fwnode, s, sizeof(s));
572ffadc441STimur Tabi 		printf("Could not add compatible property to node %s: %s\n", s,
573ffadc441STimur Tabi 		       fdt_strerror(rc));
574ffadc441STimur Tabi 		return;
575ffadc441STimur Tabi 	}
576a2c1229cSTimur Tabi 	phandle = fdt_create_phandle(blob, fwnode);
577a2c1229cSTimur Tabi 	if (!phandle) {
578ffadc441STimur Tabi 		char s[64];
579ffadc441STimur Tabi 		fdt_get_path(blob, fwnode, s, sizeof(s));
580ffadc441STimur Tabi 		printf("Could not add phandle property to node %s: %s\n", s,
581ffadc441STimur Tabi 		       fdt_strerror(rc));
582ffadc441STimur Tabi 		return;
583ffadc441STimur Tabi 	}
584ffadc441STimur Tabi 	rc = fdt_setprop(blob, fwnode, "fsl,firmware", fmanfw, fmanfw->header.length);
585ffadc441STimur Tabi 	if (rc < 0) {
586ffadc441STimur Tabi 		char s[64];
587ffadc441STimur Tabi 		fdt_get_path(blob, fwnode, s, sizeof(s));
588ffadc441STimur Tabi 		printf("Could not add firmware property to node %s: %s\n", s,
589ffadc441STimur Tabi 		       fdt_strerror(rc));
590ffadc441STimur Tabi 		return;
591ffadc441STimur Tabi 	}
592ffadc441STimur Tabi 
593ffadc441STimur Tabi 	/* Find all other Fman nodes and point them to the firmware node. */
594ffadc441STimur Tabi 	while ((fmnode = fdt_node_offset_by_compatible(blob, fmnode, "fsl,fman")) > 0) {
595ffadc441STimur Tabi 		rc = fdt_setprop_cell(blob, fmnode, "fsl,firmware-phandle", phandle);
596ffadc441STimur Tabi 		if (rc < 0) {
597ffadc441STimur Tabi 			char s[64];
598ffadc441STimur Tabi 			fdt_get_path(blob, fmnode, s, sizeof(s));
599ffadc441STimur Tabi 			printf("Could not add pointer property to node %s: %s\n",
600ffadc441STimur Tabi 			       s, fdt_strerror(rc));
601ffadc441STimur Tabi 			return;
602ffadc441STimur Tabi 		}
603ffadc441STimur Tabi 	}
604ffadc441STimur Tabi }
605ffadc441STimur Tabi #else
606ffadc441STimur Tabi #define fdt_fixup_fman_firmware(x)
607ffadc441STimur Tabi #endif
608ffadc441STimur Tabi 
609055ce080STimur Tabi #if defined(CONFIG_PPC_P4080)
610f81f19faSShengzhou Liu static void fdt_fixup_usb(void *fdt)
611f81f19faSShengzhou Liu {
612f81f19faSShengzhou Liu 	ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
613f81f19faSShengzhou Liu 	u32 rcwsr11 = in_be32(&gur->rcwsr[11]);
614f81f19faSShengzhou Liu 	int off;
615f81f19faSShengzhou Liu 
616f81f19faSShengzhou Liu 	off = fdt_node_offset_by_compatible(fdt, -1, "fsl,mpc85xx-usb2-mph");
617f81f19faSShengzhou Liu 	if ((rcwsr11 & FSL_CORENET_RCWSR11_EC1) !=
618f81f19faSShengzhou Liu 				FSL_CORENET_RCWSR11_EC1_FM1_USB1)
619f81f19faSShengzhou Liu 		fdt_status_disabled(fdt, off);
620f81f19faSShengzhou Liu 
621f81f19faSShengzhou Liu 	off = fdt_node_offset_by_compatible(fdt, -1, "fsl,mpc85xx-usb2-dr");
622f81f19faSShengzhou Liu 	if ((rcwsr11 & FSL_CORENET_RCWSR11_EC2) !=
623f81f19faSShengzhou Liu 				FSL_CORENET_RCWSR11_EC2_USB2)
624f81f19faSShengzhou Liu 		fdt_status_disabled(fdt, off);
625f81f19faSShengzhou Liu }
626f81f19faSShengzhou Liu #else
627f81f19faSShengzhou Liu #define fdt_fixup_usb(x)
628f81f19faSShengzhou Liu #endif
629f81f19faSShengzhou Liu 
630605714f6SShengzhou Liu #if defined(CONFIG_PPC_T2080) || defined(CONFIG_PPC_T4240) || \
631605714f6SShengzhou Liu 	defined(CONFIG_PPC_T4160) || defined(CONFIG_PPC_T4080)
632605714f6SShengzhou Liu void fdt_fixup_dma3(void *blob)
633605714f6SShengzhou Liu {
634605714f6SShengzhou Liu 	/* the 3rd DMA is not functional if SRIO2 is chosen */
635605714f6SShengzhou Liu 	int nodeoff;
636605714f6SShengzhou Liu 	ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
637605714f6SShengzhou Liu 
638605714f6SShengzhou Liu #define CONFIG_SYS_ELO3_DMA3 (0xffe000000 + 0x102300)
639605714f6SShengzhou Liu #if defined(CONFIG_PPC_T2080)
640605714f6SShengzhou Liu 	u32 srds_prtcl_s2 = in_be32(&gur->rcwsr[4]) &
641605714f6SShengzhou Liu 				    FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
642605714f6SShengzhou Liu 	srds_prtcl_s2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
643605714f6SShengzhou Liu 
644605714f6SShengzhou Liu 	switch (srds_prtcl_s2) {
645605714f6SShengzhou Liu 	case 0x29:
646605714f6SShengzhou Liu 	case 0x2d:
647605714f6SShengzhou Liu 	case 0x2e:
648605714f6SShengzhou Liu #elif defined(CONFIG_PPC_T4240) || defined(CONFIG_PPC_T4160) || \
649605714f6SShengzhou Liu 	defined(CONFIG_PPC_T4080)
650605714f6SShengzhou Liu 	u32 srds_prtcl_s4 = in_be32(&gur->rcwsr[4]) &
651605714f6SShengzhou Liu 				    FSL_CORENET2_RCWSR4_SRDS4_PRTCL;
652605714f6SShengzhou Liu 	srds_prtcl_s4 >>= FSL_CORENET2_RCWSR4_SRDS4_PRTCL_SHIFT;
653605714f6SShengzhou Liu 
654605714f6SShengzhou Liu 	switch (srds_prtcl_s4) {
655605714f6SShengzhou Liu 	case 6:
656605714f6SShengzhou Liu 	case 8:
657605714f6SShengzhou Liu 	case 14:
658605714f6SShengzhou Liu 	case 16:
659605714f6SShengzhou Liu #endif
660605714f6SShengzhou Liu 		nodeoff = fdt_node_offset_by_compat_reg(blob, "fsl,elo3-dma",
661605714f6SShengzhou Liu 							CONFIG_SYS_ELO3_DMA3);
662605714f6SShengzhou Liu 		if (nodeoff > 0)
663605714f6SShengzhou Liu 			fdt_status_disabled(blob, nodeoff);
664605714f6SShengzhou Liu 		else
665605714f6SShengzhou Liu 			printf("WARNING: unable to disable dma3\n");
666605714f6SShengzhou Liu 		break;
667605714f6SShengzhou Liu 	default:
668605714f6SShengzhou Liu 		break;
669605714f6SShengzhou Liu 	}
670605714f6SShengzhou Liu }
671605714f6SShengzhou Liu #else
672605714f6SShengzhou Liu #define fdt_fixup_dma3(x)
673605714f6SShengzhou Liu #endif
674605714f6SShengzhou Liu 
675d616fc58SCodrin Ciubotariu #if defined(CONFIG_PPC_T1040)
676d616fc58SCodrin Ciubotariu static void fdt_fixup_l2_switch(void *blob)
677d616fc58SCodrin Ciubotariu {
678d616fc58SCodrin Ciubotariu 	uchar l2swaddr[6];
679d616fc58SCodrin Ciubotariu 	int node;
680d616fc58SCodrin Ciubotariu 
681d616fc58SCodrin Ciubotariu 	/* The l2switch node from device-tree has
682d616fc58SCodrin Ciubotariu 	 * compatible string "vitesse-9953" */
683d616fc58SCodrin Ciubotariu 	node = fdt_node_offset_by_compatible(blob, -1, "vitesse-9953");
684d616fc58SCodrin Ciubotariu 	if (node == -FDT_ERR_NOTFOUND)
685d616fc58SCodrin Ciubotariu 		/* no l2switch node has been found */
686d616fc58SCodrin Ciubotariu 		return;
687d616fc58SCodrin Ciubotariu 
688d616fc58SCodrin Ciubotariu 	/* Get MAC address for the l2switch from "l2switchaddr"*/
689d616fc58SCodrin Ciubotariu 	if (!eth_getenv_enetaddr("l2switchaddr", l2swaddr)) {
690d616fc58SCodrin Ciubotariu 		printf("Warning: MAC address for l2switch not found\n");
691d616fc58SCodrin Ciubotariu 		memset(l2swaddr, 0, sizeof(l2swaddr));
692d616fc58SCodrin Ciubotariu 	}
693d616fc58SCodrin Ciubotariu 
694d616fc58SCodrin Ciubotariu 	/* Add MAC address to l2switch node */
695d616fc58SCodrin Ciubotariu 	fdt_setprop(blob, node, "local-mac-address", l2swaddr,
696d616fc58SCodrin Ciubotariu 		    sizeof(l2swaddr));
697d616fc58SCodrin Ciubotariu }
698d616fc58SCodrin Ciubotariu #else
699d616fc58SCodrin Ciubotariu #define fdt_fixup_l2_switch(x)
700d616fc58SCodrin Ciubotariu #endif
701d616fc58SCodrin Ciubotariu 
702a47a12beSStefan Roese void ft_cpu_setup(void *blob, bd_t *bd)
703a47a12beSStefan Roese {
704a47a12beSStefan Roese 	int off;
705a47a12beSStefan Roese 	int val;
70651abee64SLaurentiu TUDOR 	int len;
707a47a12beSStefan Roese 	sys_info_t sysinfo;
708a47a12beSStefan Roese 
709a47a12beSStefan Roese 	/* delete crypto node if not on an E-processor */
710a47a12beSStefan Roese 	if (!IS_E_PROCESSOR(get_svr()))
711a47a12beSStefan Roese 		fdt_fixup_crypto_node(blob, 0);
7125e95e2d8SVakul Garg #if CONFIG_SYS_FSL_SEC_COMPAT >= 4
7135e95e2d8SVakul Garg 	else {
7145e95e2d8SVakul Garg 		ccsr_sec_t __iomem *sec;
7155e95e2d8SVakul Garg 
7165e95e2d8SVakul Garg 		sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR;
717*028dbb8dSRuchika Gupta 		fdt_fixup_crypto_node(blob, sec_in32(&sec->secvid_ms));
7185e95e2d8SVakul Garg 	}
7195e95e2d8SVakul Garg #endif
720a47a12beSStefan Roese 
721a47a12beSStefan Roese 	fdt_fixup_ethernet(blob);
722a47a12beSStefan Roese 
723a47a12beSStefan Roese 	fdt_add_enet_stashing(blob);
724a47a12beSStefan Roese 
725cb93071bSYork Sun #ifndef CONFIG_FSL_TBCLK_EXTRA_DIV
726cb93071bSYork Sun #define CONFIG_FSL_TBCLK_EXTRA_DIV 1
727cb93071bSYork Sun #endif
728a47a12beSStefan Roese 	do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
729cb93071bSYork Sun 		"timebase-frequency", get_tbclk() / CONFIG_FSL_TBCLK_EXTRA_DIV,
730cb93071bSYork Sun 		1);
731a47a12beSStefan Roese 	do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
732a47a12beSStefan Roese 		"bus-frequency", bd->bi_busfreq, 1);
733a47a12beSStefan Roese 	get_sys_info(&sysinfo);
734a47a12beSStefan Roese 	off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
735a47a12beSStefan Roese 	while (off != -FDT_ERR_NOTFOUND) {
73651abee64SLaurentiu TUDOR 		u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", &len);
73751abee64SLaurentiu TUDOR 		val = cpu_to_fdt32(sysinfo.freq_processor[(*reg) / (len / 4)]);
738a47a12beSStefan Roese 		fdt_setprop(blob, off, "clock-frequency", &val, 4);
739a47a12beSStefan Roese 		off = fdt_node_offset_by_prop_value(blob, off, "device_type",
740a47a12beSStefan Roese 							"cpu", 4);
741a47a12beSStefan Roese 	}
742a47a12beSStefan Roese 	do_fixup_by_prop_u32(blob, "device_type", "soc", 4,
743a47a12beSStefan Roese 		"bus-frequency", bd->bi_busfreq, 1);
744a47a12beSStefan Roese 
745a47a12beSStefan Roese 	do_fixup_by_compat_u32(blob, "fsl,pq3-localbus",
74667ac13b1SSimon Glass 		"bus-frequency", gd->arch.lbc_clk, 1);
747a47a12beSStefan Roese 	do_fixup_by_compat_u32(blob, "fsl,elbc",
74867ac13b1SSimon Glass 		"bus-frequency", gd->arch.lbc_clk, 1);
749a47a12beSStefan Roese #ifdef CONFIG_QE
750a47a12beSStefan Roese 	ft_qe_setup(blob);
751a47a12beSStefan Roese 	ft_fixup_qe_snum(blob);
752a47a12beSStefan Roese #endif
753a47a12beSStefan Roese 
754ffadc441STimur Tabi 	fdt_fixup_fman_firmware(blob);
755ffadc441STimur Tabi 
756a47a12beSStefan Roese #ifdef CONFIG_SYS_NS16550
757a47a12beSStefan Roese 	do_fixup_by_compat_u32(blob, "ns16550",
758a47a12beSStefan Roese 		"clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
759a47a12beSStefan Roese #endif
760a47a12beSStefan Roese 
761a47a12beSStefan Roese #ifdef CONFIG_CPM2
762a47a12beSStefan Roese 	do_fixup_by_compat_u32(blob, "fsl,cpm2-scc-uart",
7638e261575SMasahiro Yamada 		"current-speed", gd->baudrate, 1);
764a47a12beSStefan Roese 
765a47a12beSStefan Roese 	do_fixup_by_compat_u32(blob, "fsl,cpm2-brg",
766a47a12beSStefan Roese 		"clock-frequency", bd->bi_brgfreq, 1);
767a47a12beSStefan Roese #endif
768a47a12beSStefan Roese 
76985f8cda3SKumar Gala #ifdef CONFIG_FSL_CORENET
77085f8cda3SKumar Gala 	do_fixup_by_compat_u32(blob, "fsl,qoriq-clockgen-1.0",
77185f8cda3SKumar Gala 		"clock-frequency", CONFIG_SYS_CLK_FREQ, 1);
7727dd09b54SAndy Fleming 	do_fixup_by_compat_u32(blob, "fsl,qoriq-clockgen-2.0",
7737b700d21STang Yuantian 		"clock-frequency", CONFIG_SYS_CLK_FREQ, 1);
774f5c2623dSDongsheng.wang@freescale.com 	do_fixup_by_compat_u32(blob, "fsl,mpic",
775f5c2623dSDongsheng.wang@freescale.com 		"clock-frequency", get_bus_freq(0)/2, 1);
776f5c2623dSDongsheng.wang@freescale.com #else
777f5c2623dSDongsheng.wang@freescale.com 	do_fixup_by_compat_u32(blob, "fsl,mpic",
778f5c2623dSDongsheng.wang@freescale.com 		"clock-frequency", get_bus_freq(0), 1);
77985f8cda3SKumar Gala #endif
78085f8cda3SKumar Gala 
781a47a12beSStefan Roese 	fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
782a47a12beSStefan Roese 
783a47a12beSStefan Roese #ifdef CONFIG_MP
784a47a12beSStefan Roese 	ft_fixup_cpu(blob, (u64)bd->bi_memstart + (u64)bd->bi_memsize);
785a47a12beSStefan Roese 	ft_fixup_num_cores(blob);
7868f3a7fa4SKumar Gala #endif
787a47a12beSStefan Roese 
788a47a12beSStefan Roese 	ft_fixup_cache(blob);
789a47a12beSStefan Roese 
790a47a12beSStefan Roese #if defined(CONFIG_FSL_ESDHC)
791a47a12beSStefan Roese 	fdt_fixup_esdhc(blob, bd);
792a47a12beSStefan Roese #endif
793a47a12beSStefan Roese 
794a47a12beSStefan Roese 	ft_fixup_dpaa_clks(blob);
795db977abfSKumar Gala 
796db977abfSKumar Gala #if defined(CONFIG_SYS_BMAN_MEM_PHYS)
797db977abfSKumar Gala 	fdt_portal(blob, "fsl,bman-portal", "bman-portals",
798db977abfSKumar Gala 			(u64)CONFIG_SYS_BMAN_MEM_PHYS,
799db977abfSKumar Gala 			CONFIG_SYS_BMAN_MEM_SIZE);
8002a0ffb84SHaiying Wang 	fdt_fixup_bportals(blob);
801db977abfSKumar Gala #endif
802db977abfSKumar Gala 
803db977abfSKumar Gala #if defined(CONFIG_SYS_QMAN_MEM_PHYS)
804db977abfSKumar Gala 	fdt_portal(blob, "fsl,qman-portal", "qman-portals",
805db977abfSKumar Gala 			(u64)CONFIG_SYS_QMAN_MEM_PHYS,
806db977abfSKumar Gala 			CONFIG_SYS_QMAN_MEM_SIZE);
807db977abfSKumar Gala 
808db977abfSKumar Gala 	fdt_fixup_qportals(blob);
809db977abfSKumar Gala #endif
810a09b9b68SKumar Gala 
811a09b9b68SKumar Gala #ifdef CONFIG_SYS_SRIO
812a09b9b68SKumar Gala 	ft_srio_setup(blob);
813a09b9b68SKumar Gala #endif
814f5feb5afSbhaskar upadhaya 
815f5feb5afSbhaskar upadhaya 	/*
816f5feb5afSbhaskar upadhaya 	 * system-clock = CCB clock/2
817f5feb5afSbhaskar upadhaya 	 * Here gd->bus_clk = CCB clock
818f5feb5afSbhaskar upadhaya 	 * We are using the system clock as 1588 Timer reference
819f5feb5afSbhaskar upadhaya 	 * clock source select
820f5feb5afSbhaskar upadhaya 	 */
821f5feb5afSbhaskar upadhaya 	do_fixup_by_compat_u32(blob, "fsl,gianfar-ptp-timer",
822f5feb5afSbhaskar upadhaya 			"timer-frequency", gd->bus_clk/2, 1);
82365bb8b06SBhaskar Upadhaya 
82433c87536SJia Hongtao 	/*
82533c87536SJia Hongtao 	 * clock-freq should change to clock-frequency and
82633c87536SJia Hongtao 	 * flexcan-v1.0 should change to p1010-flexcan respectively
82733c87536SJia Hongtao 	 * in the future.
82833c87536SJia Hongtao 	 */
82965bb8b06SBhaskar Upadhaya 	do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0",
83033c87536SJia Hongtao 			"clock_freq", gd->bus_clk/2, 1);
83133c87536SJia Hongtao 
83233c87536SJia Hongtao 	do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0",
83333c87536SJia Hongtao 			"clock-frequency", gd->bus_clk/2, 1);
83433c87536SJia Hongtao 
83533c87536SJia Hongtao 	do_fixup_by_compat_u32(blob, "fsl,p1010-flexcan",
83633c87536SJia Hongtao 			"clock-frequency", gd->bus_clk/2, 1);
837f81f19faSShengzhou Liu 
838f81f19faSShengzhou Liu 	fdt_fixup_usb(blob);
839d616fc58SCodrin Ciubotariu 
840d616fc58SCodrin Ciubotariu 	fdt_fixup_l2_switch(blob);
841605714f6SShengzhou Liu 
842605714f6SShengzhou Liu 	fdt_fixup_dma3(blob);
843a47a12beSStefan Roese }
84490f89f09STimur Tabi 
84590f89f09STimur Tabi /*
84690f89f09STimur Tabi  * For some CCSR devices, we only have the virtual address, not the physical
84790f89f09STimur Tabi  * address.  This is because we map CCSR as a whole, so we typically don't need
84890f89f09STimur Tabi  * a macro for the physical address of any device within CCSR.  In this case,
84990f89f09STimur Tabi  * we calculate the physical address of that device using it's the difference
85090f89f09STimur Tabi  * between the virtual address of the device and the virtual address of the
85190f89f09STimur Tabi  * beginning of CCSR.
85290f89f09STimur Tabi  */
85390f89f09STimur Tabi #define CCSR_VIRT_TO_PHYS(x) \
85490f89f09STimur Tabi 	(CONFIG_SYS_CCSRBAR_PHYS + ((x) - CONFIG_SYS_CCSRBAR))
85590f89f09STimur Tabi 
856cc15df57STimur Tabi static void msg(const char *name, uint64_t uaddr, uint64_t daddr)
857cc15df57STimur Tabi {
858cc15df57STimur Tabi 	printf("Warning: U-Boot configured %s at address %llx,\n"
859cc15df57STimur Tabi 	       "but the device tree has it at %llx\n", name, uaddr, daddr);
860cc15df57STimur Tabi }
861cc15df57STimur Tabi 
86290f89f09STimur Tabi /*
86390f89f09STimur Tabi  * Verify the device tree
86490f89f09STimur Tabi  *
86590f89f09STimur Tabi  * This function compares several CONFIG_xxx macros that contain physical
86690f89f09STimur Tabi  * addresses with the corresponding nodes in the device tree, to see if
86790f89f09STimur Tabi  * the physical addresses are all correct.  For example, if
86890f89f09STimur Tabi  * CONFIG_SYS_NS16550_COM1 is defined, then it contains the virtual address
86990f89f09STimur Tabi  * of the first UART.  We convert this to a physical address and compare
87090f89f09STimur Tabi  * that with the physical address of the first ns16550-compatible node
87190f89f09STimur Tabi  * in the device tree.  If they don't match, then we display a warning.
87290f89f09STimur Tabi  *
87390f89f09STimur Tabi  * Returns 1 on success, 0 on failure
87490f89f09STimur Tabi  */
87590f89f09STimur Tabi int ft_verify_fdt(void *fdt)
87690f89f09STimur Tabi {
877cc15df57STimur Tabi 	uint64_t addr = 0;
87890f89f09STimur Tabi 	int aliases;
87990f89f09STimur Tabi 	int off;
88090f89f09STimur Tabi 
88190f89f09STimur Tabi 	/* First check the CCSR base address */
88290f89f09STimur Tabi 	off = fdt_node_offset_by_prop_value(fdt, -1, "device_type", "soc", 4);
88390f89f09STimur Tabi 	if (off > 0)
884cc15df57STimur Tabi 		addr = fdt_get_base_address(fdt, off);
88590f89f09STimur Tabi 
886cc15df57STimur Tabi 	if (!addr) {
88790f89f09STimur Tabi 		printf("Warning: could not determine base CCSR address in "
88890f89f09STimur Tabi 		       "device tree\n");
88990f89f09STimur Tabi 		/* No point in checking anything else */
89090f89f09STimur Tabi 		return 0;
89190f89f09STimur Tabi 	}
89290f89f09STimur Tabi 
893cc15df57STimur Tabi 	if (addr != CONFIG_SYS_CCSRBAR_PHYS) {
894cc15df57STimur Tabi 		msg("CCSR", CONFIG_SYS_CCSRBAR_PHYS, addr);
89590f89f09STimur Tabi 		/* No point in checking anything else */
89690f89f09STimur Tabi 		return 0;
89790f89f09STimur Tabi 	}
89890f89f09STimur Tabi 
89990f89f09STimur Tabi 	/*
900cc15df57STimur Tabi 	 * Check some nodes via aliases.  We assume that U-Boot and the device
901cc15df57STimur Tabi 	 * tree enumerate the devices equally.  E.g. the first serial port in
902cc15df57STimur Tabi 	 * U-Boot is the same as "serial0" in the device tree.
90390f89f09STimur Tabi 	 */
90490f89f09STimur Tabi 	aliases = fdt_path_offset(fdt, "/aliases");
90590f89f09STimur Tabi 	if (aliases > 0) {
90690f89f09STimur Tabi #ifdef CONFIG_SYS_NS16550_COM1
90790f89f09STimur Tabi 		if (!fdt_verify_alias_address(fdt, aliases, "serial0",
90890f89f09STimur Tabi 			CCSR_VIRT_TO_PHYS(CONFIG_SYS_NS16550_COM1)))
90990f89f09STimur Tabi 			return 0;
91090f89f09STimur Tabi #endif
91190f89f09STimur Tabi 
91290f89f09STimur Tabi #ifdef CONFIG_SYS_NS16550_COM2
91390f89f09STimur Tabi 		if (!fdt_verify_alias_address(fdt, aliases, "serial1",
91490f89f09STimur Tabi 			CCSR_VIRT_TO_PHYS(CONFIG_SYS_NS16550_COM2)))
91590f89f09STimur Tabi 			return 0;
91690f89f09STimur Tabi #endif
91790f89f09STimur Tabi 	}
91890f89f09STimur Tabi 
919cc15df57STimur Tabi 	/*
920cc15df57STimur Tabi 	 * The localbus node is typically a root node, even though the lbc
921cc15df57STimur Tabi 	 * controller is part of CCSR.  If we were to put the lbc node under
922cc15df57STimur Tabi 	 * the SOC node, then the 'ranges' property in the lbc node would
923cc15df57STimur Tabi 	 * translate through the 'ranges' property of the parent SOC node, and
924cc15df57STimur Tabi 	 * we don't want that.  Since it's a separate node, it's possible for
925cc15df57STimur Tabi 	 * the 'reg' property to be wrong, so check it here.  For now, we
926cc15df57STimur Tabi 	 * only check for "fsl,elbc" nodes.
927cc15df57STimur Tabi 	 */
928cc15df57STimur Tabi #ifdef CONFIG_SYS_LBC_ADDR
929cc15df57STimur Tabi 	off = fdt_node_offset_by_compatible(fdt, -1, "fsl,elbc");
930cc15df57STimur Tabi 	if (off > 0) {
9318aa5ec6eSKim Phillips 		const fdt32_t *reg = fdt_getprop(fdt, off, "reg", NULL);
932cc15df57STimur Tabi 		if (reg) {
933cc15df57STimur Tabi 			uint64_t uaddr = CCSR_VIRT_TO_PHYS(CONFIG_SYS_LBC_ADDR);
934cc15df57STimur Tabi 
935cc15df57STimur Tabi 			addr = fdt_translate_address(fdt, off, reg);
936cc15df57STimur Tabi 			if (uaddr != addr) {
937cc15df57STimur Tabi 				msg("the localbus", uaddr, addr);
938cc15df57STimur Tabi 				return 0;
939cc15df57STimur Tabi 			}
940cc15df57STimur Tabi 		}
941cc15df57STimur Tabi 	}
942cc15df57STimur Tabi #endif
943cc15df57STimur Tabi 
94490f89f09STimur Tabi 	return 1;
94590f89f09STimur Tabi }
946