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> 17a47a12beSStefan Roese #ifdef CONFIG_FSL_ESDHC 18a47a12beSStefan Roese #include <fsl_esdhc.h> 19a47a12beSStefan Roese #endif 20ffadc441STimur Tabi #include "../../../../drivers/qe/qe.h" /* For struct qe_firmware */ 21a47a12beSStefan Roese 22a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR; 23a47a12beSStefan Roese 24a47a12beSStefan Roese extern void ft_qe_setup(void *blob); 25a47a12beSStefan Roese extern void ft_fixup_num_cores(void *blob); 26a09b9b68SKumar Gala extern void ft_srio_setup(void *blob); 27a47a12beSStefan Roese 28a47a12beSStefan Roese #ifdef CONFIG_MP 29a47a12beSStefan Roese #include "mp.h" 30a47a12beSStefan Roese 31a47a12beSStefan Roese void ft_fixup_cpu(void *blob, u64 memory_limit) 32a47a12beSStefan Roese { 33a47a12beSStefan Roese int off; 34ffd06e02SYork Sun phys_addr_t spin_tbl_addr = get_spin_phys_addr(); 35eb539412SYork Sun u32 bootpg = determine_mp_bootpg(NULL); 36a47a12beSStefan Roese u32 id = get_my_id(); 379d64c6bbSAaron Sierra const char *enable_method; 38a47a12beSStefan Roese 39a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 40a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 41a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 42a47a12beSStefan Roese 43a47a12beSStefan Roese if (reg) { 44709389b6SYork Sun u32 phys_cpu_id = thread_to_core(*reg); 45709389b6SYork Sun u64 val = phys_cpu_id * SIZE_BOOT_ENTRY + spin_tbl_addr; 46709389b6SYork Sun val = cpu_to_fdt64(val); 47b80d3054SMatthew McClintock if (*reg == id) { 48b80d3054SMatthew McClintock fdt_setprop_string(blob, off, "status", 49b80d3054SMatthew McClintock "okay"); 50b80d3054SMatthew McClintock } else { 51a47a12beSStefan Roese fdt_setprop_string(blob, off, "status", 52a47a12beSStefan Roese "disabled"); 53b80d3054SMatthew McClintock } 549d64c6bbSAaron Sierra 559d64c6bbSAaron Sierra if (hold_cores_in_reset(0)) { 569d64c6bbSAaron Sierra #ifdef CONFIG_FSL_CORENET 579d64c6bbSAaron Sierra /* Cores held in reset, use BRR to release */ 589d64c6bbSAaron Sierra enable_method = "fsl,brr-holdoff"; 599d64c6bbSAaron Sierra #else 609d64c6bbSAaron Sierra /* Cores held in reset, use EEBPCR to release */ 619d64c6bbSAaron Sierra enable_method = "fsl,eebpcr-holdoff"; 629d64c6bbSAaron Sierra #endif 639d64c6bbSAaron Sierra } else { 649d64c6bbSAaron Sierra /* Cores out of reset and in a spin-loop */ 659d64c6bbSAaron Sierra enable_method = "spin-table"; 669d64c6bbSAaron Sierra 67a47a12beSStefan Roese fdt_setprop(blob, off, "cpu-release-addr", 68a47a12beSStefan Roese &val, sizeof(val)); 699d64c6bbSAaron Sierra } 709d64c6bbSAaron Sierra 719d64c6bbSAaron Sierra fdt_setprop_string(blob, off, "enable-method", 729d64c6bbSAaron Sierra enable_method); 73a47a12beSStefan Roese } else { 74a47a12beSStefan Roese printf ("cpu NULL\n"); 75a47a12beSStefan Roese } 76a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, 77a47a12beSStefan Roese "device_type", "cpu", 4); 78a47a12beSStefan Roese } 79a47a12beSStefan Roese 80a47a12beSStefan Roese /* Reserve the boot page so OSes dont use it */ 81a47a12beSStefan Roese if ((u64)bootpg < memory_limit) { 82a47a12beSStefan Roese off = fdt_add_mem_rsv(blob, bootpg, (u64)4096); 83a47a12beSStefan Roese if (off < 0) 84ffd06e02SYork Sun printf("Failed to reserve memory for bootpg: %s\n", 85ffd06e02SYork Sun fdt_strerror(off)); 86ffd06e02SYork Sun } 872d9f26b6SYork Sun 882d9f26b6SYork Sun #ifndef CONFIG_MPC8xxx_DISABLE_BPTR 892d9f26b6SYork Sun /* 902d9f26b6SYork Sun * Reserve the default boot page so OSes dont use it. 912d9f26b6SYork Sun * The default boot page is always mapped to bootpg above using 922d9f26b6SYork Sun * boot page translation. 932d9f26b6SYork Sun */ 942d9f26b6SYork Sun if (0xfffff000ull < memory_limit) { 952d9f26b6SYork Sun off = fdt_add_mem_rsv(blob, 0xfffff000ull, (u64)4096); 962d9f26b6SYork Sun if (off < 0) { 972d9f26b6SYork Sun printf("Failed to reserve memory for 0xfffff000: %s\n", 982d9f26b6SYork Sun fdt_strerror(off)); 992d9f26b6SYork Sun } 1002d9f26b6SYork Sun } 1012d9f26b6SYork Sun #endif 1022d9f26b6SYork Sun 103ffd06e02SYork Sun /* Reserve spin table page */ 104ffd06e02SYork Sun if (spin_tbl_addr < memory_limit) { 105ffd06e02SYork Sun off = fdt_add_mem_rsv(blob, 106ffd06e02SYork Sun (spin_tbl_addr & ~0xffful), 4096); 107ffd06e02SYork Sun if (off < 0) 108ffd06e02SYork Sun printf("Failed to reserve memory for spin table: %s\n", 109ffd06e02SYork Sun fdt_strerror(off)); 110a47a12beSStefan Roese } 111a47a12beSStefan Roese } 112a47a12beSStefan Roese #endif 113a47a12beSStefan Roese 1146aba33e9SKumar Gala #ifdef CONFIG_SYS_FSL_CPC 1156aba33e9SKumar Gala static inline void ft_fixup_l3cache(void *blob, int off) 1166aba33e9SKumar Gala { 1176aba33e9SKumar Gala u32 line_size, num_ways, size, num_sets; 1186aba33e9SKumar Gala cpc_corenet_t *cpc = (void *)CONFIG_SYS_FSL_CPC_ADDR; 1196aba33e9SKumar Gala u32 cfg0 = in_be32(&cpc->cpccfg0); 1206aba33e9SKumar Gala 1216aba33e9SKumar Gala size = CPC_CFG0_SZ_K(cfg0) * 1024 * CONFIG_SYS_NUM_CPC; 1226aba33e9SKumar Gala num_ways = CPC_CFG0_NUM_WAYS(cfg0); 1236aba33e9SKumar Gala line_size = CPC_CFG0_LINE_SZ(cfg0); 1246aba33e9SKumar Gala num_sets = size / (line_size * num_ways); 1256aba33e9SKumar Gala 1266aba33e9SKumar Gala fdt_setprop(blob, off, "cache-unified", NULL, 0); 1276aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-block-size", line_size); 1286aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-size", size); 1296aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-sets", num_sets); 1306aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-level", 3); 1316aba33e9SKumar Gala #ifdef CONFIG_SYS_CACHE_STASHING 1326aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-stash-id", 1); 1336aba33e9SKumar Gala #endif 1346aba33e9SKumar Gala } 1356aba33e9SKumar Gala #else 136a47a12beSStefan Roese #define ft_fixup_l3cache(x, y) 1376aba33e9SKumar Gala #endif 138a47a12beSStefan Roese 139a47a12beSStefan Roese #if defined(CONFIG_L2_CACHE) 140a47a12beSStefan Roese /* return size in kilobytes */ 141a47a12beSStefan Roese static inline u32 l2cache_size(void) 142a47a12beSStefan Roese { 143a47a12beSStefan Roese volatile ccsr_l2cache_t *l2cache = (void *)CONFIG_SYS_MPC85xx_L2_ADDR; 144a47a12beSStefan Roese volatile u32 l2siz_field = (l2cache->l2ctl >> 28) & 0x3; 145a47a12beSStefan Roese u32 ver = SVR_SOC_VER(get_svr()); 146a47a12beSStefan Roese 147a47a12beSStefan Roese switch (l2siz_field) { 148a47a12beSStefan Roese case 0x0: 149a47a12beSStefan Roese break; 150a47a12beSStefan Roese case 0x1: 151a47a12beSStefan Roese if (ver == SVR_8540 || ver == SVR_8560 || 15248f6a5c3SYork Sun ver == SVR_8541 || ver == SVR_8555) 153a47a12beSStefan Roese return 128; 154a47a12beSStefan Roese else 155a47a12beSStefan Roese return 256; 156a47a12beSStefan Roese break; 157a47a12beSStefan Roese case 0x2: 158a47a12beSStefan Roese if (ver == SVR_8540 || ver == SVR_8560 || 15948f6a5c3SYork Sun ver == SVR_8541 || ver == SVR_8555) 160a47a12beSStefan Roese return 256; 161a47a12beSStefan Roese else 162a47a12beSStefan Roese return 512; 163a47a12beSStefan Roese break; 164a47a12beSStefan Roese case 0x3: 165a47a12beSStefan Roese return 1024; 166a47a12beSStefan Roese break; 167a47a12beSStefan Roese } 168a47a12beSStefan Roese 169a47a12beSStefan Roese return 0; 170a47a12beSStefan Roese } 171a47a12beSStefan Roese 172a47a12beSStefan Roese static inline void ft_fixup_l2cache(void *blob) 173a47a12beSStefan Roese { 174a47a12beSStefan Roese int len, off; 175a47a12beSStefan Roese u32 *ph; 176a47a12beSStefan Roese struct cpu_type *cpu = identify_cpu(SVR_SOC_VER(get_svr())); 177a47a12beSStefan Roese 178a47a12beSStefan Roese const u32 line_size = 32; 179a47a12beSStefan Roese const u32 num_ways = 8; 180a47a12beSStefan Roese const u32 size = l2cache_size() * 1024; 181a47a12beSStefan Roese const u32 num_sets = size / (line_size * num_ways); 182a47a12beSStefan Roese 183a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 184a47a12beSStefan Roese if (off < 0) { 185a47a12beSStefan Roese debug("no cpu node fount\n"); 186a47a12beSStefan Roese return; 187a47a12beSStefan Roese } 188a47a12beSStefan Roese 189a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0); 190a47a12beSStefan Roese 191a47a12beSStefan Roese if (ph == NULL) { 192a47a12beSStefan Roese debug("no next-level-cache property\n"); 193a47a12beSStefan Roese return ; 194a47a12beSStefan Roese } 195a47a12beSStefan Roese 196a47a12beSStefan Roese off = fdt_node_offset_by_phandle(blob, *ph); 197a47a12beSStefan Roese if (off < 0) { 198a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off)); 199a47a12beSStefan Roese return ; 200a47a12beSStefan Roese } 201a47a12beSStefan Roese 202a47a12beSStefan Roese if (cpu) { 203ee4756d4STimur Tabi char buf[40]; 204a47a12beSStefan Roese 205ee4756d4STimur Tabi if (isdigit(cpu->name[0])) { 206ee4756d4STimur Tabi /* MPCxxxx, where xxxx == 4-digit number */ 207ee4756d4STimur Tabi len = sprintf(buf, "fsl,mpc%s-l2-cache-controller", 208ee4756d4STimur Tabi cpu->name) + 1; 209ee4756d4STimur Tabi } else { 210ee4756d4STimur Tabi /* Pxxxx or Txxxx, where xxxx == 4-digit number */ 211ee4756d4STimur Tabi len = sprintf(buf, "fsl,%c%s-l2-cache-controller", 212ee4756d4STimur Tabi tolower(cpu->name[0]), cpu->name + 1) + 1; 213ee4756d4STimur Tabi } 214ee4756d4STimur Tabi 215ee4756d4STimur Tabi /* 216ee4756d4STimur Tabi * append "cache" after the NULL character that the previous 217ee4756d4STimur Tabi * sprintf wrote. This is how a device tree stores multiple 218ee4756d4STimur Tabi * strings in a property. 219ee4756d4STimur Tabi */ 220ee4756d4STimur Tabi len += sprintf(buf + len, "cache") + 1; 221ee4756d4STimur Tabi 222ee4756d4STimur Tabi fdt_setprop(blob, off, "compatible", buf, len); 223a47a12beSStefan Roese } 224a47a12beSStefan Roese fdt_setprop(blob, off, "cache-unified", NULL, 0); 225a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-block-size", line_size); 226a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-size", size); 227a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-sets", num_sets); 228a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-level", 2); 229a47a12beSStefan Roese 230a47a12beSStefan Roese /* we dont bother w/L3 since no platform of this type has one */ 231a47a12beSStefan Roese } 2326d2b9da1SYork Sun #elif defined(CONFIG_BACKSIDE_L2_CACHE) || \ 2336d2b9da1SYork Sun defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) 234a47a12beSStefan Roese static inline void ft_fixup_l2cache(void *blob) 235a47a12beSStefan Roese { 236a47a12beSStefan Roese int off, l2_off, l3_off = -1; 237a47a12beSStefan Roese u32 *ph; 2386d2b9da1SYork Sun #ifdef CONFIG_BACKSIDE_L2_CACHE 239a47a12beSStefan Roese u32 l2cfg0 = mfspr(SPRN_L2CFG0); 2406d2b9da1SYork Sun #else 2416d2b9da1SYork Sun struct ccsr_cluster_l2 *l2cache = 2426d2b9da1SYork Sun (struct ccsr_cluster_l2 __iomem *)(CONFIG_SYS_FSL_CLUSTER_1_L2); 2436d2b9da1SYork Sun u32 l2cfg0 = in_be32(&l2cache->l2cfg0); 2446d2b9da1SYork Sun #endif 245a47a12beSStefan Roese u32 size, line_size, num_ways, num_sets; 246acf3f8daSKumar Gala int has_l2 = 1; 247acf3f8daSKumar Gala 248acf3f8daSKumar Gala /* P2040/P2040E has no L2, so dont set any L2 props */ 24948f6a5c3SYork Sun if (SVR_SOC_VER(get_svr()) == SVR_P2040) 250acf3f8daSKumar Gala has_l2 = 0; 251a47a12beSStefan Roese 252a47a12beSStefan Roese size = (l2cfg0 & 0x3fff) * 64 * 1024; 253a47a12beSStefan Roese num_ways = ((l2cfg0 >> 14) & 0x1f) + 1; 254a47a12beSStefan Roese line_size = (((l2cfg0 >> 23) & 0x3) + 1) * 32; 255a47a12beSStefan Roese num_sets = size / (line_size * num_ways); 256a47a12beSStefan Roese 257a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 258a47a12beSStefan Roese 259a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 260a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0); 261a47a12beSStefan Roese 262a47a12beSStefan Roese if (ph == NULL) { 263a47a12beSStefan Roese debug("no next-level-cache property\n"); 264a47a12beSStefan Roese goto next; 265a47a12beSStefan Roese } 266a47a12beSStefan Roese 267a47a12beSStefan Roese l2_off = fdt_node_offset_by_phandle(blob, *ph); 268a47a12beSStefan Roese if (l2_off < 0) { 269a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off)); 270a47a12beSStefan Roese goto next; 271a47a12beSStefan Roese } 272a47a12beSStefan Roese 273acf3f8daSKumar Gala if (has_l2) { 274a47a12beSStefan Roese #ifdef CONFIG_SYS_CACHE_STASHING 275a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 276*e9827468SPrabhakar Kushwaha #if defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500) 2776d2b9da1SYork Sun /* Only initialize every eighth thread */ 2786d2b9da1SYork Sun if (reg && !((*reg) % 8)) 2796d2b9da1SYork Sun #else 280a47a12beSStefan Roese if (reg) 2816d2b9da1SYork Sun #endif 282a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-stash-id", 283a47a12beSStefan Roese (*reg * 2) + 32 + 1); 284a47a12beSStefan Roese #endif 285a47a12beSStefan Roese 286a47a12beSStefan Roese fdt_setprop(blob, l2_off, "cache-unified", NULL, 0); 287acf3f8daSKumar Gala fdt_setprop_cell(blob, l2_off, "cache-block-size", 288acf3f8daSKumar Gala line_size); 289a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-size", size); 290a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-sets", num_sets); 291a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-level", 2); 292a47a12beSStefan Roese fdt_setprop(blob, l2_off, "compatible", "cache", 6); 293acf3f8daSKumar Gala } 294a47a12beSStefan Roese 295a47a12beSStefan Roese if (l3_off < 0) { 296a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, l2_off, "next-level-cache", 0); 297a47a12beSStefan Roese 298a47a12beSStefan Roese if (ph == NULL) { 299a47a12beSStefan Roese debug("no next-level-cache property\n"); 300a47a12beSStefan Roese goto next; 301a47a12beSStefan Roese } 302a47a12beSStefan Roese l3_off = *ph; 303a47a12beSStefan Roese } 304a47a12beSStefan Roese next: 305a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, 306a47a12beSStefan Roese "device_type", "cpu", 4); 307a47a12beSStefan Roese } 308a47a12beSStefan Roese if (l3_off > 0) { 309a47a12beSStefan Roese l3_off = fdt_node_offset_by_phandle(blob, l3_off); 310a47a12beSStefan Roese if (l3_off < 0) { 311a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off)); 312a47a12beSStefan Roese return ; 313a47a12beSStefan Roese } 314a47a12beSStefan Roese ft_fixup_l3cache(blob, l3_off); 315a47a12beSStefan Roese } 316a47a12beSStefan Roese } 317a47a12beSStefan Roese #else 318a47a12beSStefan Roese #define ft_fixup_l2cache(x) 319a47a12beSStefan Roese #endif 320a47a12beSStefan Roese 321a47a12beSStefan Roese static inline void ft_fixup_cache(void *blob) 322a47a12beSStefan Roese { 323a47a12beSStefan Roese int off; 324a47a12beSStefan Roese 325a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 326a47a12beSStefan Roese 327a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 328a47a12beSStefan Roese u32 l1cfg0 = mfspr(SPRN_L1CFG0); 329a47a12beSStefan Roese u32 l1cfg1 = mfspr(SPRN_L1CFG1); 330a47a12beSStefan Roese u32 isize, iline_size, inum_sets, inum_ways; 331a47a12beSStefan Roese u32 dsize, dline_size, dnum_sets, dnum_ways; 332a47a12beSStefan Roese 333a47a12beSStefan Roese /* d-side config */ 334a47a12beSStefan Roese dsize = (l1cfg0 & 0x7ff) * 1024; 335a47a12beSStefan Roese dnum_ways = ((l1cfg0 >> 11) & 0xff) + 1; 336a47a12beSStefan Roese dline_size = (((l1cfg0 >> 23) & 0x3) + 1) * 32; 337a47a12beSStefan Roese dnum_sets = dsize / (dline_size * dnum_ways); 338a47a12beSStefan Roese 339a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-block-size", dline_size); 340a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-size", dsize); 341a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-sets", dnum_sets); 342a47a12beSStefan Roese 343a47a12beSStefan Roese #ifdef CONFIG_SYS_CACHE_STASHING 344a47a12beSStefan Roese { 345a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 346a47a12beSStefan Roese if (reg) 347a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-stash-id", 348a47a12beSStefan Roese (*reg * 2) + 32 + 0); 349a47a12beSStefan Roese } 350a47a12beSStefan Roese #endif 351a47a12beSStefan Roese 352a47a12beSStefan Roese /* i-side config */ 353a47a12beSStefan Roese isize = (l1cfg1 & 0x7ff) * 1024; 354a47a12beSStefan Roese inum_ways = ((l1cfg1 >> 11) & 0xff) + 1; 355a47a12beSStefan Roese iline_size = (((l1cfg1 >> 23) & 0x3) + 1) * 32; 356a47a12beSStefan Roese inum_sets = isize / (iline_size * inum_ways); 357a47a12beSStefan Roese 358a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-block-size", iline_size); 359a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-size", isize); 360a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-sets", inum_sets); 361a47a12beSStefan Roese 362a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, 363a47a12beSStefan Roese "device_type", "cpu", 4); 364a47a12beSStefan Roese } 365a47a12beSStefan Roese 366a47a12beSStefan Roese ft_fixup_l2cache(blob); 367a47a12beSStefan Roese } 368a47a12beSStefan Roese 369a47a12beSStefan Roese 370a47a12beSStefan Roese void fdt_add_enet_stashing(void *fdt) 371a47a12beSStefan Roese { 372a47a12beSStefan Roese do_fixup_by_compat(fdt, "gianfar", "bd-stash", NULL, 0, 1); 373a47a12beSStefan Roese 374a47a12beSStefan Roese do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-len", 96, 1); 375a47a12beSStefan Roese 376a47a12beSStefan Roese do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-idx", 0, 1); 377eea9a123SPankaj Chauhan do_fixup_by_compat(fdt, "fsl,etsec2", "bd-stash", NULL, 0, 1); 378eea9a123SPankaj Chauhan do_fixup_by_compat_u32(fdt, "fsl,etsec2", "rx-stash-len", 96, 1); 379eea9a123SPankaj Chauhan do_fixup_by_compat_u32(fdt, "fsl,etsec2", "rx-stash-idx", 0, 1); 380a47a12beSStefan Roese } 381a47a12beSStefan Roese 382a47a12beSStefan Roese #if defined(CONFIG_SYS_DPAA_FMAN) || defined(CONFIG_SYS_DPAA_PME) 383e2d0f255SKumar Gala #ifdef CONFIG_SYS_DPAA_FMAN 3841b942f74SKumar Gala static void ft_fixup_clks(void *blob, const char *compat, u32 offset, 3851b942f74SKumar Gala unsigned long freq) 386a47a12beSStefan Roese { 3871b942f74SKumar Gala phys_addr_t phys = offset + CONFIG_SYS_CCSRBAR_PHYS; 3881b942f74SKumar Gala int off = fdt_node_offset_by_compat_reg(blob, compat, phys); 389a47a12beSStefan Roese 390a47a12beSStefan Roese if (off >= 0) { 391a47a12beSStefan Roese off = fdt_setprop_cell(blob, off, "clock-frequency", freq); 392a47a12beSStefan Roese if (off > 0) 393a47a12beSStefan Roese printf("WARNING enable to set clock-frequency " 3941b942f74SKumar Gala "for %s: %s\n", compat, fdt_strerror(off)); 395a47a12beSStefan Roese } 396a47a12beSStefan Roese } 397e2d0f255SKumar Gala #endif 398a47a12beSStefan Roese 399a47a12beSStefan Roese static void ft_fixup_dpaa_clks(void *blob) 400a47a12beSStefan Roese { 401a47a12beSStefan Roese sys_info_t sysinfo; 402a47a12beSStefan Roese 403a47a12beSStefan Roese get_sys_info(&sysinfo); 404e2d0f255SKumar Gala #ifdef CONFIG_SYS_DPAA_FMAN 4051b942f74SKumar Gala ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM1_OFFSET, 406997399faSPrabhakar Kushwaha sysinfo.freq_fman[0]); 407a47a12beSStefan Roese 408a47a12beSStefan Roese #if (CONFIG_SYS_NUM_FMAN == 2) 4091b942f74SKumar Gala ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM2_OFFSET, 410997399faSPrabhakar Kushwaha sysinfo.freq_fman[1]); 411a47a12beSStefan Roese #endif 412e2d0f255SKumar Gala #endif 413a47a12beSStefan Roese 414990e1a8cSHaiying Wang #ifdef CONFIG_SYS_DPAA_QBMAN 415990e1a8cSHaiying Wang do_fixup_by_compat_u32(blob, "fsl,qman", 416997399faSPrabhakar Kushwaha "clock-frequency", sysinfo.freq_qman, 1); 417990e1a8cSHaiying Wang #endif 418990e1a8cSHaiying Wang 419a47a12beSStefan Roese #ifdef CONFIG_SYS_DPAA_PME 4201b942f74SKumar Gala do_fixup_by_compat_u32(blob, "fsl,pme", 421997399faSPrabhakar Kushwaha "clock-frequency", sysinfo.freq_pme, 1); 422a47a12beSStefan Roese #endif 423a47a12beSStefan Roese } 424a47a12beSStefan Roese #else 425a47a12beSStefan Roese #define ft_fixup_dpaa_clks(x) 426a47a12beSStefan Roese #endif 427a47a12beSStefan Roese 428a47a12beSStefan Roese #ifdef CONFIG_QE 429a47a12beSStefan Roese static void ft_fixup_qe_snum(void *blob) 430a47a12beSStefan Roese { 431a47a12beSStefan Roese unsigned int svr; 432a47a12beSStefan Roese 433a47a12beSStefan Roese svr = mfspr(SPRN_SVR); 43448f6a5c3SYork Sun if (SVR_SOC_VER(svr) == SVR_8569) { 435a47a12beSStefan Roese if(IS_SVR_REV(svr, 1, 0)) 436a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,qe", 437a47a12beSStefan Roese "fsl,qe-num-snums", 46, 1); 438a47a12beSStefan Roese else 439a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,qe", 440a47a12beSStefan Roese "fsl,qe-num-snums", 76, 1); 441a47a12beSStefan Roese } 442a47a12beSStefan Roese } 443a47a12beSStefan Roese #endif 444a47a12beSStefan Roese 445ffadc441STimur Tabi /** 446ffadc441STimur Tabi * fdt_fixup_fman_firmware -- insert the Fman firmware into the device tree 447ffadc441STimur Tabi * 448ffadc441STimur Tabi * The binding for an Fman firmware node is documented in 449ffadc441STimur Tabi * Documentation/powerpc/dts-bindings/fsl/dpaa/fman.txt. This node contains 450ffadc441STimur Tabi * the actual Fman firmware binary data. The operating system is expected to 451ffadc441STimur Tabi * be able to parse the binary data to determine any attributes it needs. 452ffadc441STimur Tabi */ 453ffadc441STimur Tabi #ifdef CONFIG_SYS_DPAA_FMAN 454ffadc441STimur Tabi void fdt_fixup_fman_firmware(void *blob) 455ffadc441STimur Tabi { 456ffadc441STimur Tabi int rc, fmnode, fwnode = -1; 457ffadc441STimur Tabi uint32_t phandle; 458ffadc441STimur Tabi struct qe_firmware *fmanfw; 459ffadc441STimur Tabi const struct qe_header *hdr; 460ffadc441STimur Tabi unsigned int length; 461ffadc441STimur Tabi uint32_t crc; 462ffadc441STimur Tabi const char *p; 463ffadc441STimur Tabi 464ffadc441STimur Tabi /* The first Fman we find will contain the actual firmware. */ 465ffadc441STimur Tabi fmnode = fdt_node_offset_by_compatible(blob, -1, "fsl,fman"); 466ffadc441STimur Tabi if (fmnode < 0) 467ffadc441STimur Tabi /* Exit silently if there are no Fman devices */ 468ffadc441STimur Tabi return; 469ffadc441STimur Tabi 470ffadc441STimur Tabi /* If we already have a firmware node, then also exit silently. */ 471ffadc441STimur Tabi if (fdt_node_offset_by_compatible(blob, -1, "fsl,fman-firmware") > 0) 472ffadc441STimur Tabi return; 473ffadc441STimur Tabi 474ffadc441STimur Tabi /* If the environment variable is not set, then exit silently */ 475ffadc441STimur Tabi p = getenv("fman_ucode"); 476ffadc441STimur Tabi if (!p) 477ffadc441STimur Tabi return; 478ffadc441STimur Tabi 479e6394e9eSНиколай Пузанов fmanfw = (struct qe_firmware *) simple_strtoul(p, NULL, 16); 480ffadc441STimur Tabi if (!fmanfw) 481ffadc441STimur Tabi return; 482ffadc441STimur Tabi 483ffadc441STimur Tabi hdr = &fmanfw->header; 484ffadc441STimur Tabi length = be32_to_cpu(hdr->length); 485ffadc441STimur Tabi 486ffadc441STimur Tabi /* Verify the firmware. */ 487ffadc441STimur Tabi if ((hdr->magic[0] != 'Q') || (hdr->magic[1] != 'E') || 488ffadc441STimur Tabi (hdr->magic[2] != 'F')) { 489ffadc441STimur Tabi printf("Data at %p is not an Fman firmware\n", fmanfw); 490ffadc441STimur Tabi return; 491ffadc441STimur Tabi } 492ffadc441STimur Tabi 493f2717b47STimur Tabi if (length > CONFIG_SYS_QE_FMAN_FW_LENGTH) { 494ffadc441STimur Tabi printf("Fman firmware at %p is too large (size=%u)\n", 495ffadc441STimur Tabi fmanfw, length); 496ffadc441STimur Tabi return; 497ffadc441STimur Tabi } 498ffadc441STimur Tabi 499ffadc441STimur Tabi length -= sizeof(u32); /* Subtract the size of the CRC */ 500ffadc441STimur Tabi crc = be32_to_cpu(*(u32 *)((void *)fmanfw + length)); 501ffadc441STimur Tabi if (crc != crc32_no_comp(0, (void *)fmanfw, length)) { 502ffadc441STimur Tabi printf("Fman firmware at %p has invalid CRC\n", fmanfw); 503ffadc441STimur Tabi return; 504ffadc441STimur Tabi } 505ffadc441STimur Tabi 506ffadc441STimur Tabi /* Increase the size of the fdt to make room for the node. */ 507ffadc441STimur Tabi rc = fdt_increase_size(blob, fmanfw->header.length); 508ffadc441STimur Tabi if (rc < 0) { 509ffadc441STimur Tabi printf("Unable to make room for Fman firmware: %s\n", 510ffadc441STimur Tabi fdt_strerror(rc)); 511ffadc441STimur Tabi return; 512ffadc441STimur Tabi } 513ffadc441STimur Tabi 514ffadc441STimur Tabi /* Create the firmware node. */ 515ffadc441STimur Tabi fwnode = fdt_add_subnode(blob, fmnode, "fman-firmware"); 516ffadc441STimur Tabi if (fwnode < 0) { 517ffadc441STimur Tabi char s[64]; 518ffadc441STimur Tabi fdt_get_path(blob, fmnode, s, sizeof(s)); 519ffadc441STimur Tabi printf("Could not add firmware node to %s: %s\n", s, 520ffadc441STimur Tabi fdt_strerror(fwnode)); 521ffadc441STimur Tabi return; 522ffadc441STimur Tabi } 523ffadc441STimur Tabi rc = fdt_setprop_string(blob, fwnode, "compatible", "fsl,fman-firmware"); 524ffadc441STimur Tabi if (rc < 0) { 525ffadc441STimur Tabi char s[64]; 526ffadc441STimur Tabi fdt_get_path(blob, fwnode, s, sizeof(s)); 527ffadc441STimur Tabi printf("Could not add compatible property to node %s: %s\n", s, 528ffadc441STimur Tabi fdt_strerror(rc)); 529ffadc441STimur Tabi return; 530ffadc441STimur Tabi } 531a2c1229cSTimur Tabi phandle = fdt_create_phandle(blob, fwnode); 532a2c1229cSTimur Tabi if (!phandle) { 533ffadc441STimur Tabi char s[64]; 534ffadc441STimur Tabi fdt_get_path(blob, fwnode, s, sizeof(s)); 535ffadc441STimur Tabi printf("Could not add phandle property to node %s: %s\n", s, 536ffadc441STimur Tabi fdt_strerror(rc)); 537ffadc441STimur Tabi return; 538ffadc441STimur Tabi } 539ffadc441STimur Tabi rc = fdt_setprop(blob, fwnode, "fsl,firmware", fmanfw, fmanfw->header.length); 540ffadc441STimur Tabi if (rc < 0) { 541ffadc441STimur Tabi char s[64]; 542ffadc441STimur Tabi fdt_get_path(blob, fwnode, s, sizeof(s)); 543ffadc441STimur Tabi printf("Could not add firmware property to node %s: %s\n", s, 544ffadc441STimur Tabi fdt_strerror(rc)); 545ffadc441STimur Tabi return; 546ffadc441STimur Tabi } 547ffadc441STimur Tabi 548ffadc441STimur Tabi /* Find all other Fman nodes and point them to the firmware node. */ 549ffadc441STimur Tabi while ((fmnode = fdt_node_offset_by_compatible(blob, fmnode, "fsl,fman")) > 0) { 550ffadc441STimur Tabi rc = fdt_setprop_cell(blob, fmnode, "fsl,firmware-phandle", phandle); 551ffadc441STimur Tabi if (rc < 0) { 552ffadc441STimur Tabi char s[64]; 553ffadc441STimur Tabi fdt_get_path(blob, fmnode, s, sizeof(s)); 554ffadc441STimur Tabi printf("Could not add pointer property to node %s: %s\n", 555ffadc441STimur Tabi s, fdt_strerror(rc)); 556ffadc441STimur Tabi return; 557ffadc441STimur Tabi } 558ffadc441STimur Tabi } 559ffadc441STimur Tabi } 560ffadc441STimur Tabi #else 561ffadc441STimur Tabi #define fdt_fixup_fman_firmware(x) 562ffadc441STimur Tabi #endif 563ffadc441STimur Tabi 564055ce080STimur Tabi #if defined(CONFIG_PPC_P4080) 565f81f19faSShengzhou Liu static void fdt_fixup_usb(void *fdt) 566f81f19faSShengzhou Liu { 567f81f19faSShengzhou Liu ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 568f81f19faSShengzhou Liu u32 rcwsr11 = in_be32(&gur->rcwsr[11]); 569f81f19faSShengzhou Liu int off; 570f81f19faSShengzhou Liu 571f81f19faSShengzhou Liu off = fdt_node_offset_by_compatible(fdt, -1, "fsl,mpc85xx-usb2-mph"); 572f81f19faSShengzhou Liu if ((rcwsr11 & FSL_CORENET_RCWSR11_EC1) != 573f81f19faSShengzhou Liu FSL_CORENET_RCWSR11_EC1_FM1_USB1) 574f81f19faSShengzhou Liu fdt_status_disabled(fdt, off); 575f81f19faSShengzhou Liu 576f81f19faSShengzhou Liu off = fdt_node_offset_by_compatible(fdt, -1, "fsl,mpc85xx-usb2-dr"); 577f81f19faSShengzhou Liu if ((rcwsr11 & FSL_CORENET_RCWSR11_EC2) != 578f81f19faSShengzhou Liu FSL_CORENET_RCWSR11_EC2_USB2) 579f81f19faSShengzhou Liu fdt_status_disabled(fdt, off); 580f81f19faSShengzhou Liu } 581f81f19faSShengzhou Liu #else 582f81f19faSShengzhou Liu #define fdt_fixup_usb(x) 583f81f19faSShengzhou Liu #endif 584f81f19faSShengzhou Liu 585a47a12beSStefan Roese void ft_cpu_setup(void *blob, bd_t *bd) 586a47a12beSStefan Roese { 587a47a12beSStefan Roese int off; 588a47a12beSStefan Roese int val; 589a47a12beSStefan Roese sys_info_t sysinfo; 590a47a12beSStefan Roese 591a47a12beSStefan Roese /* delete crypto node if not on an E-processor */ 592a47a12beSStefan Roese if (!IS_E_PROCESSOR(get_svr())) 593a47a12beSStefan Roese fdt_fixup_crypto_node(blob, 0); 5945e95e2d8SVakul Garg #if CONFIG_SYS_FSL_SEC_COMPAT >= 4 5955e95e2d8SVakul Garg else { 5965e95e2d8SVakul Garg ccsr_sec_t __iomem *sec; 5975e95e2d8SVakul Garg 5985e95e2d8SVakul Garg sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR; 5995e95e2d8SVakul Garg fdt_fixup_crypto_node(blob, in_be32(&sec->secvid_ms)); 6005e95e2d8SVakul Garg } 6015e95e2d8SVakul Garg #endif 602a47a12beSStefan Roese 603a47a12beSStefan Roese fdt_fixup_ethernet(blob); 604a47a12beSStefan Roese 605a47a12beSStefan Roese fdt_add_enet_stashing(blob); 606a47a12beSStefan Roese 607cb93071bSYork Sun #ifndef CONFIG_FSL_TBCLK_EXTRA_DIV 608cb93071bSYork Sun #define CONFIG_FSL_TBCLK_EXTRA_DIV 1 609cb93071bSYork Sun #endif 610a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, 611cb93071bSYork Sun "timebase-frequency", get_tbclk() / CONFIG_FSL_TBCLK_EXTRA_DIV, 612cb93071bSYork Sun 1); 613a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, 614a47a12beSStefan Roese "bus-frequency", bd->bi_busfreq, 1); 615a47a12beSStefan Roese get_sys_info(&sysinfo); 616a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 617a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 618a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 619997399faSPrabhakar Kushwaha val = cpu_to_fdt32(sysinfo.freq_processor[*reg]); 620a47a12beSStefan Roese fdt_setprop(blob, off, "clock-frequency", &val, 4); 621a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, "device_type", 622a47a12beSStefan Roese "cpu", 4); 623a47a12beSStefan Roese } 624a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "soc", 4, 625a47a12beSStefan Roese "bus-frequency", bd->bi_busfreq, 1); 626a47a12beSStefan Roese 627a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,pq3-localbus", 62867ac13b1SSimon Glass "bus-frequency", gd->arch.lbc_clk, 1); 629a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,elbc", 63067ac13b1SSimon Glass "bus-frequency", gd->arch.lbc_clk, 1); 631a47a12beSStefan Roese #ifdef CONFIG_QE 632a47a12beSStefan Roese ft_qe_setup(blob); 633a47a12beSStefan Roese ft_fixup_qe_snum(blob); 634a47a12beSStefan Roese #endif 635a47a12beSStefan Roese 636ffadc441STimur Tabi fdt_fixup_fman_firmware(blob); 637ffadc441STimur Tabi 638a47a12beSStefan Roese #ifdef CONFIG_SYS_NS16550 639a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "ns16550", 640a47a12beSStefan Roese "clock-frequency", CONFIG_SYS_NS16550_CLK, 1); 641a47a12beSStefan Roese #endif 642a47a12beSStefan Roese 643a47a12beSStefan Roese #ifdef CONFIG_CPM2 644a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,cpm2-scc-uart", 645a47a12beSStefan Roese "current-speed", bd->bi_baudrate, 1); 646a47a12beSStefan Roese 647a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,cpm2-brg", 648a47a12beSStefan Roese "clock-frequency", bd->bi_brgfreq, 1); 649a47a12beSStefan Roese #endif 650a47a12beSStefan Roese 65185f8cda3SKumar Gala #ifdef CONFIG_FSL_CORENET 65285f8cda3SKumar Gala do_fixup_by_compat_u32(blob, "fsl,qoriq-clockgen-1.0", 65385f8cda3SKumar Gala "clock-frequency", CONFIG_SYS_CLK_FREQ, 1); 6547dd09b54SAndy Fleming do_fixup_by_compat_u32(blob, "fsl,qoriq-clockgen-2.0", 6557b700d21STang Yuantian "clock-frequency", CONFIG_SYS_CLK_FREQ, 1); 656f5c2623dSDongsheng.wang@freescale.com do_fixup_by_compat_u32(blob, "fsl,mpic", 657f5c2623dSDongsheng.wang@freescale.com "clock-frequency", get_bus_freq(0)/2, 1); 658f5c2623dSDongsheng.wang@freescale.com #else 659f5c2623dSDongsheng.wang@freescale.com do_fixup_by_compat_u32(blob, "fsl,mpic", 660f5c2623dSDongsheng.wang@freescale.com "clock-frequency", get_bus_freq(0), 1); 66185f8cda3SKumar Gala #endif 66285f8cda3SKumar Gala 663a47a12beSStefan Roese fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize); 664a47a12beSStefan Roese 665a47a12beSStefan Roese #ifdef CONFIG_MP 666a47a12beSStefan Roese ft_fixup_cpu(blob, (u64)bd->bi_memstart + (u64)bd->bi_memsize); 667a47a12beSStefan Roese ft_fixup_num_cores(blob); 6688f3a7fa4SKumar Gala #endif 669a47a12beSStefan Roese 670a47a12beSStefan Roese ft_fixup_cache(blob); 671a47a12beSStefan Roese 672a47a12beSStefan Roese #if defined(CONFIG_FSL_ESDHC) 673a47a12beSStefan Roese fdt_fixup_esdhc(blob, bd); 674a47a12beSStefan Roese #endif 675a47a12beSStefan Roese 676a47a12beSStefan Roese ft_fixup_dpaa_clks(blob); 677db977abfSKumar Gala 678db977abfSKumar Gala #if defined(CONFIG_SYS_BMAN_MEM_PHYS) 679db977abfSKumar Gala fdt_portal(blob, "fsl,bman-portal", "bman-portals", 680db977abfSKumar Gala (u64)CONFIG_SYS_BMAN_MEM_PHYS, 681db977abfSKumar Gala CONFIG_SYS_BMAN_MEM_SIZE); 6822a0ffb84SHaiying Wang fdt_fixup_bportals(blob); 683db977abfSKumar Gala #endif 684db977abfSKumar Gala 685db977abfSKumar Gala #if defined(CONFIG_SYS_QMAN_MEM_PHYS) 686db977abfSKumar Gala fdt_portal(blob, "fsl,qman-portal", "qman-portals", 687db977abfSKumar Gala (u64)CONFIG_SYS_QMAN_MEM_PHYS, 688db977abfSKumar Gala CONFIG_SYS_QMAN_MEM_SIZE); 689db977abfSKumar Gala 690db977abfSKumar Gala fdt_fixup_qportals(blob); 691db977abfSKumar Gala #endif 692a09b9b68SKumar Gala 693a09b9b68SKumar Gala #ifdef CONFIG_SYS_SRIO 694a09b9b68SKumar Gala ft_srio_setup(blob); 695a09b9b68SKumar Gala #endif 696f5feb5afSbhaskar upadhaya 697f5feb5afSbhaskar upadhaya /* 698f5feb5afSbhaskar upadhaya * system-clock = CCB clock/2 699f5feb5afSbhaskar upadhaya * Here gd->bus_clk = CCB clock 700f5feb5afSbhaskar upadhaya * We are using the system clock as 1588 Timer reference 701f5feb5afSbhaskar upadhaya * clock source select 702f5feb5afSbhaskar upadhaya */ 703f5feb5afSbhaskar upadhaya do_fixup_by_compat_u32(blob, "fsl,gianfar-ptp-timer", 704f5feb5afSbhaskar upadhaya "timer-frequency", gd->bus_clk/2, 1); 70565bb8b06SBhaskar Upadhaya 70633c87536SJia Hongtao /* 70733c87536SJia Hongtao * clock-freq should change to clock-frequency and 70833c87536SJia Hongtao * flexcan-v1.0 should change to p1010-flexcan respectively 70933c87536SJia Hongtao * in the future. 71033c87536SJia Hongtao */ 71165bb8b06SBhaskar Upadhaya do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0", 71233c87536SJia Hongtao "clock_freq", gd->bus_clk/2, 1); 71333c87536SJia Hongtao 71433c87536SJia Hongtao do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0", 71533c87536SJia Hongtao "clock-frequency", gd->bus_clk/2, 1); 71633c87536SJia Hongtao 71733c87536SJia Hongtao do_fixup_by_compat_u32(blob, "fsl,p1010-flexcan", 71833c87536SJia Hongtao "clock-frequency", gd->bus_clk/2, 1); 719f81f19faSShengzhou Liu 720f81f19faSShengzhou Liu fdt_fixup_usb(blob); 721a47a12beSStefan Roese } 72290f89f09STimur Tabi 72390f89f09STimur Tabi /* 72490f89f09STimur Tabi * For some CCSR devices, we only have the virtual address, not the physical 72590f89f09STimur Tabi * address. This is because we map CCSR as a whole, so we typically don't need 72690f89f09STimur Tabi * a macro for the physical address of any device within CCSR. In this case, 72790f89f09STimur Tabi * we calculate the physical address of that device using it's the difference 72890f89f09STimur Tabi * between the virtual address of the device and the virtual address of the 72990f89f09STimur Tabi * beginning of CCSR. 73090f89f09STimur Tabi */ 73190f89f09STimur Tabi #define CCSR_VIRT_TO_PHYS(x) \ 73290f89f09STimur Tabi (CONFIG_SYS_CCSRBAR_PHYS + ((x) - CONFIG_SYS_CCSRBAR)) 73390f89f09STimur Tabi 734cc15df57STimur Tabi static void msg(const char *name, uint64_t uaddr, uint64_t daddr) 735cc15df57STimur Tabi { 736cc15df57STimur Tabi printf("Warning: U-Boot configured %s at address %llx,\n" 737cc15df57STimur Tabi "but the device tree has it at %llx\n", name, uaddr, daddr); 738cc15df57STimur Tabi } 739cc15df57STimur Tabi 74090f89f09STimur Tabi /* 74190f89f09STimur Tabi * Verify the device tree 74290f89f09STimur Tabi * 74390f89f09STimur Tabi * This function compares several CONFIG_xxx macros that contain physical 74490f89f09STimur Tabi * addresses with the corresponding nodes in the device tree, to see if 74590f89f09STimur Tabi * the physical addresses are all correct. For example, if 74690f89f09STimur Tabi * CONFIG_SYS_NS16550_COM1 is defined, then it contains the virtual address 74790f89f09STimur Tabi * of the first UART. We convert this to a physical address and compare 74890f89f09STimur Tabi * that with the physical address of the first ns16550-compatible node 74990f89f09STimur Tabi * in the device tree. If they don't match, then we display a warning. 75090f89f09STimur Tabi * 75190f89f09STimur Tabi * Returns 1 on success, 0 on failure 75290f89f09STimur Tabi */ 75390f89f09STimur Tabi int ft_verify_fdt(void *fdt) 75490f89f09STimur Tabi { 755cc15df57STimur Tabi uint64_t addr = 0; 75690f89f09STimur Tabi int aliases; 75790f89f09STimur Tabi int off; 75890f89f09STimur Tabi 75990f89f09STimur Tabi /* First check the CCSR base address */ 76090f89f09STimur Tabi off = fdt_node_offset_by_prop_value(fdt, -1, "device_type", "soc", 4); 76190f89f09STimur Tabi if (off > 0) 762cc15df57STimur Tabi addr = fdt_get_base_address(fdt, off); 76390f89f09STimur Tabi 764cc15df57STimur Tabi if (!addr) { 76590f89f09STimur Tabi printf("Warning: could not determine base CCSR address in " 76690f89f09STimur Tabi "device tree\n"); 76790f89f09STimur Tabi /* No point in checking anything else */ 76890f89f09STimur Tabi return 0; 76990f89f09STimur Tabi } 77090f89f09STimur Tabi 771cc15df57STimur Tabi if (addr != CONFIG_SYS_CCSRBAR_PHYS) { 772cc15df57STimur Tabi msg("CCSR", CONFIG_SYS_CCSRBAR_PHYS, addr); 77390f89f09STimur Tabi /* No point in checking anything else */ 77490f89f09STimur Tabi return 0; 77590f89f09STimur Tabi } 77690f89f09STimur Tabi 77790f89f09STimur Tabi /* 778cc15df57STimur Tabi * Check some nodes via aliases. We assume that U-Boot and the device 779cc15df57STimur Tabi * tree enumerate the devices equally. E.g. the first serial port in 780cc15df57STimur Tabi * U-Boot is the same as "serial0" in the device tree. 78190f89f09STimur Tabi */ 78290f89f09STimur Tabi aliases = fdt_path_offset(fdt, "/aliases"); 78390f89f09STimur Tabi if (aliases > 0) { 78490f89f09STimur Tabi #ifdef CONFIG_SYS_NS16550_COM1 78590f89f09STimur Tabi if (!fdt_verify_alias_address(fdt, aliases, "serial0", 78690f89f09STimur Tabi CCSR_VIRT_TO_PHYS(CONFIG_SYS_NS16550_COM1))) 78790f89f09STimur Tabi return 0; 78890f89f09STimur Tabi #endif 78990f89f09STimur Tabi 79090f89f09STimur Tabi #ifdef CONFIG_SYS_NS16550_COM2 79190f89f09STimur Tabi if (!fdt_verify_alias_address(fdt, aliases, "serial1", 79290f89f09STimur Tabi CCSR_VIRT_TO_PHYS(CONFIG_SYS_NS16550_COM2))) 79390f89f09STimur Tabi return 0; 79490f89f09STimur Tabi #endif 79590f89f09STimur Tabi } 79690f89f09STimur Tabi 797cc15df57STimur Tabi /* 798cc15df57STimur Tabi * The localbus node is typically a root node, even though the lbc 799cc15df57STimur Tabi * controller is part of CCSR. If we were to put the lbc node under 800cc15df57STimur Tabi * the SOC node, then the 'ranges' property in the lbc node would 801cc15df57STimur Tabi * translate through the 'ranges' property of the parent SOC node, and 802cc15df57STimur Tabi * we don't want that. Since it's a separate node, it's possible for 803cc15df57STimur Tabi * the 'reg' property to be wrong, so check it here. For now, we 804cc15df57STimur Tabi * only check for "fsl,elbc" nodes. 805cc15df57STimur Tabi */ 806cc15df57STimur Tabi #ifdef CONFIG_SYS_LBC_ADDR 807cc15df57STimur Tabi off = fdt_node_offset_by_compatible(fdt, -1, "fsl,elbc"); 808cc15df57STimur Tabi if (off > 0) { 8098aa5ec6eSKim Phillips const fdt32_t *reg = fdt_getprop(fdt, off, "reg", NULL); 810cc15df57STimur Tabi if (reg) { 811cc15df57STimur Tabi uint64_t uaddr = CCSR_VIRT_TO_PHYS(CONFIG_SYS_LBC_ADDR); 812cc15df57STimur Tabi 813cc15df57STimur Tabi addr = fdt_translate_address(fdt, off, reg); 814cc15df57STimur Tabi if (uaddr != addr) { 815cc15df57STimur Tabi msg("the localbus", uaddr, addr); 816cc15df57STimur Tabi return 0; 817cc15df57STimur Tabi } 818cc15df57STimur Tabi } 819cc15df57STimur Tabi } 820cc15df57STimur Tabi #endif 821cc15df57STimur Tabi 82290f89f09STimur Tabi return 1; 82390f89f09STimur Tabi } 824