1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2a47a12beSStefan Roese /*
3a09b9b68SKumar Gala * Copyright 2007-2011 Freescale Semiconductor, Inc.
4a47a12beSStefan Roese *
5a47a12beSStefan Roese * (C) Copyright 2000
6a47a12beSStefan Roese * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7a47a12beSStefan Roese */
8a47a12beSStefan Roese
9a47a12beSStefan Roese #include <common.h>
109925f1dbSAlex Kiernan #include <environment.h>
11b08c8c48SMasahiro Yamada #include <linux/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>
16d4683776SZhao Qiang #include <asm/fsl_fdt.h>
17db977abfSKumar Gala #include <asm/fsl_portals.h>
1844262327SAhmed Mansour #include <fsl_qbman.h>
19377ffcfaSSandeep Singh #include <hwconfig.h>
20a47a12beSStefan Roese #ifdef CONFIG_FSL_ESDHC
21a47a12beSStefan Roese #include <fsl_esdhc.h>
22a47a12beSStefan Roese #endif
23075affb1SQianyu Gong #ifdef CONFIG_SYS_DPAA_FMAN
24075affb1SQianyu Gong #include <fsl_fman.h>
25075affb1SQianyu Gong #endif
26a47a12beSStefan Roese
27a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR;
28a47a12beSStefan Roese
29a47a12beSStefan Roese extern void ft_qe_setup(void *blob);
30a47a12beSStefan Roese extern void ft_fixup_num_cores(void *blob);
31a09b9b68SKumar Gala extern void ft_srio_setup(void *blob);
32a47a12beSStefan Roese
33a47a12beSStefan Roese #ifdef CONFIG_MP
34a47a12beSStefan Roese #include "mp.h"
35a47a12beSStefan Roese
ft_fixup_cpu(void * blob,u64 memory_limit)36a47a12beSStefan Roese void ft_fixup_cpu(void *blob, u64 memory_limit)
37a47a12beSStefan Roese {
38a47a12beSStefan Roese int off;
39ffd06e02SYork Sun phys_addr_t spin_tbl_addr = get_spin_phys_addr();
40eb539412SYork Sun u32 bootpg = determine_mp_bootpg(NULL);
41a47a12beSStefan Roese u32 id = get_my_id();
429d64c6bbSAaron Sierra const char *enable_method;
43377ffcfaSSandeep Singh #if defined(T1040_TDM_QUIRK_CCSR_BASE)
44377ffcfaSSandeep Singh int ret;
45377ffcfaSSandeep Singh int tdm_hwconfig_enabled = 0;
46377ffcfaSSandeep Singh char buffer[HWCONFIG_BUFFER_SIZE] = {0};
47377ffcfaSSandeep Singh #endif
48a47a12beSStefan Roese
49a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
50a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) {
51a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
52a47a12beSStefan Roese
53a47a12beSStefan Roese if (reg) {
54709389b6SYork Sun u32 phys_cpu_id = thread_to_core(*reg);
55709389b6SYork Sun u64 val = phys_cpu_id * SIZE_BOOT_ENTRY + spin_tbl_addr;
56709389b6SYork Sun val = cpu_to_fdt64(val);
57b80d3054SMatthew McClintock if (*reg == id) {
58b80d3054SMatthew McClintock fdt_setprop_string(blob, off, "status",
59b80d3054SMatthew McClintock "okay");
60b80d3054SMatthew McClintock } else {
61a47a12beSStefan Roese fdt_setprop_string(blob, off, "status",
62a47a12beSStefan Roese "disabled");
63b80d3054SMatthew McClintock }
649d64c6bbSAaron Sierra
659d64c6bbSAaron Sierra if (hold_cores_in_reset(0)) {
669d64c6bbSAaron Sierra #ifdef CONFIG_FSL_CORENET
679d64c6bbSAaron Sierra /* Cores held in reset, use BRR to release */
689d64c6bbSAaron Sierra enable_method = "fsl,brr-holdoff";
699d64c6bbSAaron Sierra #else
709d64c6bbSAaron Sierra /* Cores held in reset, use EEBPCR to release */
719d64c6bbSAaron Sierra enable_method = "fsl,eebpcr-holdoff";
729d64c6bbSAaron Sierra #endif
739d64c6bbSAaron Sierra } else {
749d64c6bbSAaron Sierra /* Cores out of reset and in a spin-loop */
759d64c6bbSAaron Sierra enable_method = "spin-table";
769d64c6bbSAaron Sierra
77a47a12beSStefan Roese fdt_setprop(blob, off, "cpu-release-addr",
78a47a12beSStefan Roese &val, sizeof(val));
799d64c6bbSAaron Sierra }
809d64c6bbSAaron Sierra
819d64c6bbSAaron Sierra fdt_setprop_string(blob, off, "enable-method",
829d64c6bbSAaron Sierra enable_method);
83a47a12beSStefan Roese } else {
84a47a12beSStefan Roese printf ("cpu NULL\n");
85a47a12beSStefan Roese }
86a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off,
87a47a12beSStefan Roese "device_type", "cpu", 4);
88a47a12beSStefan Roese }
89a47a12beSStefan Roese
90377ffcfaSSandeep Singh #if defined(T1040_TDM_QUIRK_CCSR_BASE)
91377ffcfaSSandeep Singh #define CONFIG_MEM_HOLE_16M 0x1000000
92377ffcfaSSandeep Singh /*
93377ffcfaSSandeep Singh * Extract hwconfig from environment.
94377ffcfaSSandeep Singh * Search for tdm entry in hwconfig.
95377ffcfaSSandeep Singh */
9600caae6dSSimon Glass ret = env_get_f("hwconfig", buffer, sizeof(buffer));
97377ffcfaSSandeep Singh if (ret > 0)
98377ffcfaSSandeep Singh tdm_hwconfig_enabled = hwconfig_f("tdm", buffer);
99377ffcfaSSandeep Singh
100377ffcfaSSandeep Singh /* Reserve the memory hole created by TDM LAW, so OSes dont use it */
101377ffcfaSSandeep Singh if (tdm_hwconfig_enabled) {
102377ffcfaSSandeep Singh off = fdt_add_mem_rsv(blob, T1040_TDM_QUIRK_CCSR_BASE,
103377ffcfaSSandeep Singh CONFIG_MEM_HOLE_16M);
104377ffcfaSSandeep Singh if (off < 0)
105377ffcfaSSandeep Singh printf("Failed to reserve memory for tdm: %s\n",
106377ffcfaSSandeep Singh fdt_strerror(off));
107377ffcfaSSandeep Singh }
108377ffcfaSSandeep Singh #endif
109377ffcfaSSandeep Singh
110a47a12beSStefan Roese /* Reserve the boot page so OSes dont use it */
111a47a12beSStefan Roese if ((u64)bootpg < memory_limit) {
112a47a12beSStefan Roese off = fdt_add_mem_rsv(blob, bootpg, (u64)4096);
113a47a12beSStefan Roese if (off < 0)
114ffd06e02SYork Sun printf("Failed to reserve memory for bootpg: %s\n",
115ffd06e02SYork Sun fdt_strerror(off));
116ffd06e02SYork Sun }
1172d9f26b6SYork Sun
1182d9f26b6SYork Sun #ifndef CONFIG_MPC8xxx_DISABLE_BPTR
1192d9f26b6SYork Sun /*
1202d9f26b6SYork Sun * Reserve the default boot page so OSes dont use it.
1212d9f26b6SYork Sun * The default boot page is always mapped to bootpg above using
1222d9f26b6SYork Sun * boot page translation.
1232d9f26b6SYork Sun */
1242d9f26b6SYork Sun if (0xfffff000ull < memory_limit) {
1252d9f26b6SYork Sun off = fdt_add_mem_rsv(blob, 0xfffff000ull, (u64)4096);
1262d9f26b6SYork Sun if (off < 0) {
1272d9f26b6SYork Sun printf("Failed to reserve memory for 0xfffff000: %s\n",
1282d9f26b6SYork Sun fdt_strerror(off));
1292d9f26b6SYork Sun }
1302d9f26b6SYork Sun }
1312d9f26b6SYork Sun #endif
1322d9f26b6SYork Sun
133ffd06e02SYork Sun /* Reserve spin table page */
134ffd06e02SYork Sun if (spin_tbl_addr < memory_limit) {
135ffd06e02SYork Sun off = fdt_add_mem_rsv(blob,
136ffd06e02SYork Sun (spin_tbl_addr & ~0xffful), 4096);
137ffd06e02SYork Sun if (off < 0)
138ffd06e02SYork Sun printf("Failed to reserve memory for spin table: %s\n",
139ffd06e02SYork Sun fdt_strerror(off));
140a47a12beSStefan Roese }
141ce249d95STang Yuantian #ifdef CONFIG_DEEP_SLEEP
142ce249d95STang Yuantian #ifdef CONFIG_SPL_MMC_BOOT
143ce249d95STang Yuantian off = fdt_add_mem_rsv(blob, CONFIG_SYS_MMC_U_BOOT_START,
144ce249d95STang Yuantian CONFIG_SYS_MMC_U_BOOT_SIZE);
145ce249d95STang Yuantian if (off < 0)
146ce249d95STang Yuantian printf("Failed to reserve memory for SD deep sleep: %s\n",
147ce249d95STang Yuantian fdt_strerror(off));
148ce249d95STang Yuantian #elif defined(CONFIG_SPL_SPI_BOOT)
149ce249d95STang Yuantian off = fdt_add_mem_rsv(blob, CONFIG_SYS_SPI_FLASH_U_BOOT_START,
150ce249d95STang Yuantian CONFIG_SYS_SPI_FLASH_U_BOOT_SIZE);
151ce249d95STang Yuantian if (off < 0)
152ce249d95STang Yuantian printf("Failed to reserve memory for SPI deep sleep: %s\n",
153ce249d95STang Yuantian fdt_strerror(off));
154ce249d95STang Yuantian #endif
155ce249d95STang Yuantian #endif
156a47a12beSStefan Roese }
157a47a12beSStefan Roese #endif
158a47a12beSStefan Roese
1596aba33e9SKumar Gala #ifdef CONFIG_SYS_FSL_CPC
ft_fixup_l3cache(void * blob,int off)1606aba33e9SKumar Gala static inline void ft_fixup_l3cache(void *blob, int off)
1616aba33e9SKumar Gala {
1626aba33e9SKumar Gala u32 line_size, num_ways, size, num_sets;
1636aba33e9SKumar Gala cpc_corenet_t *cpc = (void *)CONFIG_SYS_FSL_CPC_ADDR;
1646aba33e9SKumar Gala u32 cfg0 = in_be32(&cpc->cpccfg0);
1656aba33e9SKumar Gala
1666aba33e9SKumar Gala size = CPC_CFG0_SZ_K(cfg0) * 1024 * CONFIG_SYS_NUM_CPC;
1676aba33e9SKumar Gala num_ways = CPC_CFG0_NUM_WAYS(cfg0);
1686aba33e9SKumar Gala line_size = CPC_CFG0_LINE_SZ(cfg0);
1696aba33e9SKumar Gala num_sets = size / (line_size * num_ways);
1706aba33e9SKumar Gala
1716aba33e9SKumar Gala fdt_setprop(blob, off, "cache-unified", NULL, 0);
1726aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-block-size", line_size);
1736aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-size", size);
1746aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-sets", num_sets);
1756aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-level", 3);
1766aba33e9SKumar Gala #ifdef CONFIG_SYS_CACHE_STASHING
1776aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-stash-id", 1);
1786aba33e9SKumar Gala #endif
1796aba33e9SKumar Gala }
1806aba33e9SKumar Gala #else
181a47a12beSStefan Roese #define ft_fixup_l3cache(x, y)
1826aba33e9SKumar Gala #endif
183a47a12beSStefan Roese
18401b25d42SChris Packham #if defined(CONFIG_L2_CACHE) || \
18501b25d42SChris Packham defined(CONFIG_BACKSIDE_L2_CACHE) || \
18601b25d42SChris Packham defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2)
ft_fixup_l2cache_compatible(void * blob,int off)18701b25d42SChris Packham static inline void ft_fixup_l2cache_compatible(void *blob, int off)
18801b25d42SChris Packham {
18901b25d42SChris Packham int len;
19001b25d42SChris Packham struct cpu_type *cpu = identify_cpu(SVR_SOC_VER(get_svr()));
19101b25d42SChris Packham
19201b25d42SChris Packham if (cpu) {
19301b25d42SChris Packham char buf[40];
19401b25d42SChris Packham
19501b25d42SChris Packham if (isdigit(cpu->name[0])) {
19601b25d42SChris Packham /* MPCxxxx, where xxxx == 4-digit number */
19701b25d42SChris Packham len = sprintf(buf, "fsl,mpc%s-l2-cache-controller",
19801b25d42SChris Packham cpu->name) + 1;
19901b25d42SChris Packham } else {
20001b25d42SChris Packham /* Pxxxx or Txxxx, where xxxx == 4-digit number */
20101b25d42SChris Packham len = sprintf(buf, "fsl,%c%s-l2-cache-controller",
20201b25d42SChris Packham tolower(cpu->name[0]), cpu->name + 1) + 1;
20301b25d42SChris Packham }
20401b25d42SChris Packham
20501b25d42SChris Packham /*
20601b25d42SChris Packham * append "cache" after the NULL character that the previous
20701b25d42SChris Packham * sprintf wrote. This is how a device tree stores multiple
20801b25d42SChris Packham * strings in a property.
20901b25d42SChris Packham */
21001b25d42SChris Packham len += sprintf(buf + len, "cache") + 1;
21101b25d42SChris Packham
21201b25d42SChris Packham fdt_setprop(blob, off, "compatible", buf, len);
21301b25d42SChris Packham }
21401b25d42SChris Packham }
21501b25d42SChris Packham #endif
21601b25d42SChris Packham
217a47a12beSStefan Roese #if defined(CONFIG_L2_CACHE)
218a47a12beSStefan Roese /* return size in kilobytes */
l2cache_size(void)219a47a12beSStefan Roese static inline u32 l2cache_size(void)
220a47a12beSStefan Roese {
221a47a12beSStefan Roese volatile ccsr_l2cache_t *l2cache = (void *)CONFIG_SYS_MPC85xx_L2_ADDR;
222a47a12beSStefan Roese volatile u32 l2siz_field = (l2cache->l2ctl >> 28) & 0x3;
223a47a12beSStefan Roese u32 ver = SVR_SOC_VER(get_svr());
224a47a12beSStefan Roese
225a47a12beSStefan Roese switch (l2siz_field) {
226a47a12beSStefan Roese case 0x0:
227a47a12beSStefan Roese break;
228a47a12beSStefan Roese case 0x1:
229a47a12beSStefan Roese if (ver == SVR_8540 || ver == SVR_8560 ||
23048f6a5c3SYork Sun ver == SVR_8541 || ver == SVR_8555)
231a47a12beSStefan Roese return 128;
232a47a12beSStefan Roese else
233a47a12beSStefan Roese return 256;
234a47a12beSStefan Roese break;
235a47a12beSStefan Roese case 0x2:
236a47a12beSStefan Roese if (ver == SVR_8540 || ver == SVR_8560 ||
23748f6a5c3SYork Sun ver == SVR_8541 || ver == SVR_8555)
238a47a12beSStefan Roese return 256;
239a47a12beSStefan Roese else
240a47a12beSStefan Roese return 512;
241a47a12beSStefan Roese break;
242a47a12beSStefan Roese case 0x3:
243a47a12beSStefan Roese return 1024;
244a47a12beSStefan Roese break;
245a47a12beSStefan Roese }
246a47a12beSStefan Roese
247a47a12beSStefan Roese return 0;
248a47a12beSStefan Roese }
249a47a12beSStefan Roese
ft_fixup_l2cache(void * blob)250a47a12beSStefan Roese static inline void ft_fixup_l2cache(void *blob)
251a47a12beSStefan Roese {
25201b25d42SChris Packham int off;
253a47a12beSStefan Roese u32 *ph;
254a47a12beSStefan Roese
255a47a12beSStefan Roese const u32 line_size = 32;
256a47a12beSStefan Roese const u32 num_ways = 8;
257a47a12beSStefan Roese const u32 size = l2cache_size() * 1024;
258a47a12beSStefan Roese const u32 num_sets = size / (line_size * num_ways);
259a47a12beSStefan Roese
260a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
261a47a12beSStefan Roese if (off < 0) {
262a47a12beSStefan Roese debug("no cpu node fount\n");
263a47a12beSStefan Roese return;
264a47a12beSStefan Roese }
265a47a12beSStefan Roese
266a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0);
267a47a12beSStefan Roese
268a47a12beSStefan Roese if (ph == NULL) {
269a47a12beSStefan Roese debug("no next-level-cache property\n");
270a47a12beSStefan Roese return ;
271a47a12beSStefan Roese }
272a47a12beSStefan Roese
273a47a12beSStefan Roese off = fdt_node_offset_by_phandle(blob, *ph);
274a47a12beSStefan Roese if (off < 0) {
275a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off));
276a47a12beSStefan Roese return ;
277a47a12beSStefan Roese }
278a47a12beSStefan Roese
27901b25d42SChris Packham ft_fixup_l2cache_compatible(blob, off);
280a47a12beSStefan Roese fdt_setprop(blob, off, "cache-unified", NULL, 0);
281a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-block-size", line_size);
282a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-size", size);
283a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-sets", num_sets);
284a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-level", 2);
285a47a12beSStefan Roese
286a47a12beSStefan Roese /* we dont bother w/L3 since no platform of this type has one */
287a47a12beSStefan Roese }
2886d2b9da1SYork Sun #elif defined(CONFIG_BACKSIDE_L2_CACHE) || \
2896d2b9da1SYork Sun defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2)
ft_fixup_l2cache(void * blob)290a47a12beSStefan Roese static inline void ft_fixup_l2cache(void *blob)
291a47a12beSStefan Roese {
292a47a12beSStefan Roese int off, l2_off, l3_off = -1;
293a47a12beSStefan Roese u32 *ph;
2946d2b9da1SYork Sun #ifdef CONFIG_BACKSIDE_L2_CACHE
295a47a12beSStefan Roese u32 l2cfg0 = mfspr(SPRN_L2CFG0);
2966d2b9da1SYork Sun #else
2976d2b9da1SYork Sun struct ccsr_cluster_l2 *l2cache =
2986d2b9da1SYork Sun (struct ccsr_cluster_l2 __iomem *)(CONFIG_SYS_FSL_CLUSTER_1_L2);
2996d2b9da1SYork Sun u32 l2cfg0 = in_be32(&l2cache->l2cfg0);
3006d2b9da1SYork Sun #endif
301a47a12beSStefan Roese u32 size, line_size, num_ways, num_sets;
302acf3f8daSKumar Gala int has_l2 = 1;
303acf3f8daSKumar Gala
304acf3f8daSKumar Gala /* P2040/P2040E has no L2, so dont set any L2 props */
30548f6a5c3SYork Sun if (SVR_SOC_VER(get_svr()) == SVR_P2040)
306acf3f8daSKumar Gala has_l2 = 0;
307a47a12beSStefan Roese
308a47a12beSStefan Roese size = (l2cfg0 & 0x3fff) * 64 * 1024;
309a47a12beSStefan Roese num_ways = ((l2cfg0 >> 14) & 0x1f) + 1;
310a47a12beSStefan Roese line_size = (((l2cfg0 >> 23) & 0x3) + 1) * 32;
311a47a12beSStefan Roese num_sets = size / (line_size * num_ways);
312a47a12beSStefan Roese
313a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
314a47a12beSStefan Roese
315a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) {
316a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0);
317a47a12beSStefan Roese
318a47a12beSStefan Roese if (ph == NULL) {
319a47a12beSStefan Roese debug("no next-level-cache property\n");
320a47a12beSStefan Roese goto next;
321a47a12beSStefan Roese }
322a47a12beSStefan Roese
323a47a12beSStefan Roese l2_off = fdt_node_offset_by_phandle(blob, *ph);
324a47a12beSStefan Roese if (l2_off < 0) {
325a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off));
326a47a12beSStefan Roese goto next;
327a47a12beSStefan Roese }
328a47a12beSStefan Roese
329acf3f8daSKumar Gala if (has_l2) {
330a47a12beSStefan Roese #ifdef CONFIG_SYS_CACHE_STASHING
331a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
332e9827468SPrabhakar Kushwaha #if defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500)
3336d2b9da1SYork Sun /* Only initialize every eighth thread */
3348d451a71SScott Wood if (reg && !((*reg) % 8)) {
3358d451a71SScott Wood fdt_setprop_cell(blob, l2_off, "cache-stash-id",
3368d451a71SScott Wood (*reg / 4) + 32 + 1);
3378d451a71SScott Wood }
3386d2b9da1SYork Sun #else
3398d451a71SScott Wood if (reg) {
340a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-stash-id",
341a47a12beSStefan Roese (*reg * 2) + 32 + 1);
3428d451a71SScott Wood }
3438d451a71SScott Wood #endif
344a47a12beSStefan Roese #endif
345a47a12beSStefan Roese
346a47a12beSStefan Roese fdt_setprop(blob, l2_off, "cache-unified", NULL, 0);
347acf3f8daSKumar Gala fdt_setprop_cell(blob, l2_off, "cache-block-size",
348acf3f8daSKumar Gala line_size);
349a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-size", size);
350a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-sets", num_sets);
351a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-level", 2);
35201b25d42SChris Packham ft_fixup_l2cache_compatible(blob, l2_off);
353acf3f8daSKumar Gala }
354a47a12beSStefan Roese
355a47a12beSStefan Roese if (l3_off < 0) {
356a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, l2_off, "next-level-cache", 0);
357a47a12beSStefan Roese
358a47a12beSStefan Roese if (ph == NULL) {
359a47a12beSStefan Roese debug("no next-level-cache property\n");
360a47a12beSStefan Roese goto next;
361a47a12beSStefan Roese }
362a47a12beSStefan Roese l3_off = *ph;
363a47a12beSStefan Roese }
364a47a12beSStefan Roese next:
365a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off,
366a47a12beSStefan Roese "device_type", "cpu", 4);
367a47a12beSStefan Roese }
368a47a12beSStefan Roese if (l3_off > 0) {
369a47a12beSStefan Roese l3_off = fdt_node_offset_by_phandle(blob, l3_off);
370a47a12beSStefan Roese if (l3_off < 0) {
371a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off));
372a47a12beSStefan Roese return ;
373a47a12beSStefan Roese }
374a47a12beSStefan Roese ft_fixup_l3cache(blob, l3_off);
375a47a12beSStefan Roese }
376a47a12beSStefan Roese }
377a47a12beSStefan Roese #else
378a47a12beSStefan Roese #define ft_fixup_l2cache(x)
379a47a12beSStefan Roese #endif
380a47a12beSStefan Roese
ft_fixup_cache(void * blob)381a47a12beSStefan Roese static inline void ft_fixup_cache(void *blob)
382a47a12beSStefan Roese {
383a47a12beSStefan Roese int off;
384a47a12beSStefan Roese
385a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
386a47a12beSStefan Roese
387a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) {
388a47a12beSStefan Roese u32 l1cfg0 = mfspr(SPRN_L1CFG0);
389a47a12beSStefan Roese u32 l1cfg1 = mfspr(SPRN_L1CFG1);
390a47a12beSStefan Roese u32 isize, iline_size, inum_sets, inum_ways;
391a47a12beSStefan Roese u32 dsize, dline_size, dnum_sets, dnum_ways;
392a47a12beSStefan Roese
393a47a12beSStefan Roese /* d-side config */
394a47a12beSStefan Roese dsize = (l1cfg0 & 0x7ff) * 1024;
395a47a12beSStefan Roese dnum_ways = ((l1cfg0 >> 11) & 0xff) + 1;
396a47a12beSStefan Roese dline_size = (((l1cfg0 >> 23) & 0x3) + 1) * 32;
397a47a12beSStefan Roese dnum_sets = dsize / (dline_size * dnum_ways);
398a47a12beSStefan Roese
399a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-block-size", dline_size);
400a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-size", dsize);
401a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-sets", dnum_sets);
402a47a12beSStefan Roese
403a47a12beSStefan Roese #ifdef CONFIG_SYS_CACHE_STASHING
404a47a12beSStefan Roese {
405a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0);
406a47a12beSStefan Roese if (reg)
407a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-stash-id",
408a47a12beSStefan Roese (*reg * 2) + 32 + 0);
409a47a12beSStefan Roese }
410a47a12beSStefan Roese #endif
411a47a12beSStefan Roese
412a47a12beSStefan Roese /* i-side config */
413a47a12beSStefan Roese isize = (l1cfg1 & 0x7ff) * 1024;
414a47a12beSStefan Roese inum_ways = ((l1cfg1 >> 11) & 0xff) + 1;
415a47a12beSStefan Roese iline_size = (((l1cfg1 >> 23) & 0x3) + 1) * 32;
416a47a12beSStefan Roese inum_sets = isize / (iline_size * inum_ways);
417a47a12beSStefan Roese
418a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-block-size", iline_size);
419a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-size", isize);
420a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-sets", inum_sets);
421a47a12beSStefan Roese
422a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off,
423a47a12beSStefan Roese "device_type", "cpu", 4);
424a47a12beSStefan Roese }
425a47a12beSStefan Roese
426a47a12beSStefan Roese ft_fixup_l2cache(blob);
427a47a12beSStefan Roese }
428a47a12beSStefan Roese
429a47a12beSStefan Roese
fdt_add_enet_stashing(void * fdt)430a47a12beSStefan Roese void fdt_add_enet_stashing(void *fdt)
431a47a12beSStefan Roese {
432a47a12beSStefan Roese do_fixup_by_compat(fdt, "gianfar", "bd-stash", NULL, 0, 1);
433a47a12beSStefan Roese
434a47a12beSStefan Roese do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-len", 96, 1);
435a47a12beSStefan Roese
436a47a12beSStefan Roese do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-idx", 0, 1);
437eea9a123SPankaj Chauhan do_fixup_by_compat(fdt, "fsl,etsec2", "bd-stash", NULL, 0, 1);
438eea9a123SPankaj Chauhan do_fixup_by_compat_u32(fdt, "fsl,etsec2", "rx-stash-len", 96, 1);
439eea9a123SPankaj Chauhan do_fixup_by_compat_u32(fdt, "fsl,etsec2", "rx-stash-idx", 0, 1);
440a47a12beSStefan Roese }
441a47a12beSStefan Roese
442a47a12beSStefan Roese #if defined(CONFIG_SYS_DPAA_FMAN) || defined(CONFIG_SYS_DPAA_PME)
443e2d0f255SKumar Gala #ifdef CONFIG_SYS_DPAA_FMAN
ft_fixup_clks(void * blob,const char * compat,u32 offset,unsigned long freq)4441b942f74SKumar Gala static void ft_fixup_clks(void *blob, const char *compat, u32 offset,
4451b942f74SKumar Gala unsigned long freq)
446a47a12beSStefan Roese {
4471b942f74SKumar Gala phys_addr_t phys = offset + CONFIG_SYS_CCSRBAR_PHYS;
4481b942f74SKumar Gala int off = fdt_node_offset_by_compat_reg(blob, compat, phys);
449a47a12beSStefan Roese
450a47a12beSStefan Roese if (off >= 0) {
451a47a12beSStefan Roese off = fdt_setprop_cell(blob, off, "clock-frequency", freq);
452a47a12beSStefan Roese if (off > 0)
453a47a12beSStefan Roese printf("WARNING enable to set clock-frequency "
4541b942f74SKumar Gala "for %s: %s\n", compat, fdt_strerror(off));
455a47a12beSStefan Roese }
456a47a12beSStefan Roese }
457e2d0f255SKumar Gala #endif
458a47a12beSStefan Roese
ft_fixup_dpaa_clks(void * blob)459a47a12beSStefan Roese static void ft_fixup_dpaa_clks(void *blob)
460a47a12beSStefan Roese {
461a47a12beSStefan Roese sys_info_t sysinfo;
462a47a12beSStefan Roese
463a47a12beSStefan Roese get_sys_info(&sysinfo);
464e2d0f255SKumar Gala #ifdef CONFIG_SYS_DPAA_FMAN
4651b942f74SKumar Gala ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM1_OFFSET,
466997399faSPrabhakar Kushwaha sysinfo.freq_fman[0]);
467a47a12beSStefan Roese
468a47a12beSStefan Roese #if (CONFIG_SYS_NUM_FMAN == 2)
4691b942f74SKumar Gala ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM2_OFFSET,
470997399faSPrabhakar Kushwaha sysinfo.freq_fman[1]);
471a47a12beSStefan Roese #endif
472e2d0f255SKumar Gala #endif
473a47a12beSStefan Roese
474990e1a8cSHaiying Wang #ifdef CONFIG_SYS_DPAA_QBMAN
475990e1a8cSHaiying Wang do_fixup_by_compat_u32(blob, "fsl,qman",
476997399faSPrabhakar Kushwaha "clock-frequency", sysinfo.freq_qman, 1);
477990e1a8cSHaiying Wang #endif
478990e1a8cSHaiying Wang
479a47a12beSStefan Roese #ifdef CONFIG_SYS_DPAA_PME
4801b942f74SKumar Gala do_fixup_by_compat_u32(blob, "fsl,pme",
481997399faSPrabhakar Kushwaha "clock-frequency", sysinfo.freq_pme, 1);
482a47a12beSStefan Roese #endif
483a47a12beSStefan Roese }
484a47a12beSStefan Roese #else
485a47a12beSStefan Roese #define ft_fixup_dpaa_clks(x)
486a47a12beSStefan Roese #endif
487a47a12beSStefan Roese
488a47a12beSStefan Roese #ifdef CONFIG_QE
ft_fixup_qe_snum(void * blob)489a47a12beSStefan Roese static void ft_fixup_qe_snum(void *blob)
490a47a12beSStefan Roese {
491a47a12beSStefan Roese unsigned int svr;
492a47a12beSStefan Roese
493a47a12beSStefan Roese svr = mfspr(SPRN_SVR);
49448f6a5c3SYork Sun if (SVR_SOC_VER(svr) == SVR_8569) {
495a47a12beSStefan Roese if(IS_SVR_REV(svr, 1, 0))
496a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,qe",
497a47a12beSStefan Roese "fsl,qe-num-snums", 46, 1);
498a47a12beSStefan Roese else
499a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,qe",
500a47a12beSStefan Roese "fsl,qe-num-snums", 76, 1);
501a47a12beSStefan Roese }
502a47a12beSStefan Roese }
503a47a12beSStefan Roese #endif
504a47a12beSStefan Roese
505e71372cbSYork Sun #if defined(CONFIG_ARCH_P4080)
fdt_fixup_usb(void * fdt)506f81f19faSShengzhou Liu static void fdt_fixup_usb(void *fdt)
507f81f19faSShengzhou Liu {
508f81f19faSShengzhou Liu ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
509f81f19faSShengzhou Liu u32 rcwsr11 = in_be32(&gur->rcwsr[11]);
510f81f19faSShengzhou Liu int off;
511f81f19faSShengzhou Liu
512f81f19faSShengzhou Liu off = fdt_node_offset_by_compatible(fdt, -1, "fsl,mpc85xx-usb2-mph");
513f81f19faSShengzhou Liu if ((rcwsr11 & FSL_CORENET_RCWSR11_EC1) !=
514f81f19faSShengzhou Liu FSL_CORENET_RCWSR11_EC1_FM1_USB1)
515f81f19faSShengzhou Liu fdt_status_disabled(fdt, off);
516f81f19faSShengzhou Liu
517f81f19faSShengzhou Liu off = fdt_node_offset_by_compatible(fdt, -1, "fsl,mpc85xx-usb2-dr");
518f81f19faSShengzhou Liu if ((rcwsr11 & FSL_CORENET_RCWSR11_EC2) !=
519f81f19faSShengzhou Liu FSL_CORENET_RCWSR11_EC2_USB2)
520f81f19faSShengzhou Liu fdt_status_disabled(fdt, off);
521f81f19faSShengzhou Liu }
522f81f19faSShengzhou Liu #else
523f81f19faSShengzhou Liu #define fdt_fixup_usb(x)
524f81f19faSShengzhou Liu #endif
525f81f19faSShengzhou Liu
52626bc57daSYork Sun #if defined(CONFIG_ARCH_T2080) || defined(CONFIG_ARCH_T4240) || \
527cdb72c52SYork Sun defined(CONFIG_ARCH_T4160)
fdt_fixup_dma3(void * blob)528605714f6SShengzhou Liu void fdt_fixup_dma3(void *blob)
529605714f6SShengzhou Liu {
530605714f6SShengzhou Liu /* the 3rd DMA is not functional if SRIO2 is chosen */
531605714f6SShengzhou Liu int nodeoff;
532605714f6SShengzhou Liu ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
533605714f6SShengzhou Liu
534605714f6SShengzhou Liu #define CONFIG_SYS_ELO3_DMA3 (0xffe000000 + 0x102300)
5350f3d80e9SYork Sun #if defined(CONFIG_ARCH_T2080)
536605714f6SShengzhou Liu u32 srds_prtcl_s2 = in_be32(&gur->rcwsr[4]) &
537605714f6SShengzhou Liu FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
538605714f6SShengzhou Liu srds_prtcl_s2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
539605714f6SShengzhou Liu
540605714f6SShengzhou Liu switch (srds_prtcl_s2) {
541605714f6SShengzhou Liu case 0x29:
542605714f6SShengzhou Liu case 0x2d:
543605714f6SShengzhou Liu case 0x2e:
544cdb72c52SYork Sun #elif defined(CONFIG_ARCH_T4240) || defined(CONFIG_ARCH_T4160)
545605714f6SShengzhou Liu u32 srds_prtcl_s4 = in_be32(&gur->rcwsr[4]) &
546605714f6SShengzhou Liu FSL_CORENET2_RCWSR4_SRDS4_PRTCL;
547605714f6SShengzhou Liu srds_prtcl_s4 >>= FSL_CORENET2_RCWSR4_SRDS4_PRTCL_SHIFT;
548605714f6SShengzhou Liu
549605714f6SShengzhou Liu switch (srds_prtcl_s4) {
550605714f6SShengzhou Liu case 6:
551605714f6SShengzhou Liu case 8:
552605714f6SShengzhou Liu case 14:
553605714f6SShengzhou Liu case 16:
554605714f6SShengzhou Liu #endif
555605714f6SShengzhou Liu nodeoff = fdt_node_offset_by_compat_reg(blob, "fsl,elo3-dma",
556605714f6SShengzhou Liu CONFIG_SYS_ELO3_DMA3);
557605714f6SShengzhou Liu if (nodeoff > 0)
558605714f6SShengzhou Liu fdt_status_disabled(blob, nodeoff);
559605714f6SShengzhou Liu else
560605714f6SShengzhou Liu printf("WARNING: unable to disable dma3\n");
561605714f6SShengzhou Liu break;
562605714f6SShengzhou Liu default:
563605714f6SShengzhou Liu break;
564605714f6SShengzhou Liu }
565605714f6SShengzhou Liu }
566605714f6SShengzhou Liu #else
567605714f6SShengzhou Liu #define fdt_fixup_dma3(x)
568605714f6SShengzhou Liu #endif
569605714f6SShengzhou Liu
5705d737010SYork Sun #if defined(CONFIG_ARCH_T1040)
571d616fc58SCodrin Ciubotariu static void fdt_fixup_l2_switch(void *blob)
572d616fc58SCodrin Ciubotariu {
573d616fc58SCodrin Ciubotariu uchar l2swaddr[6];
574d616fc58SCodrin Ciubotariu int node;
575d616fc58SCodrin Ciubotariu
576d616fc58SCodrin Ciubotariu /* The l2switch node from device-tree has
577d616fc58SCodrin Ciubotariu * compatible string "vitesse-9953" */
578d616fc58SCodrin Ciubotariu node = fdt_node_offset_by_compatible(blob, -1, "vitesse-9953");
579d616fc58SCodrin Ciubotariu if (node == -FDT_ERR_NOTFOUND)
580d616fc58SCodrin Ciubotariu /* no l2switch node has been found */
581d616fc58SCodrin Ciubotariu return;
582d616fc58SCodrin Ciubotariu
583d616fc58SCodrin Ciubotariu /* Get MAC address for the l2switch from "l2switchaddr"*/
58435affd7aSSimon Glass if (!eth_env_get_enetaddr("l2switchaddr", l2swaddr)) {
585d616fc58SCodrin Ciubotariu printf("Warning: MAC address for l2switch not found\n");
586d616fc58SCodrin Ciubotariu memset(l2swaddr, 0, sizeof(l2swaddr));
587d616fc58SCodrin Ciubotariu }
588d616fc58SCodrin Ciubotariu
589d616fc58SCodrin Ciubotariu /* Add MAC address to l2switch node */
590d616fc58SCodrin Ciubotariu fdt_setprop(blob, node, "local-mac-address", l2swaddr,
591d616fc58SCodrin Ciubotariu sizeof(l2swaddr));
592d616fc58SCodrin Ciubotariu }
593d616fc58SCodrin Ciubotariu #else
594d616fc58SCodrin Ciubotariu #define fdt_fixup_l2_switch(x)
595d616fc58SCodrin Ciubotariu #endif
596d616fc58SCodrin Ciubotariu
597a47a12beSStefan Roese void ft_cpu_setup(void *blob, bd_t *bd)
598a47a12beSStefan Roese {
599a47a12beSStefan Roese int off;
600a47a12beSStefan Roese int val;
60151abee64SLaurentiu TUDOR int len;
602a47a12beSStefan Roese sys_info_t sysinfo;
603a47a12beSStefan Roese
604a47a12beSStefan Roese /* delete crypto node if not on an E-processor */
605a47a12beSStefan Roese if (!IS_E_PROCESSOR(get_svr()))
606a47a12beSStefan Roese fdt_fixup_crypto_node(blob, 0);
6075e95e2d8SVakul Garg #if CONFIG_SYS_FSL_SEC_COMPAT >= 4
6085e95e2d8SVakul Garg else {
6095e95e2d8SVakul Garg ccsr_sec_t __iomem *sec;
6105e95e2d8SVakul Garg
6115e95e2d8SVakul Garg sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR;
612028dbb8dSRuchika Gupta fdt_fixup_crypto_node(blob, sec_in32(&sec->secvid_ms));
6135e95e2d8SVakul Garg }
6145e95e2d8SVakul Garg #endif
615a47a12beSStefan Roese
616a47a12beSStefan Roese fdt_add_enet_stashing(blob);
617a47a12beSStefan Roese
618cb93071bSYork Sun #ifndef CONFIG_FSL_TBCLK_EXTRA_DIV
619cb93071bSYork Sun #define CONFIG_FSL_TBCLK_EXTRA_DIV 1
620cb93071bSYork Sun #endif
621a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
622cb93071bSYork Sun "timebase-frequency", get_tbclk() / CONFIG_FSL_TBCLK_EXTRA_DIV,
623cb93071bSYork Sun 1);
624a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
625a47a12beSStefan Roese "bus-frequency", bd->bi_busfreq, 1);
626a47a12beSStefan Roese get_sys_info(&sysinfo);
627a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
628a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) {
62951abee64SLaurentiu TUDOR u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", &len);
63051abee64SLaurentiu TUDOR val = cpu_to_fdt32(sysinfo.freq_processor[(*reg) / (len / 4)]);
631a47a12beSStefan Roese fdt_setprop(blob, off, "clock-frequency", &val, 4);
632a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, "device_type",
633a47a12beSStefan Roese "cpu", 4);
634a47a12beSStefan Roese }
635a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "soc", 4,
636a47a12beSStefan Roese "bus-frequency", bd->bi_busfreq, 1);
637a47a12beSStefan Roese
638a47a12beSStefan Roese #ifdef CONFIG_QE
639a47a12beSStefan Roese ft_qe_setup(blob);
640a47a12beSStefan Roese ft_fixup_qe_snum(blob);
641a47a12beSStefan Roese #endif
642a47a12beSStefan Roese
643075affb1SQianyu Gong #ifdef CONFIG_SYS_DPAA_FMAN
644ffadc441STimur Tabi fdt_fixup_fman_firmware(blob);
645075affb1SQianyu Gong #endif
646ffadc441STimur Tabi
647a47a12beSStefan Roese #ifdef CONFIG_SYS_NS16550
648a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "ns16550",
649a47a12beSStefan Roese "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
650a47a12beSStefan Roese #endif
651a47a12beSStefan Roese
652a47a12beSStefan Roese #ifdef CONFIG_CPM2
653a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,cpm2-scc-uart",
6548e261575SMasahiro Yamada "current-speed", gd->baudrate, 1);
655a47a12beSStefan Roese
656a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,cpm2-brg",
657a47a12beSStefan Roese "clock-frequency", bd->bi_brgfreq, 1);
658a47a12beSStefan Roese #endif
659a47a12beSStefan Roese
66085f8cda3SKumar Gala #ifdef CONFIG_FSL_CORENET
66185f8cda3SKumar Gala do_fixup_by_compat_u32(blob, "fsl,qoriq-clockgen-1.0",
66285f8cda3SKumar Gala "clock-frequency", CONFIG_SYS_CLK_FREQ, 1);
6637dd09b54SAndy Fleming do_fixup_by_compat_u32(blob, "fsl,qoriq-clockgen-2.0",
6647b700d21STang Yuantian "clock-frequency", CONFIG_SYS_CLK_FREQ, 1);
665f5c2623dSDongsheng.wang@freescale.com do_fixup_by_compat_u32(blob, "fsl,mpic",
666f5c2623dSDongsheng.wang@freescale.com "clock-frequency", get_bus_freq(0)/2, 1);
667f5c2623dSDongsheng.wang@freescale.com #else
668f5c2623dSDongsheng.wang@freescale.com do_fixup_by_compat_u32(blob, "fsl,mpic",
669f5c2623dSDongsheng.wang@freescale.com "clock-frequency", get_bus_freq(0), 1);
67085f8cda3SKumar Gala #endif
67185f8cda3SKumar Gala
672a47a12beSStefan Roese fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
673a47a12beSStefan Roese
674a47a12beSStefan Roese #ifdef CONFIG_MP
675a47a12beSStefan Roese ft_fixup_cpu(blob, (u64)bd->bi_memstart + (u64)bd->bi_memsize);
676a47a12beSStefan Roese ft_fixup_num_cores(blob);
6778f3a7fa4SKumar Gala #endif
678a47a12beSStefan Roese
679a47a12beSStefan Roese ft_fixup_cache(blob);
680a47a12beSStefan Roese
681a47a12beSStefan Roese #if defined(CONFIG_FSL_ESDHC)
682a47a12beSStefan Roese fdt_fixup_esdhc(blob, bd);
683a47a12beSStefan Roese #endif
684a47a12beSStefan Roese
685a47a12beSStefan Roese ft_fixup_dpaa_clks(blob);
686db977abfSKumar Gala
687db977abfSKumar Gala #if defined(CONFIG_SYS_BMAN_MEM_PHYS)
688db977abfSKumar Gala fdt_portal(blob, "fsl,bman-portal", "bman-portals",
689db977abfSKumar Gala (u64)CONFIG_SYS_BMAN_MEM_PHYS,
690db977abfSKumar Gala CONFIG_SYS_BMAN_MEM_SIZE);
6912a0ffb84SHaiying Wang fdt_fixup_bportals(blob);
692db977abfSKumar Gala #endif
693db977abfSKumar Gala
694db977abfSKumar Gala #if defined(CONFIG_SYS_QMAN_MEM_PHYS)
695db977abfSKumar Gala fdt_portal(blob, "fsl,qman-portal", "qman-portals",
696db977abfSKumar Gala (u64)CONFIG_SYS_QMAN_MEM_PHYS,
697db977abfSKumar Gala CONFIG_SYS_QMAN_MEM_SIZE);
698db977abfSKumar Gala
699db977abfSKumar Gala fdt_fixup_qportals(blob);
700db977abfSKumar Gala #endif
701a09b9b68SKumar Gala
702a09b9b68SKumar Gala #ifdef CONFIG_SYS_SRIO
703a09b9b68SKumar Gala ft_srio_setup(blob);
704a09b9b68SKumar Gala #endif
705f5feb5afSbhaskar upadhaya
706f5feb5afSbhaskar upadhaya /*
707f5feb5afSbhaskar upadhaya * system-clock = CCB clock/2
708f5feb5afSbhaskar upadhaya * Here gd->bus_clk = CCB clock
709f5feb5afSbhaskar upadhaya * We are using the system clock as 1588 Timer reference
710f5feb5afSbhaskar upadhaya * clock source select
711f5feb5afSbhaskar upadhaya */
712f5feb5afSbhaskar upadhaya do_fixup_by_compat_u32(blob, "fsl,gianfar-ptp-timer",
713f5feb5afSbhaskar upadhaya "timer-frequency", gd->bus_clk/2, 1);
71465bb8b06SBhaskar Upadhaya
71533c87536SJia Hongtao /*
71633c87536SJia Hongtao * clock-freq should change to clock-frequency and
71733c87536SJia Hongtao * flexcan-v1.0 should change to p1010-flexcan respectively
71833c87536SJia Hongtao * in the future.
71933c87536SJia Hongtao */
72065bb8b06SBhaskar Upadhaya do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0",
72133c87536SJia Hongtao "clock_freq", gd->bus_clk/2, 1);
72233c87536SJia Hongtao
72333c87536SJia Hongtao do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0",
72433c87536SJia Hongtao "clock-frequency", gd->bus_clk/2, 1);
72533c87536SJia Hongtao
72633c87536SJia Hongtao do_fixup_by_compat_u32(blob, "fsl,p1010-flexcan",
72733c87536SJia Hongtao "clock-frequency", gd->bus_clk/2, 1);
728f81f19faSShengzhou Liu
729f81f19faSShengzhou Liu fdt_fixup_usb(blob);
730d616fc58SCodrin Ciubotariu
731d616fc58SCodrin Ciubotariu fdt_fixup_l2_switch(blob);
732605714f6SShengzhou Liu
733605714f6SShengzhou Liu fdt_fixup_dma3(blob);
734a47a12beSStefan Roese }
73590f89f09STimur Tabi
73690f89f09STimur Tabi /*
73790f89f09STimur Tabi * For some CCSR devices, we only have the virtual address, not the physical
73890f89f09STimur Tabi * address. This is because we map CCSR as a whole, so we typically don't need
73990f89f09STimur Tabi * a macro for the physical address of any device within CCSR. In this case,
74090f89f09STimur Tabi * we calculate the physical address of that device using it's the difference
74190f89f09STimur Tabi * between the virtual address of the device and the virtual address of the
74290f89f09STimur Tabi * beginning of CCSR.
74390f89f09STimur Tabi */
74490f89f09STimur Tabi #define CCSR_VIRT_TO_PHYS(x) \
74590f89f09STimur Tabi (CONFIG_SYS_CCSRBAR_PHYS + ((x) - CONFIG_SYS_CCSRBAR))
74690f89f09STimur Tabi
747cc15df57STimur Tabi static void msg(const char *name, uint64_t uaddr, uint64_t daddr)
748cc15df57STimur Tabi {
749cc15df57STimur Tabi printf("Warning: U-Boot configured %s at address %llx,\n"
750cc15df57STimur Tabi "but the device tree has it at %llx\n", name, uaddr, daddr);
751cc15df57STimur Tabi }
752cc15df57STimur Tabi
75390f89f09STimur Tabi /*
75490f89f09STimur Tabi * Verify the device tree
75590f89f09STimur Tabi *
75690f89f09STimur Tabi * This function compares several CONFIG_xxx macros that contain physical
75790f89f09STimur Tabi * addresses with the corresponding nodes in the device tree, to see if
75890f89f09STimur Tabi * the physical addresses are all correct. For example, if
75990f89f09STimur Tabi * CONFIG_SYS_NS16550_COM1 is defined, then it contains the virtual address
76090f89f09STimur Tabi * of the first UART. We convert this to a physical address and compare
76190f89f09STimur Tabi * that with the physical address of the first ns16550-compatible node
76290f89f09STimur Tabi * in the device tree. If they don't match, then we display a warning.
76390f89f09STimur Tabi *
76490f89f09STimur Tabi * Returns 1 on success, 0 on failure
76590f89f09STimur Tabi */
76690f89f09STimur Tabi int ft_verify_fdt(void *fdt)
76790f89f09STimur Tabi {
768cc15df57STimur Tabi uint64_t addr = 0;
76990f89f09STimur Tabi int aliases;
77090f89f09STimur Tabi int off;
77190f89f09STimur Tabi
77290f89f09STimur Tabi /* First check the CCSR base address */
77390f89f09STimur Tabi off = fdt_node_offset_by_prop_value(fdt, -1, "device_type", "soc", 4);
774217324b2STom Rini if (off > 0) {
775217324b2STom Rini int size;
776217324b2STom Rini u32 naddr;
777217324b2STom Rini const fdt32_t *prop;
778217324b2STom Rini
779217324b2STom Rini naddr = fdt_address_cells(fdt, off);
780217324b2STom Rini prop = fdt_getprop(fdt, off, "ranges", &size);
781217324b2STom Rini addr = fdt_translate_address(fdt, off, prop + naddr);
782217324b2STom Rini }
78390f89f09STimur Tabi
784cc15df57STimur Tabi if (!addr) {
78590f89f09STimur Tabi printf("Warning: could not determine base CCSR address in "
78690f89f09STimur Tabi "device tree\n");
78790f89f09STimur Tabi /* No point in checking anything else */
78890f89f09STimur Tabi return 0;
78990f89f09STimur Tabi }
79090f89f09STimur Tabi
791cc15df57STimur Tabi if (addr != CONFIG_SYS_CCSRBAR_PHYS) {
792cc15df57STimur Tabi msg("CCSR", CONFIG_SYS_CCSRBAR_PHYS, addr);
79390f89f09STimur Tabi /* No point in checking anything else */
79490f89f09STimur Tabi return 0;
79590f89f09STimur Tabi }
79690f89f09STimur Tabi
79790f89f09STimur Tabi /*
798cc15df57STimur Tabi * Check some nodes via aliases. We assume that U-Boot and the device
799cc15df57STimur Tabi * tree enumerate the devices equally. E.g. the first serial port in
800cc15df57STimur Tabi * U-Boot is the same as "serial0" in the device tree.
80190f89f09STimur Tabi */
80290f89f09STimur Tabi aliases = fdt_path_offset(fdt, "/aliases");
80390f89f09STimur Tabi if (aliases > 0) {
80490f89f09STimur Tabi #ifdef CONFIG_SYS_NS16550_COM1
80590f89f09STimur Tabi if (!fdt_verify_alias_address(fdt, aliases, "serial0",
80690f89f09STimur Tabi CCSR_VIRT_TO_PHYS(CONFIG_SYS_NS16550_COM1)))
80790f89f09STimur Tabi return 0;
80890f89f09STimur Tabi #endif
80990f89f09STimur Tabi
81090f89f09STimur Tabi #ifdef CONFIG_SYS_NS16550_COM2
81190f89f09STimur Tabi if (!fdt_verify_alias_address(fdt, aliases, "serial1",
81290f89f09STimur Tabi CCSR_VIRT_TO_PHYS(CONFIG_SYS_NS16550_COM2)))
81390f89f09STimur Tabi return 0;
81490f89f09STimur Tabi #endif
81590f89f09STimur Tabi }
81690f89f09STimur Tabi
817cc15df57STimur Tabi /*
818cc15df57STimur Tabi * The localbus node is typically a root node, even though the lbc
819cc15df57STimur Tabi * controller is part of CCSR. If we were to put the lbc node under
820cc15df57STimur Tabi * the SOC node, then the 'ranges' property in the lbc node would
821cc15df57STimur Tabi * translate through the 'ranges' property of the parent SOC node, and
822cc15df57STimur Tabi * we don't want that. Since it's a separate node, it's possible for
823cc15df57STimur Tabi * the 'reg' property to be wrong, so check it here. For now, we
824cc15df57STimur Tabi * only check for "fsl,elbc" nodes.
825cc15df57STimur Tabi */
826cc15df57STimur Tabi #ifdef CONFIG_SYS_LBC_ADDR
827cc15df57STimur Tabi off = fdt_node_offset_by_compatible(fdt, -1, "fsl,elbc");
828cc15df57STimur Tabi if (off > 0) {
8298aa5ec6eSKim Phillips const fdt32_t *reg = fdt_getprop(fdt, off, "reg", NULL);
830cc15df57STimur Tabi if (reg) {
831cc15df57STimur Tabi uint64_t uaddr = CCSR_VIRT_TO_PHYS(CONFIG_SYS_LBC_ADDR);
832cc15df57STimur Tabi
833cc15df57STimur Tabi addr = fdt_translate_address(fdt, off, reg);
834cc15df57STimur Tabi if (uaddr != addr) {
835cc15df57STimur Tabi msg("the localbus", uaddr, addr);
836cc15df57STimur Tabi return 0;
837cc15df57STimur Tabi }
838cc15df57STimur Tabi }
839cc15df57STimur Tabi }
840cc15df57STimur Tabi #endif
841cc15df57STimur Tabi
84290f89f09STimur Tabi return 1;
84390f89f09STimur Tabi }
844d4683776SZhao Qiang
845d4683776SZhao Qiang void fdt_del_diu(void *blob)
846d4683776SZhao Qiang {
847d4683776SZhao Qiang int nodeoff = 0;
848d4683776SZhao Qiang
849d4683776SZhao Qiang while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
850d4683776SZhao Qiang "fsl,diu")) >= 0) {
851d4683776SZhao Qiang fdt_del_node(blob, nodeoff);
852d4683776SZhao Qiang }
853d4683776SZhao Qiang }
854