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 * 7a47a12beSStefan Roese * See file CREDITS for list of people who contributed to this 8a47a12beSStefan Roese * project. 9a47a12beSStefan Roese * 10a47a12beSStefan Roese * This program is free software; you can redistribute it and/or 11a47a12beSStefan Roese * modify it under the terms of the GNU General Public License as 12a47a12beSStefan Roese * published by the Free Software Foundation; either version 2 of 13a47a12beSStefan Roese * the License, or (at your option) any later version. 14a47a12beSStefan Roese * 15a47a12beSStefan Roese * This program is distributed in the hope that it will be useful, 16a47a12beSStefan Roese * but WITHOUT ANY WARRANTY; without even the implied warranty of 17a47a12beSStefan Roese * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18a47a12beSStefan Roese * GNU General Public License for more details. 19a47a12beSStefan Roese * 20a47a12beSStefan Roese * You should have received a copy of the GNU General Public License 21a47a12beSStefan Roese * along with this program; if not, write to the Free Software 22a47a12beSStefan Roese * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 23a47a12beSStefan Roese * MA 02111-1307 USA 24a47a12beSStefan Roese */ 25a47a12beSStefan Roese 26a47a12beSStefan Roese #include <common.h> 27a47a12beSStefan Roese #include <libfdt.h> 28a47a12beSStefan Roese #include <fdt_support.h> 29a47a12beSStefan Roese #include <asm/processor.h> 30a47a12beSStefan Roese #include <linux/ctype.h> 316aba33e9SKumar Gala #include <asm/io.h> 32db977abfSKumar Gala #include <asm/fsl_portals.h> 33a47a12beSStefan Roese #ifdef CONFIG_FSL_ESDHC 34a47a12beSStefan Roese #include <fsl_esdhc.h> 35a47a12beSStefan Roese #endif 36ffadc441STimur Tabi #include "../../../../drivers/qe/qe.h" /* For struct qe_firmware */ 37a47a12beSStefan Roese 38a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR; 39a47a12beSStefan Roese 40a47a12beSStefan Roese extern void ft_qe_setup(void *blob); 41a47a12beSStefan Roese extern void ft_fixup_num_cores(void *blob); 42a09b9b68SKumar Gala extern void ft_srio_setup(void *blob); 43a47a12beSStefan Roese 44a47a12beSStefan Roese #ifdef CONFIG_MP 45a47a12beSStefan Roese #include "mp.h" 46a47a12beSStefan Roese 47a47a12beSStefan Roese void ft_fixup_cpu(void *blob, u64 memory_limit) 48a47a12beSStefan Roese { 49a47a12beSStefan Roese int off; 50a47a12beSStefan Roese ulong spin_tbl_addr = get_spin_phys_addr(); 51*eb539412SYork Sun u32 bootpg = determine_mp_bootpg(NULL); 52a47a12beSStefan Roese u32 id = get_my_id(); 539d64c6bbSAaron Sierra const char *enable_method; 54a47a12beSStefan Roese 55a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 56a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 57a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 58a47a12beSStefan Roese 59a47a12beSStefan Roese if (reg) { 60709389b6SYork Sun u32 phys_cpu_id = thread_to_core(*reg); 61709389b6SYork Sun u64 val = phys_cpu_id * SIZE_BOOT_ENTRY + spin_tbl_addr; 62709389b6SYork Sun val = cpu_to_fdt64(val); 63b80d3054SMatthew McClintock if (*reg == id) { 64b80d3054SMatthew McClintock fdt_setprop_string(blob, off, "status", 65b80d3054SMatthew McClintock "okay"); 66b80d3054SMatthew McClintock } else { 67a47a12beSStefan Roese fdt_setprop_string(blob, off, "status", 68a47a12beSStefan Roese "disabled"); 69b80d3054SMatthew McClintock } 709d64c6bbSAaron Sierra 719d64c6bbSAaron Sierra if (hold_cores_in_reset(0)) { 729d64c6bbSAaron Sierra #ifdef CONFIG_FSL_CORENET 739d64c6bbSAaron Sierra /* Cores held in reset, use BRR to release */ 749d64c6bbSAaron Sierra enable_method = "fsl,brr-holdoff"; 759d64c6bbSAaron Sierra #else 769d64c6bbSAaron Sierra /* Cores held in reset, use EEBPCR to release */ 779d64c6bbSAaron Sierra enable_method = "fsl,eebpcr-holdoff"; 789d64c6bbSAaron Sierra #endif 799d64c6bbSAaron Sierra } else { 809d64c6bbSAaron Sierra /* Cores out of reset and in a spin-loop */ 819d64c6bbSAaron Sierra enable_method = "spin-table"; 829d64c6bbSAaron Sierra 83a47a12beSStefan Roese fdt_setprop(blob, off, "cpu-release-addr", 84a47a12beSStefan Roese &val, sizeof(val)); 859d64c6bbSAaron Sierra } 869d64c6bbSAaron Sierra 879d64c6bbSAaron Sierra fdt_setprop_string(blob, off, "enable-method", 889d64c6bbSAaron Sierra enable_method); 89a47a12beSStefan Roese } else { 90a47a12beSStefan Roese printf ("cpu NULL\n"); 91a47a12beSStefan Roese } 92a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, 93a47a12beSStefan Roese "device_type", "cpu", 4); 94a47a12beSStefan Roese } 95a47a12beSStefan Roese 96a47a12beSStefan Roese /* Reserve the boot page so OSes dont use it */ 97a47a12beSStefan Roese if ((u64)bootpg < memory_limit) { 98a47a12beSStefan Roese off = fdt_add_mem_rsv(blob, bootpg, (u64)4096); 99a47a12beSStefan Roese if (off < 0) 100a47a12beSStefan Roese printf("%s: %s\n", __FUNCTION__, fdt_strerror(off)); 101a47a12beSStefan Roese } 102a47a12beSStefan Roese } 103a47a12beSStefan Roese #endif 104a47a12beSStefan Roese 1056aba33e9SKumar Gala #ifdef CONFIG_SYS_FSL_CPC 1066aba33e9SKumar Gala static inline void ft_fixup_l3cache(void *blob, int off) 1076aba33e9SKumar Gala { 1086aba33e9SKumar Gala u32 line_size, num_ways, size, num_sets; 1096aba33e9SKumar Gala cpc_corenet_t *cpc = (void *)CONFIG_SYS_FSL_CPC_ADDR; 1106aba33e9SKumar Gala u32 cfg0 = in_be32(&cpc->cpccfg0); 1116aba33e9SKumar Gala 1126aba33e9SKumar Gala size = CPC_CFG0_SZ_K(cfg0) * 1024 * CONFIG_SYS_NUM_CPC; 1136aba33e9SKumar Gala num_ways = CPC_CFG0_NUM_WAYS(cfg0); 1146aba33e9SKumar Gala line_size = CPC_CFG0_LINE_SZ(cfg0); 1156aba33e9SKumar Gala num_sets = size / (line_size * num_ways); 1166aba33e9SKumar Gala 1176aba33e9SKumar Gala fdt_setprop(blob, off, "cache-unified", NULL, 0); 1186aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-block-size", line_size); 1196aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-size", size); 1206aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-sets", num_sets); 1216aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-level", 3); 1226aba33e9SKumar Gala #ifdef CONFIG_SYS_CACHE_STASHING 1236aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-stash-id", 1); 1246aba33e9SKumar Gala #endif 1256aba33e9SKumar Gala } 1266aba33e9SKumar Gala #else 127a47a12beSStefan Roese #define ft_fixup_l3cache(x, y) 1286aba33e9SKumar Gala #endif 129a47a12beSStefan Roese 130a47a12beSStefan Roese #if defined(CONFIG_L2_CACHE) 131a47a12beSStefan Roese /* return size in kilobytes */ 132a47a12beSStefan Roese static inline u32 l2cache_size(void) 133a47a12beSStefan Roese { 134a47a12beSStefan Roese volatile ccsr_l2cache_t *l2cache = (void *)CONFIG_SYS_MPC85xx_L2_ADDR; 135a47a12beSStefan Roese volatile u32 l2siz_field = (l2cache->l2ctl >> 28) & 0x3; 136a47a12beSStefan Roese u32 ver = SVR_SOC_VER(get_svr()); 137a47a12beSStefan Roese 138a47a12beSStefan Roese switch (l2siz_field) { 139a47a12beSStefan Roese case 0x0: 140a47a12beSStefan Roese break; 141a47a12beSStefan Roese case 0x1: 142a47a12beSStefan Roese if (ver == SVR_8540 || ver == SVR_8560 || 14348f6a5c3SYork Sun ver == SVR_8541 || ver == SVR_8555) 144a47a12beSStefan Roese return 128; 145a47a12beSStefan Roese else 146a47a12beSStefan Roese return 256; 147a47a12beSStefan Roese break; 148a47a12beSStefan Roese case 0x2: 149a47a12beSStefan Roese if (ver == SVR_8540 || ver == SVR_8560 || 15048f6a5c3SYork Sun ver == SVR_8541 || ver == SVR_8555) 151a47a12beSStefan Roese return 256; 152a47a12beSStefan Roese else 153a47a12beSStefan Roese return 512; 154a47a12beSStefan Roese break; 155a47a12beSStefan Roese case 0x3: 156a47a12beSStefan Roese return 1024; 157a47a12beSStefan Roese break; 158a47a12beSStefan Roese } 159a47a12beSStefan Roese 160a47a12beSStefan Roese return 0; 161a47a12beSStefan Roese } 162a47a12beSStefan Roese 163a47a12beSStefan Roese static inline void ft_fixup_l2cache(void *blob) 164a47a12beSStefan Roese { 165a47a12beSStefan Roese int len, off; 166a47a12beSStefan Roese u32 *ph; 167a47a12beSStefan Roese struct cpu_type *cpu = identify_cpu(SVR_SOC_VER(get_svr())); 168a47a12beSStefan Roese 169a47a12beSStefan Roese const u32 line_size = 32; 170a47a12beSStefan Roese const u32 num_ways = 8; 171a47a12beSStefan Roese const u32 size = l2cache_size() * 1024; 172a47a12beSStefan Roese const u32 num_sets = size / (line_size * num_ways); 173a47a12beSStefan Roese 174a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 175a47a12beSStefan Roese if (off < 0) { 176a47a12beSStefan Roese debug("no cpu node fount\n"); 177a47a12beSStefan Roese return; 178a47a12beSStefan Roese } 179a47a12beSStefan Roese 180a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0); 181a47a12beSStefan Roese 182a47a12beSStefan Roese if (ph == NULL) { 183a47a12beSStefan Roese debug("no next-level-cache property\n"); 184a47a12beSStefan Roese return ; 185a47a12beSStefan Roese } 186a47a12beSStefan Roese 187a47a12beSStefan Roese off = fdt_node_offset_by_phandle(blob, *ph); 188a47a12beSStefan Roese if (off < 0) { 189a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off)); 190a47a12beSStefan Roese return ; 191a47a12beSStefan Roese } 192a47a12beSStefan Roese 193a47a12beSStefan Roese if (cpu) { 194ee4756d4STimur Tabi char buf[40]; 195a47a12beSStefan Roese 196ee4756d4STimur Tabi if (isdigit(cpu->name[0])) { 197ee4756d4STimur Tabi /* MPCxxxx, where xxxx == 4-digit number */ 198ee4756d4STimur Tabi len = sprintf(buf, "fsl,mpc%s-l2-cache-controller", 199ee4756d4STimur Tabi cpu->name) + 1; 200ee4756d4STimur Tabi } else { 201ee4756d4STimur Tabi /* Pxxxx or Txxxx, where xxxx == 4-digit number */ 202ee4756d4STimur Tabi len = sprintf(buf, "fsl,%c%s-l2-cache-controller", 203ee4756d4STimur Tabi tolower(cpu->name[0]), cpu->name + 1) + 1; 204ee4756d4STimur Tabi } 205ee4756d4STimur Tabi 206ee4756d4STimur Tabi /* 207ee4756d4STimur Tabi * append "cache" after the NULL character that the previous 208ee4756d4STimur Tabi * sprintf wrote. This is how a device tree stores multiple 209ee4756d4STimur Tabi * strings in a property. 210ee4756d4STimur Tabi */ 211ee4756d4STimur Tabi len += sprintf(buf + len, "cache") + 1; 212ee4756d4STimur Tabi 213ee4756d4STimur Tabi fdt_setprop(blob, off, "compatible", buf, len); 214a47a12beSStefan Roese } 215a47a12beSStefan Roese fdt_setprop(blob, off, "cache-unified", NULL, 0); 216a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-block-size", line_size); 217a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-size", size); 218a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-sets", num_sets); 219a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-level", 2); 220a47a12beSStefan Roese 221a47a12beSStefan Roese /* we dont bother w/L3 since no platform of this type has one */ 222a47a12beSStefan Roese } 2236d2b9da1SYork Sun #elif defined(CONFIG_BACKSIDE_L2_CACHE) || \ 2246d2b9da1SYork Sun defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) 225a47a12beSStefan Roese static inline void ft_fixup_l2cache(void *blob) 226a47a12beSStefan Roese { 227a47a12beSStefan Roese int off, l2_off, l3_off = -1; 228a47a12beSStefan Roese u32 *ph; 2296d2b9da1SYork Sun #ifdef CONFIG_BACKSIDE_L2_CACHE 230a47a12beSStefan Roese u32 l2cfg0 = mfspr(SPRN_L2CFG0); 2316d2b9da1SYork Sun #else 2326d2b9da1SYork Sun struct ccsr_cluster_l2 *l2cache = 2336d2b9da1SYork Sun (struct ccsr_cluster_l2 __iomem *)(CONFIG_SYS_FSL_CLUSTER_1_L2); 2346d2b9da1SYork Sun u32 l2cfg0 = in_be32(&l2cache->l2cfg0); 2356d2b9da1SYork Sun #endif 236a47a12beSStefan Roese u32 size, line_size, num_ways, num_sets; 237acf3f8daSKumar Gala int has_l2 = 1; 238acf3f8daSKumar Gala 239acf3f8daSKumar Gala /* P2040/P2040E has no L2, so dont set any L2 props */ 24048f6a5c3SYork Sun if (SVR_SOC_VER(get_svr()) == SVR_P2040) 241acf3f8daSKumar Gala has_l2 = 0; 242a47a12beSStefan Roese 243a47a12beSStefan Roese size = (l2cfg0 & 0x3fff) * 64 * 1024; 244a47a12beSStefan Roese num_ways = ((l2cfg0 >> 14) & 0x1f) + 1; 245a47a12beSStefan Roese line_size = (((l2cfg0 >> 23) & 0x3) + 1) * 32; 246a47a12beSStefan Roese num_sets = size / (line_size * num_ways); 247a47a12beSStefan Roese 248a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 249a47a12beSStefan Roese 250a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 251a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0); 252a47a12beSStefan Roese 253a47a12beSStefan Roese if (ph == NULL) { 254a47a12beSStefan Roese debug("no next-level-cache property\n"); 255a47a12beSStefan Roese goto next; 256a47a12beSStefan Roese } 257a47a12beSStefan Roese 258a47a12beSStefan Roese l2_off = fdt_node_offset_by_phandle(blob, *ph); 259a47a12beSStefan Roese if (l2_off < 0) { 260a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off)); 261a47a12beSStefan Roese goto next; 262a47a12beSStefan Roese } 263a47a12beSStefan Roese 264acf3f8daSKumar Gala if (has_l2) { 265a47a12beSStefan Roese #ifdef CONFIG_SYS_CACHE_STASHING 266a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 2676d2b9da1SYork Sun #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2 2686d2b9da1SYork Sun /* Only initialize every eighth thread */ 2696d2b9da1SYork Sun if (reg && !((*reg) % 8)) 2706d2b9da1SYork Sun #else 271a47a12beSStefan Roese if (reg) 2726d2b9da1SYork Sun #endif 273a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-stash-id", 274a47a12beSStefan Roese (*reg * 2) + 32 + 1); 275a47a12beSStefan Roese #endif 276a47a12beSStefan Roese 277a47a12beSStefan Roese fdt_setprop(blob, l2_off, "cache-unified", NULL, 0); 278acf3f8daSKumar Gala fdt_setprop_cell(blob, l2_off, "cache-block-size", 279acf3f8daSKumar Gala line_size); 280a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-size", size); 281a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-sets", num_sets); 282a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-level", 2); 283a47a12beSStefan Roese fdt_setprop(blob, l2_off, "compatible", "cache", 6); 284acf3f8daSKumar Gala } 285a47a12beSStefan Roese 286a47a12beSStefan Roese if (l3_off < 0) { 287a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, l2_off, "next-level-cache", 0); 288a47a12beSStefan Roese 289a47a12beSStefan Roese if (ph == NULL) { 290a47a12beSStefan Roese debug("no next-level-cache property\n"); 291a47a12beSStefan Roese goto next; 292a47a12beSStefan Roese } 293a47a12beSStefan Roese l3_off = *ph; 294a47a12beSStefan Roese } 295a47a12beSStefan Roese next: 296a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, 297a47a12beSStefan Roese "device_type", "cpu", 4); 298a47a12beSStefan Roese } 299a47a12beSStefan Roese if (l3_off > 0) { 300a47a12beSStefan Roese l3_off = fdt_node_offset_by_phandle(blob, l3_off); 301a47a12beSStefan Roese if (l3_off < 0) { 302a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off)); 303a47a12beSStefan Roese return ; 304a47a12beSStefan Roese } 305a47a12beSStefan Roese ft_fixup_l3cache(blob, l3_off); 306a47a12beSStefan Roese } 307a47a12beSStefan Roese } 308a47a12beSStefan Roese #else 309a47a12beSStefan Roese #define ft_fixup_l2cache(x) 310a47a12beSStefan Roese #endif 311a47a12beSStefan Roese 312a47a12beSStefan Roese static inline void ft_fixup_cache(void *blob) 313a47a12beSStefan Roese { 314a47a12beSStefan Roese int off; 315a47a12beSStefan Roese 316a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 317a47a12beSStefan Roese 318a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 319a47a12beSStefan Roese u32 l1cfg0 = mfspr(SPRN_L1CFG0); 320a47a12beSStefan Roese u32 l1cfg1 = mfspr(SPRN_L1CFG1); 321a47a12beSStefan Roese u32 isize, iline_size, inum_sets, inum_ways; 322a47a12beSStefan Roese u32 dsize, dline_size, dnum_sets, dnum_ways; 323a47a12beSStefan Roese 324a47a12beSStefan Roese /* d-side config */ 325a47a12beSStefan Roese dsize = (l1cfg0 & 0x7ff) * 1024; 326a47a12beSStefan Roese dnum_ways = ((l1cfg0 >> 11) & 0xff) + 1; 327a47a12beSStefan Roese dline_size = (((l1cfg0 >> 23) & 0x3) + 1) * 32; 328a47a12beSStefan Roese dnum_sets = dsize / (dline_size * dnum_ways); 329a47a12beSStefan Roese 330a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-block-size", dline_size); 331a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-size", dsize); 332a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-sets", dnum_sets); 333a47a12beSStefan Roese 334a47a12beSStefan Roese #ifdef CONFIG_SYS_CACHE_STASHING 335a47a12beSStefan Roese { 336a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 337a47a12beSStefan Roese if (reg) 338a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-stash-id", 339a47a12beSStefan Roese (*reg * 2) + 32 + 0); 340a47a12beSStefan Roese } 341a47a12beSStefan Roese #endif 342a47a12beSStefan Roese 343a47a12beSStefan Roese /* i-side config */ 344a47a12beSStefan Roese isize = (l1cfg1 & 0x7ff) * 1024; 345a47a12beSStefan Roese inum_ways = ((l1cfg1 >> 11) & 0xff) + 1; 346a47a12beSStefan Roese iline_size = (((l1cfg1 >> 23) & 0x3) + 1) * 32; 347a47a12beSStefan Roese inum_sets = isize / (iline_size * inum_ways); 348a47a12beSStefan Roese 349a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-block-size", iline_size); 350a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-size", isize); 351a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-sets", inum_sets); 352a47a12beSStefan Roese 353a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, 354a47a12beSStefan Roese "device_type", "cpu", 4); 355a47a12beSStefan Roese } 356a47a12beSStefan Roese 357a47a12beSStefan Roese ft_fixup_l2cache(blob); 358a47a12beSStefan Roese } 359a47a12beSStefan Roese 360a47a12beSStefan Roese 361a47a12beSStefan Roese void fdt_add_enet_stashing(void *fdt) 362a47a12beSStefan Roese { 363a47a12beSStefan Roese do_fixup_by_compat(fdt, "gianfar", "bd-stash", NULL, 0, 1); 364a47a12beSStefan Roese 365a47a12beSStefan Roese do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-len", 96, 1); 366a47a12beSStefan Roese 367a47a12beSStefan Roese do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-idx", 0, 1); 368eea9a123SPankaj Chauhan do_fixup_by_compat(fdt, "fsl,etsec2", "bd-stash", NULL, 0, 1); 369eea9a123SPankaj Chauhan do_fixup_by_compat_u32(fdt, "fsl,etsec2", "rx-stash-len", 96, 1); 370eea9a123SPankaj Chauhan do_fixup_by_compat_u32(fdt, "fsl,etsec2", "rx-stash-idx", 0, 1); 371a47a12beSStefan Roese } 372a47a12beSStefan Roese 373a47a12beSStefan Roese #if defined(CONFIG_SYS_DPAA_FMAN) || defined(CONFIG_SYS_DPAA_PME) 374e2d0f255SKumar Gala #ifdef CONFIG_SYS_DPAA_FMAN 3751b942f74SKumar Gala static void ft_fixup_clks(void *blob, const char *compat, u32 offset, 3761b942f74SKumar Gala unsigned long freq) 377a47a12beSStefan Roese { 3781b942f74SKumar Gala phys_addr_t phys = offset + CONFIG_SYS_CCSRBAR_PHYS; 3791b942f74SKumar Gala int off = fdt_node_offset_by_compat_reg(blob, compat, phys); 380a47a12beSStefan Roese 381a47a12beSStefan Roese if (off >= 0) { 382a47a12beSStefan Roese off = fdt_setprop_cell(blob, off, "clock-frequency", freq); 383a47a12beSStefan Roese if (off > 0) 384a47a12beSStefan Roese printf("WARNING enable to set clock-frequency " 3851b942f74SKumar Gala "for %s: %s\n", compat, fdt_strerror(off)); 386a47a12beSStefan Roese } 387a47a12beSStefan Roese } 388e2d0f255SKumar Gala #endif 389a47a12beSStefan Roese 390a47a12beSStefan Roese static void ft_fixup_dpaa_clks(void *blob) 391a47a12beSStefan Roese { 392a47a12beSStefan Roese sys_info_t sysinfo; 393a47a12beSStefan Roese 394a47a12beSStefan Roese get_sys_info(&sysinfo); 395e2d0f255SKumar Gala #ifdef CONFIG_SYS_DPAA_FMAN 3961b942f74SKumar Gala ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM1_OFFSET, 3971b942f74SKumar Gala sysinfo.freqFMan[0]); 398a47a12beSStefan Roese 399a47a12beSStefan Roese #if (CONFIG_SYS_NUM_FMAN == 2) 4001b942f74SKumar Gala ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM2_OFFSET, 4011b942f74SKumar Gala sysinfo.freqFMan[1]); 402a47a12beSStefan Roese #endif 403e2d0f255SKumar Gala #endif 404a47a12beSStefan Roese 405a47a12beSStefan Roese #ifdef CONFIG_SYS_DPAA_PME 4061b942f74SKumar Gala do_fixup_by_compat_u32(blob, "fsl,pme", 4071b942f74SKumar Gala "clock-frequency", sysinfo.freqPME, 1); 408a47a12beSStefan Roese #endif 409a47a12beSStefan Roese } 410a47a12beSStefan Roese #else 411a47a12beSStefan Roese #define ft_fixup_dpaa_clks(x) 412a47a12beSStefan Roese #endif 413a47a12beSStefan Roese 414a47a12beSStefan Roese #ifdef CONFIG_QE 415a47a12beSStefan Roese static void ft_fixup_qe_snum(void *blob) 416a47a12beSStefan Roese { 417a47a12beSStefan Roese unsigned int svr; 418a47a12beSStefan Roese 419a47a12beSStefan Roese svr = mfspr(SPRN_SVR); 42048f6a5c3SYork Sun if (SVR_SOC_VER(svr) == SVR_8569) { 421a47a12beSStefan Roese if(IS_SVR_REV(svr, 1, 0)) 422a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,qe", 423a47a12beSStefan Roese "fsl,qe-num-snums", 46, 1); 424a47a12beSStefan Roese else 425a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,qe", 426a47a12beSStefan Roese "fsl,qe-num-snums", 76, 1); 427a47a12beSStefan Roese } 428a47a12beSStefan Roese } 429a47a12beSStefan Roese #endif 430a47a12beSStefan Roese 431ffadc441STimur Tabi /** 432ffadc441STimur Tabi * fdt_fixup_fman_firmware -- insert the Fman firmware into the device tree 433ffadc441STimur Tabi * 434ffadc441STimur Tabi * The binding for an Fman firmware node is documented in 435ffadc441STimur Tabi * Documentation/powerpc/dts-bindings/fsl/dpaa/fman.txt. This node contains 436ffadc441STimur Tabi * the actual Fman firmware binary data. The operating system is expected to 437ffadc441STimur Tabi * be able to parse the binary data to determine any attributes it needs. 438ffadc441STimur Tabi */ 439ffadc441STimur Tabi #ifdef CONFIG_SYS_DPAA_FMAN 440ffadc441STimur Tabi void fdt_fixup_fman_firmware(void *blob) 441ffadc441STimur Tabi { 442ffadc441STimur Tabi int rc, fmnode, fwnode = -1; 443ffadc441STimur Tabi uint32_t phandle; 444ffadc441STimur Tabi struct qe_firmware *fmanfw; 445ffadc441STimur Tabi const struct qe_header *hdr; 446ffadc441STimur Tabi unsigned int length; 447ffadc441STimur Tabi uint32_t crc; 448ffadc441STimur Tabi const char *p; 449ffadc441STimur Tabi 450ffadc441STimur Tabi /* The first Fman we find will contain the actual firmware. */ 451ffadc441STimur Tabi fmnode = fdt_node_offset_by_compatible(blob, -1, "fsl,fman"); 452ffadc441STimur Tabi if (fmnode < 0) 453ffadc441STimur Tabi /* Exit silently if there are no Fman devices */ 454ffadc441STimur Tabi return; 455ffadc441STimur Tabi 456ffadc441STimur Tabi /* If we already have a firmware node, then also exit silently. */ 457ffadc441STimur Tabi if (fdt_node_offset_by_compatible(blob, -1, "fsl,fman-firmware") > 0) 458ffadc441STimur Tabi return; 459ffadc441STimur Tabi 460ffadc441STimur Tabi /* If the environment variable is not set, then exit silently */ 461ffadc441STimur Tabi p = getenv("fman_ucode"); 462ffadc441STimur Tabi if (!p) 463ffadc441STimur Tabi return; 464ffadc441STimur Tabi 465ffadc441STimur Tabi fmanfw = (struct qe_firmware *) simple_strtoul(p, NULL, 0); 466ffadc441STimur Tabi if (!fmanfw) 467ffadc441STimur Tabi return; 468ffadc441STimur Tabi 469ffadc441STimur Tabi hdr = &fmanfw->header; 470ffadc441STimur Tabi length = be32_to_cpu(hdr->length); 471ffadc441STimur Tabi 472ffadc441STimur Tabi /* Verify the firmware. */ 473ffadc441STimur Tabi if ((hdr->magic[0] != 'Q') || (hdr->magic[1] != 'E') || 474ffadc441STimur Tabi (hdr->magic[2] != 'F')) { 475ffadc441STimur Tabi printf("Data at %p is not an Fman firmware\n", fmanfw); 476ffadc441STimur Tabi return; 477ffadc441STimur Tabi } 478ffadc441STimur Tabi 479f2717b47STimur Tabi if (length > CONFIG_SYS_QE_FMAN_FW_LENGTH) { 480ffadc441STimur Tabi printf("Fman firmware at %p is too large (size=%u)\n", 481ffadc441STimur Tabi fmanfw, length); 482ffadc441STimur Tabi return; 483ffadc441STimur Tabi } 484ffadc441STimur Tabi 485ffadc441STimur Tabi length -= sizeof(u32); /* Subtract the size of the CRC */ 486ffadc441STimur Tabi crc = be32_to_cpu(*(u32 *)((void *)fmanfw + length)); 487ffadc441STimur Tabi if (crc != crc32_no_comp(0, (void *)fmanfw, length)) { 488ffadc441STimur Tabi printf("Fman firmware at %p has invalid CRC\n", fmanfw); 489ffadc441STimur Tabi return; 490ffadc441STimur Tabi } 491ffadc441STimur Tabi 492ffadc441STimur Tabi /* Increase the size of the fdt to make room for the node. */ 493ffadc441STimur Tabi rc = fdt_increase_size(blob, fmanfw->header.length); 494ffadc441STimur Tabi if (rc < 0) { 495ffadc441STimur Tabi printf("Unable to make room for Fman firmware: %s\n", 496ffadc441STimur Tabi fdt_strerror(rc)); 497ffadc441STimur Tabi return; 498ffadc441STimur Tabi } 499ffadc441STimur Tabi 500ffadc441STimur Tabi /* Create the firmware node. */ 501ffadc441STimur Tabi fwnode = fdt_add_subnode(blob, fmnode, "fman-firmware"); 502ffadc441STimur Tabi if (fwnode < 0) { 503ffadc441STimur Tabi char s[64]; 504ffadc441STimur Tabi fdt_get_path(blob, fmnode, s, sizeof(s)); 505ffadc441STimur Tabi printf("Could not add firmware node to %s: %s\n", s, 506ffadc441STimur Tabi fdt_strerror(fwnode)); 507ffadc441STimur Tabi return; 508ffadc441STimur Tabi } 509ffadc441STimur Tabi rc = fdt_setprop_string(blob, fwnode, "compatible", "fsl,fman-firmware"); 510ffadc441STimur Tabi if (rc < 0) { 511ffadc441STimur Tabi char s[64]; 512ffadc441STimur Tabi fdt_get_path(blob, fwnode, s, sizeof(s)); 513ffadc441STimur Tabi printf("Could not add compatible property to node %s: %s\n", s, 514ffadc441STimur Tabi fdt_strerror(rc)); 515ffadc441STimur Tabi return; 516ffadc441STimur Tabi } 517a2c1229cSTimur Tabi phandle = fdt_create_phandle(blob, fwnode); 518a2c1229cSTimur Tabi if (!phandle) { 519ffadc441STimur Tabi char s[64]; 520ffadc441STimur Tabi fdt_get_path(blob, fwnode, s, sizeof(s)); 521ffadc441STimur Tabi printf("Could not add phandle property to node %s: %s\n", s, 522ffadc441STimur Tabi fdt_strerror(rc)); 523ffadc441STimur Tabi return; 524ffadc441STimur Tabi } 525ffadc441STimur Tabi rc = fdt_setprop(blob, fwnode, "fsl,firmware", fmanfw, fmanfw->header.length); 526ffadc441STimur Tabi if (rc < 0) { 527ffadc441STimur Tabi char s[64]; 528ffadc441STimur Tabi fdt_get_path(blob, fwnode, s, sizeof(s)); 529ffadc441STimur Tabi printf("Could not add firmware property to node %s: %s\n", s, 530ffadc441STimur Tabi fdt_strerror(rc)); 531ffadc441STimur Tabi return; 532ffadc441STimur Tabi } 533ffadc441STimur Tabi 534ffadc441STimur Tabi /* Find all other Fman nodes and point them to the firmware node. */ 535ffadc441STimur Tabi while ((fmnode = fdt_node_offset_by_compatible(blob, fmnode, "fsl,fman")) > 0) { 536ffadc441STimur Tabi rc = fdt_setprop_cell(blob, fmnode, "fsl,firmware-phandle", phandle); 537ffadc441STimur Tabi if (rc < 0) { 538ffadc441STimur Tabi char s[64]; 539ffadc441STimur Tabi fdt_get_path(blob, fmnode, s, sizeof(s)); 540ffadc441STimur Tabi printf("Could not add pointer property to node %s: %s\n", 541ffadc441STimur Tabi s, fdt_strerror(rc)); 542ffadc441STimur Tabi return; 543ffadc441STimur Tabi } 544ffadc441STimur Tabi } 545ffadc441STimur Tabi } 546ffadc441STimur Tabi #else 547ffadc441STimur Tabi #define fdt_fixup_fman_firmware(x) 548ffadc441STimur Tabi #endif 549ffadc441STimur Tabi 550055ce080STimur Tabi #if defined(CONFIG_PPC_P4080) 551f81f19faSShengzhou Liu static void fdt_fixup_usb(void *fdt) 552f81f19faSShengzhou Liu { 553f81f19faSShengzhou Liu ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 554f81f19faSShengzhou Liu u32 rcwsr11 = in_be32(&gur->rcwsr[11]); 555f81f19faSShengzhou Liu int off; 556f81f19faSShengzhou Liu 557f81f19faSShengzhou Liu off = fdt_node_offset_by_compatible(fdt, -1, "fsl,mpc85xx-usb2-mph"); 558f81f19faSShengzhou Liu if ((rcwsr11 & FSL_CORENET_RCWSR11_EC1) != 559f81f19faSShengzhou Liu FSL_CORENET_RCWSR11_EC1_FM1_USB1) 560f81f19faSShengzhou Liu fdt_status_disabled(fdt, off); 561f81f19faSShengzhou Liu 562f81f19faSShengzhou Liu off = fdt_node_offset_by_compatible(fdt, -1, "fsl,mpc85xx-usb2-dr"); 563f81f19faSShengzhou Liu if ((rcwsr11 & FSL_CORENET_RCWSR11_EC2) != 564f81f19faSShengzhou Liu FSL_CORENET_RCWSR11_EC2_USB2) 565f81f19faSShengzhou Liu fdt_status_disabled(fdt, off); 566f81f19faSShengzhou Liu } 567f81f19faSShengzhou Liu #else 568f81f19faSShengzhou Liu #define fdt_fixup_usb(x) 569f81f19faSShengzhou Liu #endif 570f81f19faSShengzhou Liu 571a47a12beSStefan Roese void ft_cpu_setup(void *blob, bd_t *bd) 572a47a12beSStefan Roese { 573a47a12beSStefan Roese int off; 574a47a12beSStefan Roese int val; 575a47a12beSStefan Roese sys_info_t sysinfo; 576a47a12beSStefan Roese 577a47a12beSStefan Roese /* delete crypto node if not on an E-processor */ 578a47a12beSStefan Roese if (!IS_E_PROCESSOR(get_svr())) 579a47a12beSStefan Roese fdt_fixup_crypto_node(blob, 0); 580a47a12beSStefan Roese 581a47a12beSStefan Roese fdt_fixup_ethernet(blob); 582a47a12beSStefan Roese 583a47a12beSStefan Roese fdt_add_enet_stashing(blob); 584a47a12beSStefan Roese 585a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, 586a47a12beSStefan Roese "timebase-frequency", get_tbclk(), 1); 587a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, 588a47a12beSStefan Roese "bus-frequency", bd->bi_busfreq, 1); 589a47a12beSStefan Roese get_sys_info(&sysinfo); 590a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 591a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 592a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 593a47a12beSStefan Roese val = cpu_to_fdt32(sysinfo.freqProcessor[*reg]); 594a47a12beSStefan Roese fdt_setprop(blob, off, "clock-frequency", &val, 4); 595a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, "device_type", 596a47a12beSStefan Roese "cpu", 4); 597a47a12beSStefan Roese } 598a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "soc", 4, 599a47a12beSStefan Roese "bus-frequency", bd->bi_busfreq, 1); 600a47a12beSStefan Roese 601a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,pq3-localbus", 602a47a12beSStefan Roese "bus-frequency", gd->lbc_clk, 1); 603a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,elbc", 604a47a12beSStefan Roese "bus-frequency", gd->lbc_clk, 1); 605a47a12beSStefan Roese #ifdef CONFIG_QE 606a47a12beSStefan Roese ft_qe_setup(blob); 607a47a12beSStefan Roese ft_fixup_qe_snum(blob); 608a47a12beSStefan Roese #endif 609a47a12beSStefan Roese 610ffadc441STimur Tabi fdt_fixup_fman_firmware(blob); 611ffadc441STimur Tabi 612a47a12beSStefan Roese #ifdef CONFIG_SYS_NS16550 613a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "ns16550", 614a47a12beSStefan Roese "clock-frequency", CONFIG_SYS_NS16550_CLK, 1); 615a47a12beSStefan Roese #endif 616a47a12beSStefan Roese 617a47a12beSStefan Roese #ifdef CONFIG_CPM2 618a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,cpm2-scc-uart", 619a47a12beSStefan Roese "current-speed", bd->bi_baudrate, 1); 620a47a12beSStefan Roese 621a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,cpm2-brg", 622a47a12beSStefan Roese "clock-frequency", bd->bi_brgfreq, 1); 623a47a12beSStefan Roese #endif 624a47a12beSStefan Roese 62585f8cda3SKumar Gala #ifdef CONFIG_FSL_CORENET 62685f8cda3SKumar Gala do_fixup_by_compat_u32(blob, "fsl,qoriq-clockgen-1.0", 62785f8cda3SKumar Gala "clock-frequency", CONFIG_SYS_CLK_FREQ, 1); 62885f8cda3SKumar Gala #endif 62985f8cda3SKumar Gala 630a47a12beSStefan Roese fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize); 631a47a12beSStefan Roese 632a47a12beSStefan Roese #ifdef CONFIG_MP 633a47a12beSStefan Roese ft_fixup_cpu(blob, (u64)bd->bi_memstart + (u64)bd->bi_memsize); 634a47a12beSStefan Roese ft_fixup_num_cores(blob); 6358f3a7fa4SKumar Gala #endif 636a47a12beSStefan Roese 637a47a12beSStefan Roese ft_fixup_cache(blob); 638a47a12beSStefan Roese 639a47a12beSStefan Roese #if defined(CONFIG_FSL_ESDHC) 640a47a12beSStefan Roese fdt_fixup_esdhc(blob, bd); 641a47a12beSStefan Roese #endif 642a47a12beSStefan Roese 643a47a12beSStefan Roese ft_fixup_dpaa_clks(blob); 644db977abfSKumar Gala 645db977abfSKumar Gala #if defined(CONFIG_SYS_BMAN_MEM_PHYS) 646db977abfSKumar Gala fdt_portal(blob, "fsl,bman-portal", "bman-portals", 647db977abfSKumar Gala (u64)CONFIG_SYS_BMAN_MEM_PHYS, 648db977abfSKumar Gala CONFIG_SYS_BMAN_MEM_SIZE); 6492a0ffb84SHaiying Wang fdt_fixup_bportals(blob); 650db977abfSKumar Gala #endif 651db977abfSKumar Gala 652db977abfSKumar Gala #if defined(CONFIG_SYS_QMAN_MEM_PHYS) 653db977abfSKumar Gala fdt_portal(blob, "fsl,qman-portal", "qman-portals", 654db977abfSKumar Gala (u64)CONFIG_SYS_QMAN_MEM_PHYS, 655db977abfSKumar Gala CONFIG_SYS_QMAN_MEM_SIZE); 656db977abfSKumar Gala 657db977abfSKumar Gala fdt_fixup_qportals(blob); 658db977abfSKumar Gala #endif 659a09b9b68SKumar Gala 660a09b9b68SKumar Gala #ifdef CONFIG_SYS_SRIO 661a09b9b68SKumar Gala ft_srio_setup(blob); 662a09b9b68SKumar Gala #endif 663f5feb5afSbhaskar upadhaya 664f5feb5afSbhaskar upadhaya /* 665f5feb5afSbhaskar upadhaya * system-clock = CCB clock/2 666f5feb5afSbhaskar upadhaya * Here gd->bus_clk = CCB clock 667f5feb5afSbhaskar upadhaya * We are using the system clock as 1588 Timer reference 668f5feb5afSbhaskar upadhaya * clock source select 669f5feb5afSbhaskar upadhaya */ 670f5feb5afSbhaskar upadhaya do_fixup_by_compat_u32(blob, "fsl,gianfar-ptp-timer", 671f5feb5afSbhaskar upadhaya "timer-frequency", gd->bus_clk/2, 1); 67265bb8b06SBhaskar Upadhaya 67333c87536SJia Hongtao /* 67433c87536SJia Hongtao * clock-freq should change to clock-frequency and 67533c87536SJia Hongtao * flexcan-v1.0 should change to p1010-flexcan respectively 67633c87536SJia Hongtao * in the future. 67733c87536SJia Hongtao */ 67865bb8b06SBhaskar Upadhaya do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0", 67933c87536SJia Hongtao "clock_freq", gd->bus_clk/2, 1); 68033c87536SJia Hongtao 68133c87536SJia Hongtao do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0", 68233c87536SJia Hongtao "clock-frequency", gd->bus_clk/2, 1); 68333c87536SJia Hongtao 68433c87536SJia Hongtao do_fixup_by_compat_u32(blob, "fsl,p1010-flexcan", 68533c87536SJia Hongtao "clock-frequency", gd->bus_clk/2, 1); 686f81f19faSShengzhou Liu 687f81f19faSShengzhou Liu fdt_fixup_usb(blob); 688a47a12beSStefan Roese } 68990f89f09STimur Tabi 69090f89f09STimur Tabi /* 69190f89f09STimur Tabi * For some CCSR devices, we only have the virtual address, not the physical 69290f89f09STimur Tabi * address. This is because we map CCSR as a whole, so we typically don't need 69390f89f09STimur Tabi * a macro for the physical address of any device within CCSR. In this case, 69490f89f09STimur Tabi * we calculate the physical address of that device using it's the difference 69590f89f09STimur Tabi * between the virtual address of the device and the virtual address of the 69690f89f09STimur Tabi * beginning of CCSR. 69790f89f09STimur Tabi */ 69890f89f09STimur Tabi #define CCSR_VIRT_TO_PHYS(x) \ 69990f89f09STimur Tabi (CONFIG_SYS_CCSRBAR_PHYS + ((x) - CONFIG_SYS_CCSRBAR)) 70090f89f09STimur Tabi 701cc15df57STimur Tabi static void msg(const char *name, uint64_t uaddr, uint64_t daddr) 702cc15df57STimur Tabi { 703cc15df57STimur Tabi printf("Warning: U-Boot configured %s at address %llx,\n" 704cc15df57STimur Tabi "but the device tree has it at %llx\n", name, uaddr, daddr); 705cc15df57STimur Tabi } 706cc15df57STimur Tabi 70790f89f09STimur Tabi /* 70890f89f09STimur Tabi * Verify the device tree 70990f89f09STimur Tabi * 71090f89f09STimur Tabi * This function compares several CONFIG_xxx macros that contain physical 71190f89f09STimur Tabi * addresses with the corresponding nodes in the device tree, to see if 71290f89f09STimur Tabi * the physical addresses are all correct. For example, if 71390f89f09STimur Tabi * CONFIG_SYS_NS16550_COM1 is defined, then it contains the virtual address 71490f89f09STimur Tabi * of the first UART. We convert this to a physical address and compare 71590f89f09STimur Tabi * that with the physical address of the first ns16550-compatible node 71690f89f09STimur Tabi * in the device tree. If they don't match, then we display a warning. 71790f89f09STimur Tabi * 71890f89f09STimur Tabi * Returns 1 on success, 0 on failure 71990f89f09STimur Tabi */ 72090f89f09STimur Tabi int ft_verify_fdt(void *fdt) 72190f89f09STimur Tabi { 722cc15df57STimur Tabi uint64_t addr = 0; 72390f89f09STimur Tabi int aliases; 72490f89f09STimur Tabi int off; 72590f89f09STimur Tabi 72690f89f09STimur Tabi /* First check the CCSR base address */ 72790f89f09STimur Tabi off = fdt_node_offset_by_prop_value(fdt, -1, "device_type", "soc", 4); 72890f89f09STimur Tabi if (off > 0) 729cc15df57STimur Tabi addr = fdt_get_base_address(fdt, off); 73090f89f09STimur Tabi 731cc15df57STimur Tabi if (!addr) { 73290f89f09STimur Tabi printf("Warning: could not determine base CCSR address in " 73390f89f09STimur Tabi "device tree\n"); 73490f89f09STimur Tabi /* No point in checking anything else */ 73590f89f09STimur Tabi return 0; 73690f89f09STimur Tabi } 73790f89f09STimur Tabi 738cc15df57STimur Tabi if (addr != CONFIG_SYS_CCSRBAR_PHYS) { 739cc15df57STimur Tabi msg("CCSR", CONFIG_SYS_CCSRBAR_PHYS, addr); 74090f89f09STimur Tabi /* No point in checking anything else */ 74190f89f09STimur Tabi return 0; 74290f89f09STimur Tabi } 74390f89f09STimur Tabi 74490f89f09STimur Tabi /* 745cc15df57STimur Tabi * Check some nodes via aliases. We assume that U-Boot and the device 746cc15df57STimur Tabi * tree enumerate the devices equally. E.g. the first serial port in 747cc15df57STimur Tabi * U-Boot is the same as "serial0" in the device tree. 74890f89f09STimur Tabi */ 74990f89f09STimur Tabi aliases = fdt_path_offset(fdt, "/aliases"); 75090f89f09STimur Tabi if (aliases > 0) { 75190f89f09STimur Tabi #ifdef CONFIG_SYS_NS16550_COM1 75290f89f09STimur Tabi if (!fdt_verify_alias_address(fdt, aliases, "serial0", 75390f89f09STimur Tabi CCSR_VIRT_TO_PHYS(CONFIG_SYS_NS16550_COM1))) 75490f89f09STimur Tabi return 0; 75590f89f09STimur Tabi #endif 75690f89f09STimur Tabi 75790f89f09STimur Tabi #ifdef CONFIG_SYS_NS16550_COM2 75890f89f09STimur Tabi if (!fdt_verify_alias_address(fdt, aliases, "serial1", 75990f89f09STimur Tabi CCSR_VIRT_TO_PHYS(CONFIG_SYS_NS16550_COM2))) 76090f89f09STimur Tabi return 0; 76190f89f09STimur Tabi #endif 76290f89f09STimur Tabi } 76390f89f09STimur Tabi 764cc15df57STimur Tabi /* 765cc15df57STimur Tabi * The localbus node is typically a root node, even though the lbc 766cc15df57STimur Tabi * controller is part of CCSR. If we were to put the lbc node under 767cc15df57STimur Tabi * the SOC node, then the 'ranges' property in the lbc node would 768cc15df57STimur Tabi * translate through the 'ranges' property of the parent SOC node, and 769cc15df57STimur Tabi * we don't want that. Since it's a separate node, it's possible for 770cc15df57STimur Tabi * the 'reg' property to be wrong, so check it here. For now, we 771cc15df57STimur Tabi * only check for "fsl,elbc" nodes. 772cc15df57STimur Tabi */ 773cc15df57STimur Tabi #ifdef CONFIG_SYS_LBC_ADDR 774cc15df57STimur Tabi off = fdt_node_offset_by_compatible(fdt, -1, "fsl,elbc"); 775cc15df57STimur Tabi if (off > 0) { 776cc15df57STimur Tabi const u32 *reg = fdt_getprop(fdt, off, "reg", NULL); 777cc15df57STimur Tabi if (reg) { 778cc15df57STimur Tabi uint64_t uaddr = CCSR_VIRT_TO_PHYS(CONFIG_SYS_LBC_ADDR); 779cc15df57STimur Tabi 780cc15df57STimur Tabi addr = fdt_translate_address(fdt, off, reg); 781cc15df57STimur Tabi if (uaddr != addr) { 782cc15df57STimur Tabi msg("the localbus", uaddr, addr); 783cc15df57STimur Tabi return 0; 784cc15df57STimur Tabi } 785cc15df57STimur Tabi } 786cc15df57STimur Tabi } 787cc15df57STimur Tabi #endif 788cc15df57STimur Tabi 78990f89f09STimur Tabi return 1; 79090f89f09STimur Tabi } 791