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> 17*377ffcfaSSandeep Singh #include <hwconfig.h> 18a47a12beSStefan Roese #ifdef CONFIG_FSL_ESDHC 19a47a12beSStefan Roese #include <fsl_esdhc.h> 20a47a12beSStefan Roese #endif 21ffadc441STimur Tabi #include "../../../../drivers/qe/qe.h" /* For struct qe_firmware */ 22a47a12beSStefan Roese 23a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR; 24a47a12beSStefan Roese 25a47a12beSStefan Roese extern void ft_qe_setup(void *blob); 26a47a12beSStefan Roese extern void ft_fixup_num_cores(void *blob); 27a09b9b68SKumar Gala extern void ft_srio_setup(void *blob); 28a47a12beSStefan Roese 29a47a12beSStefan Roese #ifdef CONFIG_MP 30a47a12beSStefan Roese #include "mp.h" 31a47a12beSStefan Roese 32a47a12beSStefan Roese void ft_fixup_cpu(void *blob, u64 memory_limit) 33a47a12beSStefan Roese { 34a47a12beSStefan Roese int off; 35ffd06e02SYork Sun phys_addr_t spin_tbl_addr = get_spin_phys_addr(); 36eb539412SYork Sun u32 bootpg = determine_mp_bootpg(NULL); 37a47a12beSStefan Roese u32 id = get_my_id(); 389d64c6bbSAaron Sierra const char *enable_method; 39*377ffcfaSSandeep Singh #if defined(T1040_TDM_QUIRK_CCSR_BASE) 40*377ffcfaSSandeep Singh int ret; 41*377ffcfaSSandeep Singh int tdm_hwconfig_enabled = 0; 42*377ffcfaSSandeep Singh char buffer[HWCONFIG_BUFFER_SIZE] = {0}; 43*377ffcfaSSandeep Singh #endif 44a47a12beSStefan Roese 45a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 46a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 47a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 48a47a12beSStefan Roese 49a47a12beSStefan Roese if (reg) { 50709389b6SYork Sun u32 phys_cpu_id = thread_to_core(*reg); 51709389b6SYork Sun u64 val = phys_cpu_id * SIZE_BOOT_ENTRY + spin_tbl_addr; 52709389b6SYork Sun val = cpu_to_fdt64(val); 53b80d3054SMatthew McClintock if (*reg == id) { 54b80d3054SMatthew McClintock fdt_setprop_string(blob, off, "status", 55b80d3054SMatthew McClintock "okay"); 56b80d3054SMatthew McClintock } else { 57a47a12beSStefan Roese fdt_setprop_string(blob, off, "status", 58a47a12beSStefan Roese "disabled"); 59b80d3054SMatthew McClintock } 609d64c6bbSAaron Sierra 619d64c6bbSAaron Sierra if (hold_cores_in_reset(0)) { 629d64c6bbSAaron Sierra #ifdef CONFIG_FSL_CORENET 639d64c6bbSAaron Sierra /* Cores held in reset, use BRR to release */ 649d64c6bbSAaron Sierra enable_method = "fsl,brr-holdoff"; 659d64c6bbSAaron Sierra #else 669d64c6bbSAaron Sierra /* Cores held in reset, use EEBPCR to release */ 679d64c6bbSAaron Sierra enable_method = "fsl,eebpcr-holdoff"; 689d64c6bbSAaron Sierra #endif 699d64c6bbSAaron Sierra } else { 709d64c6bbSAaron Sierra /* Cores out of reset and in a spin-loop */ 719d64c6bbSAaron Sierra enable_method = "spin-table"; 729d64c6bbSAaron Sierra 73a47a12beSStefan Roese fdt_setprop(blob, off, "cpu-release-addr", 74a47a12beSStefan Roese &val, sizeof(val)); 759d64c6bbSAaron Sierra } 769d64c6bbSAaron Sierra 779d64c6bbSAaron Sierra fdt_setprop_string(blob, off, "enable-method", 789d64c6bbSAaron Sierra enable_method); 79a47a12beSStefan Roese } else { 80a47a12beSStefan Roese printf ("cpu NULL\n"); 81a47a12beSStefan Roese } 82a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, 83a47a12beSStefan Roese "device_type", "cpu", 4); 84a47a12beSStefan Roese } 85a47a12beSStefan Roese 86*377ffcfaSSandeep Singh #if defined(T1040_TDM_QUIRK_CCSR_BASE) 87*377ffcfaSSandeep Singh #define CONFIG_MEM_HOLE_16M 0x1000000 88*377ffcfaSSandeep Singh /* 89*377ffcfaSSandeep Singh * Extract hwconfig from environment. 90*377ffcfaSSandeep Singh * Search for tdm entry in hwconfig. 91*377ffcfaSSandeep Singh */ 92*377ffcfaSSandeep Singh ret = getenv_f("hwconfig", buffer, sizeof(buffer)); 93*377ffcfaSSandeep Singh if (ret > 0) 94*377ffcfaSSandeep Singh tdm_hwconfig_enabled = hwconfig_f("tdm", buffer); 95*377ffcfaSSandeep Singh 96*377ffcfaSSandeep Singh /* Reserve the memory hole created by TDM LAW, so OSes dont use it */ 97*377ffcfaSSandeep Singh if (tdm_hwconfig_enabled) { 98*377ffcfaSSandeep Singh off = fdt_add_mem_rsv(blob, T1040_TDM_QUIRK_CCSR_BASE, 99*377ffcfaSSandeep Singh CONFIG_MEM_HOLE_16M); 100*377ffcfaSSandeep Singh if (off < 0) 101*377ffcfaSSandeep Singh printf("Failed to reserve memory for tdm: %s\n", 102*377ffcfaSSandeep Singh fdt_strerror(off)); 103*377ffcfaSSandeep Singh } 104*377ffcfaSSandeep Singh #endif 105*377ffcfaSSandeep Singh 106a47a12beSStefan Roese /* Reserve the boot page so OSes dont use it */ 107a47a12beSStefan Roese if ((u64)bootpg < memory_limit) { 108a47a12beSStefan Roese off = fdt_add_mem_rsv(blob, bootpg, (u64)4096); 109a47a12beSStefan Roese if (off < 0) 110ffd06e02SYork Sun printf("Failed to reserve memory for bootpg: %s\n", 111ffd06e02SYork Sun fdt_strerror(off)); 112ffd06e02SYork Sun } 1132d9f26b6SYork Sun 1142d9f26b6SYork Sun #ifndef CONFIG_MPC8xxx_DISABLE_BPTR 1152d9f26b6SYork Sun /* 1162d9f26b6SYork Sun * Reserve the default boot page so OSes dont use it. 1172d9f26b6SYork Sun * The default boot page is always mapped to bootpg above using 1182d9f26b6SYork Sun * boot page translation. 1192d9f26b6SYork Sun */ 1202d9f26b6SYork Sun if (0xfffff000ull < memory_limit) { 1212d9f26b6SYork Sun off = fdt_add_mem_rsv(blob, 0xfffff000ull, (u64)4096); 1222d9f26b6SYork Sun if (off < 0) { 1232d9f26b6SYork Sun printf("Failed to reserve memory for 0xfffff000: %s\n", 1242d9f26b6SYork Sun fdt_strerror(off)); 1252d9f26b6SYork Sun } 1262d9f26b6SYork Sun } 1272d9f26b6SYork Sun #endif 1282d9f26b6SYork Sun 129ffd06e02SYork Sun /* Reserve spin table page */ 130ffd06e02SYork Sun if (spin_tbl_addr < memory_limit) { 131ffd06e02SYork Sun off = fdt_add_mem_rsv(blob, 132ffd06e02SYork Sun (spin_tbl_addr & ~0xffful), 4096); 133ffd06e02SYork Sun if (off < 0) 134ffd06e02SYork Sun printf("Failed to reserve memory for spin table: %s\n", 135ffd06e02SYork Sun fdt_strerror(off)); 136a47a12beSStefan Roese } 137a47a12beSStefan Roese } 138a47a12beSStefan Roese #endif 139a47a12beSStefan Roese 1406aba33e9SKumar Gala #ifdef CONFIG_SYS_FSL_CPC 1416aba33e9SKumar Gala static inline void ft_fixup_l3cache(void *blob, int off) 1426aba33e9SKumar Gala { 1436aba33e9SKumar Gala u32 line_size, num_ways, size, num_sets; 1446aba33e9SKumar Gala cpc_corenet_t *cpc = (void *)CONFIG_SYS_FSL_CPC_ADDR; 1456aba33e9SKumar Gala u32 cfg0 = in_be32(&cpc->cpccfg0); 1466aba33e9SKumar Gala 1476aba33e9SKumar Gala size = CPC_CFG0_SZ_K(cfg0) * 1024 * CONFIG_SYS_NUM_CPC; 1486aba33e9SKumar Gala num_ways = CPC_CFG0_NUM_WAYS(cfg0); 1496aba33e9SKumar Gala line_size = CPC_CFG0_LINE_SZ(cfg0); 1506aba33e9SKumar Gala num_sets = size / (line_size * num_ways); 1516aba33e9SKumar Gala 1526aba33e9SKumar Gala fdt_setprop(blob, off, "cache-unified", NULL, 0); 1536aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-block-size", line_size); 1546aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-size", size); 1556aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-sets", num_sets); 1566aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-level", 3); 1576aba33e9SKumar Gala #ifdef CONFIG_SYS_CACHE_STASHING 1586aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-stash-id", 1); 1596aba33e9SKumar Gala #endif 1606aba33e9SKumar Gala } 1616aba33e9SKumar Gala #else 162a47a12beSStefan Roese #define ft_fixup_l3cache(x, y) 1636aba33e9SKumar Gala #endif 164a47a12beSStefan Roese 165a47a12beSStefan Roese #if defined(CONFIG_L2_CACHE) 166a47a12beSStefan Roese /* return size in kilobytes */ 167a47a12beSStefan Roese static inline u32 l2cache_size(void) 168a47a12beSStefan Roese { 169a47a12beSStefan Roese volatile ccsr_l2cache_t *l2cache = (void *)CONFIG_SYS_MPC85xx_L2_ADDR; 170a47a12beSStefan Roese volatile u32 l2siz_field = (l2cache->l2ctl >> 28) & 0x3; 171a47a12beSStefan Roese u32 ver = SVR_SOC_VER(get_svr()); 172a47a12beSStefan Roese 173a47a12beSStefan Roese switch (l2siz_field) { 174a47a12beSStefan Roese case 0x0: 175a47a12beSStefan Roese break; 176a47a12beSStefan Roese case 0x1: 177a47a12beSStefan Roese if (ver == SVR_8540 || ver == SVR_8560 || 17848f6a5c3SYork Sun ver == SVR_8541 || ver == SVR_8555) 179a47a12beSStefan Roese return 128; 180a47a12beSStefan Roese else 181a47a12beSStefan Roese return 256; 182a47a12beSStefan Roese break; 183a47a12beSStefan Roese case 0x2: 184a47a12beSStefan Roese if (ver == SVR_8540 || ver == SVR_8560 || 18548f6a5c3SYork Sun ver == SVR_8541 || ver == SVR_8555) 186a47a12beSStefan Roese return 256; 187a47a12beSStefan Roese else 188a47a12beSStefan Roese return 512; 189a47a12beSStefan Roese break; 190a47a12beSStefan Roese case 0x3: 191a47a12beSStefan Roese return 1024; 192a47a12beSStefan Roese break; 193a47a12beSStefan Roese } 194a47a12beSStefan Roese 195a47a12beSStefan Roese return 0; 196a47a12beSStefan Roese } 197a47a12beSStefan Roese 198a47a12beSStefan Roese static inline void ft_fixup_l2cache(void *blob) 199a47a12beSStefan Roese { 200a47a12beSStefan Roese int len, off; 201a47a12beSStefan Roese u32 *ph; 202a47a12beSStefan Roese struct cpu_type *cpu = identify_cpu(SVR_SOC_VER(get_svr())); 203a47a12beSStefan Roese 204a47a12beSStefan Roese const u32 line_size = 32; 205a47a12beSStefan Roese const u32 num_ways = 8; 206a47a12beSStefan Roese const u32 size = l2cache_size() * 1024; 207a47a12beSStefan Roese const u32 num_sets = size / (line_size * num_ways); 208a47a12beSStefan Roese 209a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 210a47a12beSStefan Roese if (off < 0) { 211a47a12beSStefan Roese debug("no cpu node fount\n"); 212a47a12beSStefan Roese return; 213a47a12beSStefan Roese } 214a47a12beSStefan Roese 215a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0); 216a47a12beSStefan Roese 217a47a12beSStefan Roese if (ph == NULL) { 218a47a12beSStefan Roese debug("no next-level-cache property\n"); 219a47a12beSStefan Roese return ; 220a47a12beSStefan Roese } 221a47a12beSStefan Roese 222a47a12beSStefan Roese off = fdt_node_offset_by_phandle(blob, *ph); 223a47a12beSStefan Roese if (off < 0) { 224a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off)); 225a47a12beSStefan Roese return ; 226a47a12beSStefan Roese } 227a47a12beSStefan Roese 228a47a12beSStefan Roese if (cpu) { 229ee4756d4STimur Tabi char buf[40]; 230a47a12beSStefan Roese 231ee4756d4STimur Tabi if (isdigit(cpu->name[0])) { 232ee4756d4STimur Tabi /* MPCxxxx, where xxxx == 4-digit number */ 233ee4756d4STimur Tabi len = sprintf(buf, "fsl,mpc%s-l2-cache-controller", 234ee4756d4STimur Tabi cpu->name) + 1; 235ee4756d4STimur Tabi } else { 236ee4756d4STimur Tabi /* Pxxxx or Txxxx, where xxxx == 4-digit number */ 237ee4756d4STimur Tabi len = sprintf(buf, "fsl,%c%s-l2-cache-controller", 238ee4756d4STimur Tabi tolower(cpu->name[0]), cpu->name + 1) + 1; 239ee4756d4STimur Tabi } 240ee4756d4STimur Tabi 241ee4756d4STimur Tabi /* 242ee4756d4STimur Tabi * append "cache" after the NULL character that the previous 243ee4756d4STimur Tabi * sprintf wrote. This is how a device tree stores multiple 244ee4756d4STimur Tabi * strings in a property. 245ee4756d4STimur Tabi */ 246ee4756d4STimur Tabi len += sprintf(buf + len, "cache") + 1; 247ee4756d4STimur Tabi 248ee4756d4STimur Tabi fdt_setprop(blob, off, "compatible", buf, len); 249a47a12beSStefan Roese } 250a47a12beSStefan Roese fdt_setprop(blob, off, "cache-unified", NULL, 0); 251a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-block-size", line_size); 252a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-size", size); 253a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-sets", num_sets); 254a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-level", 2); 255a47a12beSStefan Roese 256a47a12beSStefan Roese /* we dont bother w/L3 since no platform of this type has one */ 257a47a12beSStefan Roese } 2586d2b9da1SYork Sun #elif defined(CONFIG_BACKSIDE_L2_CACHE) || \ 2596d2b9da1SYork Sun defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) 260a47a12beSStefan Roese static inline void ft_fixup_l2cache(void *blob) 261a47a12beSStefan Roese { 262a47a12beSStefan Roese int off, l2_off, l3_off = -1; 263a47a12beSStefan Roese u32 *ph; 2646d2b9da1SYork Sun #ifdef CONFIG_BACKSIDE_L2_CACHE 265a47a12beSStefan Roese u32 l2cfg0 = mfspr(SPRN_L2CFG0); 2666d2b9da1SYork Sun #else 2676d2b9da1SYork Sun struct ccsr_cluster_l2 *l2cache = 2686d2b9da1SYork Sun (struct ccsr_cluster_l2 __iomem *)(CONFIG_SYS_FSL_CLUSTER_1_L2); 2696d2b9da1SYork Sun u32 l2cfg0 = in_be32(&l2cache->l2cfg0); 2706d2b9da1SYork Sun #endif 271a47a12beSStefan Roese u32 size, line_size, num_ways, num_sets; 272acf3f8daSKumar Gala int has_l2 = 1; 273acf3f8daSKumar Gala 274acf3f8daSKumar Gala /* P2040/P2040E has no L2, so dont set any L2 props */ 27548f6a5c3SYork Sun if (SVR_SOC_VER(get_svr()) == SVR_P2040) 276acf3f8daSKumar Gala has_l2 = 0; 277a47a12beSStefan Roese 278a47a12beSStefan Roese size = (l2cfg0 & 0x3fff) * 64 * 1024; 279a47a12beSStefan Roese num_ways = ((l2cfg0 >> 14) & 0x1f) + 1; 280a47a12beSStefan Roese line_size = (((l2cfg0 >> 23) & 0x3) + 1) * 32; 281a47a12beSStefan Roese num_sets = size / (line_size * num_ways); 282a47a12beSStefan Roese 283a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 284a47a12beSStefan Roese 285a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 286a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0); 287a47a12beSStefan Roese 288a47a12beSStefan Roese if (ph == NULL) { 289a47a12beSStefan Roese debug("no next-level-cache property\n"); 290a47a12beSStefan Roese goto next; 291a47a12beSStefan Roese } 292a47a12beSStefan Roese 293a47a12beSStefan Roese l2_off = fdt_node_offset_by_phandle(blob, *ph); 294a47a12beSStefan Roese if (l2_off < 0) { 295a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off)); 296a47a12beSStefan Roese goto next; 297a47a12beSStefan Roese } 298a47a12beSStefan Roese 299acf3f8daSKumar Gala if (has_l2) { 300a47a12beSStefan Roese #ifdef CONFIG_SYS_CACHE_STASHING 301a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 302e9827468SPrabhakar Kushwaha #if defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500) 3036d2b9da1SYork Sun /* Only initialize every eighth thread */ 3048d451a71SScott Wood if (reg && !((*reg) % 8)) { 3058d451a71SScott Wood fdt_setprop_cell(blob, l2_off, "cache-stash-id", 3068d451a71SScott Wood (*reg / 4) + 32 + 1); 3078d451a71SScott Wood } 3086d2b9da1SYork Sun #else 3098d451a71SScott Wood if (reg) { 310a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-stash-id", 311a47a12beSStefan Roese (*reg * 2) + 32 + 1); 3128d451a71SScott Wood } 3138d451a71SScott Wood #endif 314a47a12beSStefan Roese #endif 315a47a12beSStefan Roese 316a47a12beSStefan Roese fdt_setprop(blob, l2_off, "cache-unified", NULL, 0); 317acf3f8daSKumar Gala fdt_setprop_cell(blob, l2_off, "cache-block-size", 318acf3f8daSKumar Gala line_size); 319a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-size", size); 320a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-sets", num_sets); 321a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-level", 2); 322a47a12beSStefan Roese fdt_setprop(blob, l2_off, "compatible", "cache", 6); 323acf3f8daSKumar Gala } 324a47a12beSStefan Roese 325a47a12beSStefan Roese if (l3_off < 0) { 326a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, l2_off, "next-level-cache", 0); 327a47a12beSStefan Roese 328a47a12beSStefan Roese if (ph == NULL) { 329a47a12beSStefan Roese debug("no next-level-cache property\n"); 330a47a12beSStefan Roese goto next; 331a47a12beSStefan Roese } 332a47a12beSStefan Roese l3_off = *ph; 333a47a12beSStefan Roese } 334a47a12beSStefan Roese next: 335a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, 336a47a12beSStefan Roese "device_type", "cpu", 4); 337a47a12beSStefan Roese } 338a47a12beSStefan Roese if (l3_off > 0) { 339a47a12beSStefan Roese l3_off = fdt_node_offset_by_phandle(blob, l3_off); 340a47a12beSStefan Roese if (l3_off < 0) { 341a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off)); 342a47a12beSStefan Roese return ; 343a47a12beSStefan Roese } 344a47a12beSStefan Roese ft_fixup_l3cache(blob, l3_off); 345a47a12beSStefan Roese } 346a47a12beSStefan Roese } 347a47a12beSStefan Roese #else 348a47a12beSStefan Roese #define ft_fixup_l2cache(x) 349a47a12beSStefan Roese #endif 350a47a12beSStefan Roese 351a47a12beSStefan Roese static inline void ft_fixup_cache(void *blob) 352a47a12beSStefan Roese { 353a47a12beSStefan Roese int off; 354a47a12beSStefan Roese 355a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 356a47a12beSStefan Roese 357a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 358a47a12beSStefan Roese u32 l1cfg0 = mfspr(SPRN_L1CFG0); 359a47a12beSStefan Roese u32 l1cfg1 = mfspr(SPRN_L1CFG1); 360a47a12beSStefan Roese u32 isize, iline_size, inum_sets, inum_ways; 361a47a12beSStefan Roese u32 dsize, dline_size, dnum_sets, dnum_ways; 362a47a12beSStefan Roese 363a47a12beSStefan Roese /* d-side config */ 364a47a12beSStefan Roese dsize = (l1cfg0 & 0x7ff) * 1024; 365a47a12beSStefan Roese dnum_ways = ((l1cfg0 >> 11) & 0xff) + 1; 366a47a12beSStefan Roese dline_size = (((l1cfg0 >> 23) & 0x3) + 1) * 32; 367a47a12beSStefan Roese dnum_sets = dsize / (dline_size * dnum_ways); 368a47a12beSStefan Roese 369a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-block-size", dline_size); 370a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-size", dsize); 371a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-sets", dnum_sets); 372a47a12beSStefan Roese 373a47a12beSStefan Roese #ifdef CONFIG_SYS_CACHE_STASHING 374a47a12beSStefan Roese { 375a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 376a47a12beSStefan Roese if (reg) 377a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-stash-id", 378a47a12beSStefan Roese (*reg * 2) + 32 + 0); 379a47a12beSStefan Roese } 380a47a12beSStefan Roese #endif 381a47a12beSStefan Roese 382a47a12beSStefan Roese /* i-side config */ 383a47a12beSStefan Roese isize = (l1cfg1 & 0x7ff) * 1024; 384a47a12beSStefan Roese inum_ways = ((l1cfg1 >> 11) & 0xff) + 1; 385a47a12beSStefan Roese iline_size = (((l1cfg1 >> 23) & 0x3) + 1) * 32; 386a47a12beSStefan Roese inum_sets = isize / (iline_size * inum_ways); 387a47a12beSStefan Roese 388a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-block-size", iline_size); 389a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-size", isize); 390a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-sets", inum_sets); 391a47a12beSStefan Roese 392a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, 393a47a12beSStefan Roese "device_type", "cpu", 4); 394a47a12beSStefan Roese } 395a47a12beSStefan Roese 396a47a12beSStefan Roese ft_fixup_l2cache(blob); 397a47a12beSStefan Roese } 398a47a12beSStefan Roese 399a47a12beSStefan Roese 400a47a12beSStefan Roese void fdt_add_enet_stashing(void *fdt) 401a47a12beSStefan Roese { 402a47a12beSStefan Roese do_fixup_by_compat(fdt, "gianfar", "bd-stash", NULL, 0, 1); 403a47a12beSStefan Roese 404a47a12beSStefan Roese do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-len", 96, 1); 405a47a12beSStefan Roese 406a47a12beSStefan Roese do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-idx", 0, 1); 407eea9a123SPankaj Chauhan do_fixup_by_compat(fdt, "fsl,etsec2", "bd-stash", NULL, 0, 1); 408eea9a123SPankaj Chauhan do_fixup_by_compat_u32(fdt, "fsl,etsec2", "rx-stash-len", 96, 1); 409eea9a123SPankaj Chauhan do_fixup_by_compat_u32(fdt, "fsl,etsec2", "rx-stash-idx", 0, 1); 410a47a12beSStefan Roese } 411a47a12beSStefan Roese 412a47a12beSStefan Roese #if defined(CONFIG_SYS_DPAA_FMAN) || defined(CONFIG_SYS_DPAA_PME) 413e2d0f255SKumar Gala #ifdef CONFIG_SYS_DPAA_FMAN 4141b942f74SKumar Gala static void ft_fixup_clks(void *blob, const char *compat, u32 offset, 4151b942f74SKumar Gala unsigned long freq) 416a47a12beSStefan Roese { 4171b942f74SKumar Gala phys_addr_t phys = offset + CONFIG_SYS_CCSRBAR_PHYS; 4181b942f74SKumar Gala int off = fdt_node_offset_by_compat_reg(blob, compat, phys); 419a47a12beSStefan Roese 420a47a12beSStefan Roese if (off >= 0) { 421a47a12beSStefan Roese off = fdt_setprop_cell(blob, off, "clock-frequency", freq); 422a47a12beSStefan Roese if (off > 0) 423a47a12beSStefan Roese printf("WARNING enable to set clock-frequency " 4241b942f74SKumar Gala "for %s: %s\n", compat, fdt_strerror(off)); 425a47a12beSStefan Roese } 426a47a12beSStefan Roese } 427e2d0f255SKumar Gala #endif 428a47a12beSStefan Roese 429a47a12beSStefan Roese static void ft_fixup_dpaa_clks(void *blob) 430a47a12beSStefan Roese { 431a47a12beSStefan Roese sys_info_t sysinfo; 432a47a12beSStefan Roese 433a47a12beSStefan Roese get_sys_info(&sysinfo); 434e2d0f255SKumar Gala #ifdef CONFIG_SYS_DPAA_FMAN 4351b942f74SKumar Gala ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM1_OFFSET, 436997399faSPrabhakar Kushwaha sysinfo.freq_fman[0]); 437a47a12beSStefan Roese 438a47a12beSStefan Roese #if (CONFIG_SYS_NUM_FMAN == 2) 4391b942f74SKumar Gala ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM2_OFFSET, 440997399faSPrabhakar Kushwaha sysinfo.freq_fman[1]); 441a47a12beSStefan Roese #endif 442e2d0f255SKumar Gala #endif 443a47a12beSStefan Roese 444990e1a8cSHaiying Wang #ifdef CONFIG_SYS_DPAA_QBMAN 445990e1a8cSHaiying Wang do_fixup_by_compat_u32(blob, "fsl,qman", 446997399faSPrabhakar Kushwaha "clock-frequency", sysinfo.freq_qman, 1); 447990e1a8cSHaiying Wang #endif 448990e1a8cSHaiying Wang 449a47a12beSStefan Roese #ifdef CONFIG_SYS_DPAA_PME 4501b942f74SKumar Gala do_fixup_by_compat_u32(blob, "fsl,pme", 451997399faSPrabhakar Kushwaha "clock-frequency", sysinfo.freq_pme, 1); 452a47a12beSStefan Roese #endif 453a47a12beSStefan Roese } 454a47a12beSStefan Roese #else 455a47a12beSStefan Roese #define ft_fixup_dpaa_clks(x) 456a47a12beSStefan Roese #endif 457a47a12beSStefan Roese 458a47a12beSStefan Roese #ifdef CONFIG_QE 459a47a12beSStefan Roese static void ft_fixup_qe_snum(void *blob) 460a47a12beSStefan Roese { 461a47a12beSStefan Roese unsigned int svr; 462a47a12beSStefan Roese 463a47a12beSStefan Roese svr = mfspr(SPRN_SVR); 46448f6a5c3SYork Sun if (SVR_SOC_VER(svr) == SVR_8569) { 465a47a12beSStefan Roese if(IS_SVR_REV(svr, 1, 0)) 466a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,qe", 467a47a12beSStefan Roese "fsl,qe-num-snums", 46, 1); 468a47a12beSStefan Roese else 469a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,qe", 470a47a12beSStefan Roese "fsl,qe-num-snums", 76, 1); 471a47a12beSStefan Roese } 472a47a12beSStefan Roese } 473a47a12beSStefan Roese #endif 474a47a12beSStefan Roese 475ffadc441STimur Tabi /** 476ffadc441STimur Tabi * fdt_fixup_fman_firmware -- insert the Fman firmware into the device tree 477ffadc441STimur Tabi * 478ffadc441STimur Tabi * The binding for an Fman firmware node is documented in 479ffadc441STimur Tabi * Documentation/powerpc/dts-bindings/fsl/dpaa/fman.txt. This node contains 480ffadc441STimur Tabi * the actual Fman firmware binary data. The operating system is expected to 481ffadc441STimur Tabi * be able to parse the binary data to determine any attributes it needs. 482ffadc441STimur Tabi */ 483ffadc441STimur Tabi #ifdef CONFIG_SYS_DPAA_FMAN 484ffadc441STimur Tabi void fdt_fixup_fman_firmware(void *blob) 485ffadc441STimur Tabi { 486ffadc441STimur Tabi int rc, fmnode, fwnode = -1; 487ffadc441STimur Tabi uint32_t phandle; 488ffadc441STimur Tabi struct qe_firmware *fmanfw; 489ffadc441STimur Tabi const struct qe_header *hdr; 490ffadc441STimur Tabi unsigned int length; 491ffadc441STimur Tabi uint32_t crc; 492ffadc441STimur Tabi const char *p; 493ffadc441STimur Tabi 494ffadc441STimur Tabi /* The first Fman we find will contain the actual firmware. */ 495ffadc441STimur Tabi fmnode = fdt_node_offset_by_compatible(blob, -1, "fsl,fman"); 496ffadc441STimur Tabi if (fmnode < 0) 497ffadc441STimur Tabi /* Exit silently if there are no Fman devices */ 498ffadc441STimur Tabi return; 499ffadc441STimur Tabi 500ffadc441STimur Tabi /* If we already have a firmware node, then also exit silently. */ 501ffadc441STimur Tabi if (fdt_node_offset_by_compatible(blob, -1, "fsl,fman-firmware") > 0) 502ffadc441STimur Tabi return; 503ffadc441STimur Tabi 504ffadc441STimur Tabi /* If the environment variable is not set, then exit silently */ 505ffadc441STimur Tabi p = getenv("fman_ucode"); 506ffadc441STimur Tabi if (!p) 507ffadc441STimur Tabi return; 508ffadc441STimur Tabi 509e6394e9eSНиколай Пузанов fmanfw = (struct qe_firmware *) simple_strtoul(p, NULL, 16); 510ffadc441STimur Tabi if (!fmanfw) 511ffadc441STimur Tabi return; 512ffadc441STimur Tabi 513ffadc441STimur Tabi hdr = &fmanfw->header; 514ffadc441STimur Tabi length = be32_to_cpu(hdr->length); 515ffadc441STimur Tabi 516ffadc441STimur Tabi /* Verify the firmware. */ 517ffadc441STimur Tabi if ((hdr->magic[0] != 'Q') || (hdr->magic[1] != 'E') || 518ffadc441STimur Tabi (hdr->magic[2] != 'F')) { 519ffadc441STimur Tabi printf("Data at %p is not an Fman firmware\n", fmanfw); 520ffadc441STimur Tabi return; 521ffadc441STimur Tabi } 522ffadc441STimur Tabi 523f2717b47STimur Tabi if (length > CONFIG_SYS_QE_FMAN_FW_LENGTH) { 524ffadc441STimur Tabi printf("Fman firmware at %p is too large (size=%u)\n", 525ffadc441STimur Tabi fmanfw, length); 526ffadc441STimur Tabi return; 527ffadc441STimur Tabi } 528ffadc441STimur Tabi 529ffadc441STimur Tabi length -= sizeof(u32); /* Subtract the size of the CRC */ 530ffadc441STimur Tabi crc = be32_to_cpu(*(u32 *)((void *)fmanfw + length)); 531ffadc441STimur Tabi if (crc != crc32_no_comp(0, (void *)fmanfw, length)) { 532ffadc441STimur Tabi printf("Fman firmware at %p has invalid CRC\n", fmanfw); 533ffadc441STimur Tabi return; 534ffadc441STimur Tabi } 535ffadc441STimur Tabi 536ffadc441STimur Tabi /* Increase the size of the fdt to make room for the node. */ 537ffadc441STimur Tabi rc = fdt_increase_size(blob, fmanfw->header.length); 538ffadc441STimur Tabi if (rc < 0) { 539ffadc441STimur Tabi printf("Unable to make room for Fman firmware: %s\n", 540ffadc441STimur Tabi fdt_strerror(rc)); 541ffadc441STimur Tabi return; 542ffadc441STimur Tabi } 543ffadc441STimur Tabi 544ffadc441STimur Tabi /* Create the firmware node. */ 545ffadc441STimur Tabi fwnode = fdt_add_subnode(blob, fmnode, "fman-firmware"); 546ffadc441STimur Tabi if (fwnode < 0) { 547ffadc441STimur Tabi char s[64]; 548ffadc441STimur Tabi fdt_get_path(blob, fmnode, s, sizeof(s)); 549ffadc441STimur Tabi printf("Could not add firmware node to %s: %s\n", s, 550ffadc441STimur Tabi fdt_strerror(fwnode)); 551ffadc441STimur Tabi return; 552ffadc441STimur Tabi } 553ffadc441STimur Tabi rc = fdt_setprop_string(blob, fwnode, "compatible", "fsl,fman-firmware"); 554ffadc441STimur Tabi if (rc < 0) { 555ffadc441STimur Tabi char s[64]; 556ffadc441STimur Tabi fdt_get_path(blob, fwnode, s, sizeof(s)); 557ffadc441STimur Tabi printf("Could not add compatible property to node %s: %s\n", s, 558ffadc441STimur Tabi fdt_strerror(rc)); 559ffadc441STimur Tabi return; 560ffadc441STimur Tabi } 561a2c1229cSTimur Tabi phandle = fdt_create_phandle(blob, fwnode); 562a2c1229cSTimur Tabi if (!phandle) { 563ffadc441STimur Tabi char s[64]; 564ffadc441STimur Tabi fdt_get_path(blob, fwnode, s, sizeof(s)); 565ffadc441STimur Tabi printf("Could not add phandle property to node %s: %s\n", s, 566ffadc441STimur Tabi fdt_strerror(rc)); 567ffadc441STimur Tabi return; 568ffadc441STimur Tabi } 569ffadc441STimur Tabi rc = fdt_setprop(blob, fwnode, "fsl,firmware", fmanfw, fmanfw->header.length); 570ffadc441STimur Tabi if (rc < 0) { 571ffadc441STimur Tabi char s[64]; 572ffadc441STimur Tabi fdt_get_path(blob, fwnode, s, sizeof(s)); 573ffadc441STimur Tabi printf("Could not add firmware property to node %s: %s\n", s, 574ffadc441STimur Tabi fdt_strerror(rc)); 575ffadc441STimur Tabi return; 576ffadc441STimur Tabi } 577ffadc441STimur Tabi 578ffadc441STimur Tabi /* Find all other Fman nodes and point them to the firmware node. */ 579ffadc441STimur Tabi while ((fmnode = fdt_node_offset_by_compatible(blob, fmnode, "fsl,fman")) > 0) { 580ffadc441STimur Tabi rc = fdt_setprop_cell(blob, fmnode, "fsl,firmware-phandle", phandle); 581ffadc441STimur Tabi if (rc < 0) { 582ffadc441STimur Tabi char s[64]; 583ffadc441STimur Tabi fdt_get_path(blob, fmnode, s, sizeof(s)); 584ffadc441STimur Tabi printf("Could not add pointer property to node %s: %s\n", 585ffadc441STimur Tabi s, fdt_strerror(rc)); 586ffadc441STimur Tabi return; 587ffadc441STimur Tabi } 588ffadc441STimur Tabi } 589ffadc441STimur Tabi } 590ffadc441STimur Tabi #else 591ffadc441STimur Tabi #define fdt_fixup_fman_firmware(x) 592ffadc441STimur Tabi #endif 593ffadc441STimur Tabi 594055ce080STimur Tabi #if defined(CONFIG_PPC_P4080) 595f81f19faSShengzhou Liu static void fdt_fixup_usb(void *fdt) 596f81f19faSShengzhou Liu { 597f81f19faSShengzhou Liu ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 598f81f19faSShengzhou Liu u32 rcwsr11 = in_be32(&gur->rcwsr[11]); 599f81f19faSShengzhou Liu int off; 600f81f19faSShengzhou Liu 601f81f19faSShengzhou Liu off = fdt_node_offset_by_compatible(fdt, -1, "fsl,mpc85xx-usb2-mph"); 602f81f19faSShengzhou Liu if ((rcwsr11 & FSL_CORENET_RCWSR11_EC1) != 603f81f19faSShengzhou Liu FSL_CORENET_RCWSR11_EC1_FM1_USB1) 604f81f19faSShengzhou Liu fdt_status_disabled(fdt, off); 605f81f19faSShengzhou Liu 606f81f19faSShengzhou Liu off = fdt_node_offset_by_compatible(fdt, -1, "fsl,mpc85xx-usb2-dr"); 607f81f19faSShengzhou Liu if ((rcwsr11 & FSL_CORENET_RCWSR11_EC2) != 608f81f19faSShengzhou Liu FSL_CORENET_RCWSR11_EC2_USB2) 609f81f19faSShengzhou Liu fdt_status_disabled(fdt, off); 610f81f19faSShengzhou Liu } 611f81f19faSShengzhou Liu #else 612f81f19faSShengzhou Liu #define fdt_fixup_usb(x) 613f81f19faSShengzhou Liu #endif 614f81f19faSShengzhou Liu 615d616fc58SCodrin Ciubotariu #if defined(CONFIG_PPC_T1040) 616d616fc58SCodrin Ciubotariu static void fdt_fixup_l2_switch(void *blob) 617d616fc58SCodrin Ciubotariu { 618d616fc58SCodrin Ciubotariu uchar l2swaddr[6]; 619d616fc58SCodrin Ciubotariu int node; 620d616fc58SCodrin Ciubotariu 621d616fc58SCodrin Ciubotariu /* The l2switch node from device-tree has 622d616fc58SCodrin Ciubotariu * compatible string "vitesse-9953" */ 623d616fc58SCodrin Ciubotariu node = fdt_node_offset_by_compatible(blob, -1, "vitesse-9953"); 624d616fc58SCodrin Ciubotariu if (node == -FDT_ERR_NOTFOUND) 625d616fc58SCodrin Ciubotariu /* no l2switch node has been found */ 626d616fc58SCodrin Ciubotariu return; 627d616fc58SCodrin Ciubotariu 628d616fc58SCodrin Ciubotariu /* Get MAC address for the l2switch from "l2switchaddr"*/ 629d616fc58SCodrin Ciubotariu if (!eth_getenv_enetaddr("l2switchaddr", l2swaddr)) { 630d616fc58SCodrin Ciubotariu printf("Warning: MAC address for l2switch not found\n"); 631d616fc58SCodrin Ciubotariu memset(l2swaddr, 0, sizeof(l2swaddr)); 632d616fc58SCodrin Ciubotariu } 633d616fc58SCodrin Ciubotariu 634d616fc58SCodrin Ciubotariu /* Add MAC address to l2switch node */ 635d616fc58SCodrin Ciubotariu fdt_setprop(blob, node, "local-mac-address", l2swaddr, 636d616fc58SCodrin Ciubotariu sizeof(l2swaddr)); 637d616fc58SCodrin Ciubotariu } 638d616fc58SCodrin Ciubotariu #else 639d616fc58SCodrin Ciubotariu #define fdt_fixup_l2_switch(x) 640d616fc58SCodrin Ciubotariu #endif 641d616fc58SCodrin Ciubotariu 642a47a12beSStefan Roese void ft_cpu_setup(void *blob, bd_t *bd) 643a47a12beSStefan Roese { 644a47a12beSStefan Roese int off; 645a47a12beSStefan Roese int val; 64651abee64SLaurentiu TUDOR int len; 647a47a12beSStefan Roese sys_info_t sysinfo; 648a47a12beSStefan Roese 649a47a12beSStefan Roese /* delete crypto node if not on an E-processor */ 650a47a12beSStefan Roese if (!IS_E_PROCESSOR(get_svr())) 651a47a12beSStefan Roese fdt_fixup_crypto_node(blob, 0); 6525e95e2d8SVakul Garg #if CONFIG_SYS_FSL_SEC_COMPAT >= 4 6535e95e2d8SVakul Garg else { 6545e95e2d8SVakul Garg ccsr_sec_t __iomem *sec; 6555e95e2d8SVakul Garg 6565e95e2d8SVakul Garg sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR; 6575e95e2d8SVakul Garg fdt_fixup_crypto_node(blob, in_be32(&sec->secvid_ms)); 6585e95e2d8SVakul Garg } 6595e95e2d8SVakul Garg #endif 660a47a12beSStefan Roese 661a47a12beSStefan Roese fdt_fixup_ethernet(blob); 662a47a12beSStefan Roese 663a47a12beSStefan Roese fdt_add_enet_stashing(blob); 664a47a12beSStefan Roese 665cb93071bSYork Sun #ifndef CONFIG_FSL_TBCLK_EXTRA_DIV 666cb93071bSYork Sun #define CONFIG_FSL_TBCLK_EXTRA_DIV 1 667cb93071bSYork Sun #endif 668a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, 669cb93071bSYork Sun "timebase-frequency", get_tbclk() / CONFIG_FSL_TBCLK_EXTRA_DIV, 670cb93071bSYork Sun 1); 671a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, 672a47a12beSStefan Roese "bus-frequency", bd->bi_busfreq, 1); 673a47a12beSStefan Roese get_sys_info(&sysinfo); 674a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 675a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 67651abee64SLaurentiu TUDOR u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", &len); 67751abee64SLaurentiu TUDOR val = cpu_to_fdt32(sysinfo.freq_processor[(*reg) / (len / 4)]); 678a47a12beSStefan Roese fdt_setprop(blob, off, "clock-frequency", &val, 4); 679a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, "device_type", 680a47a12beSStefan Roese "cpu", 4); 681a47a12beSStefan Roese } 682a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "soc", 4, 683a47a12beSStefan Roese "bus-frequency", bd->bi_busfreq, 1); 684a47a12beSStefan Roese 685a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,pq3-localbus", 68667ac13b1SSimon Glass "bus-frequency", gd->arch.lbc_clk, 1); 687a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,elbc", 68867ac13b1SSimon Glass "bus-frequency", gd->arch.lbc_clk, 1); 689a47a12beSStefan Roese #ifdef CONFIG_QE 690a47a12beSStefan Roese ft_qe_setup(blob); 691a47a12beSStefan Roese ft_fixup_qe_snum(blob); 692a47a12beSStefan Roese #endif 693a47a12beSStefan Roese 694ffadc441STimur Tabi fdt_fixup_fman_firmware(blob); 695ffadc441STimur Tabi 696a47a12beSStefan Roese #ifdef CONFIG_SYS_NS16550 697a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "ns16550", 698a47a12beSStefan Roese "clock-frequency", CONFIG_SYS_NS16550_CLK, 1); 699a47a12beSStefan Roese #endif 700a47a12beSStefan Roese 701a47a12beSStefan Roese #ifdef CONFIG_CPM2 702a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,cpm2-scc-uart", 7038e261575SMasahiro Yamada "current-speed", gd->baudrate, 1); 704a47a12beSStefan Roese 705a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,cpm2-brg", 706a47a12beSStefan Roese "clock-frequency", bd->bi_brgfreq, 1); 707a47a12beSStefan Roese #endif 708a47a12beSStefan Roese 70985f8cda3SKumar Gala #ifdef CONFIG_FSL_CORENET 71085f8cda3SKumar Gala do_fixup_by_compat_u32(blob, "fsl,qoriq-clockgen-1.0", 71185f8cda3SKumar Gala "clock-frequency", CONFIG_SYS_CLK_FREQ, 1); 7127dd09b54SAndy Fleming do_fixup_by_compat_u32(blob, "fsl,qoriq-clockgen-2.0", 7137b700d21STang Yuantian "clock-frequency", CONFIG_SYS_CLK_FREQ, 1); 714f5c2623dSDongsheng.wang@freescale.com do_fixup_by_compat_u32(blob, "fsl,mpic", 715f5c2623dSDongsheng.wang@freescale.com "clock-frequency", get_bus_freq(0)/2, 1); 716f5c2623dSDongsheng.wang@freescale.com #else 717f5c2623dSDongsheng.wang@freescale.com do_fixup_by_compat_u32(blob, "fsl,mpic", 718f5c2623dSDongsheng.wang@freescale.com "clock-frequency", get_bus_freq(0), 1); 71985f8cda3SKumar Gala #endif 72085f8cda3SKumar Gala 721a47a12beSStefan Roese fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize); 722a47a12beSStefan Roese 723a47a12beSStefan Roese #ifdef CONFIG_MP 724a47a12beSStefan Roese ft_fixup_cpu(blob, (u64)bd->bi_memstart + (u64)bd->bi_memsize); 725a47a12beSStefan Roese ft_fixup_num_cores(blob); 7268f3a7fa4SKumar Gala #endif 727a47a12beSStefan Roese 728a47a12beSStefan Roese ft_fixup_cache(blob); 729a47a12beSStefan Roese 730a47a12beSStefan Roese #if defined(CONFIG_FSL_ESDHC) 731a47a12beSStefan Roese fdt_fixup_esdhc(blob, bd); 732a47a12beSStefan Roese #endif 733a47a12beSStefan Roese 734a47a12beSStefan Roese ft_fixup_dpaa_clks(blob); 735db977abfSKumar Gala 736db977abfSKumar Gala #if defined(CONFIG_SYS_BMAN_MEM_PHYS) 737db977abfSKumar Gala fdt_portal(blob, "fsl,bman-portal", "bman-portals", 738db977abfSKumar Gala (u64)CONFIG_SYS_BMAN_MEM_PHYS, 739db977abfSKumar Gala CONFIG_SYS_BMAN_MEM_SIZE); 7402a0ffb84SHaiying Wang fdt_fixup_bportals(blob); 741db977abfSKumar Gala #endif 742db977abfSKumar Gala 743db977abfSKumar Gala #if defined(CONFIG_SYS_QMAN_MEM_PHYS) 744db977abfSKumar Gala fdt_portal(blob, "fsl,qman-portal", "qman-portals", 745db977abfSKumar Gala (u64)CONFIG_SYS_QMAN_MEM_PHYS, 746db977abfSKumar Gala CONFIG_SYS_QMAN_MEM_SIZE); 747db977abfSKumar Gala 748db977abfSKumar Gala fdt_fixup_qportals(blob); 749db977abfSKumar Gala #endif 750a09b9b68SKumar Gala 751a09b9b68SKumar Gala #ifdef CONFIG_SYS_SRIO 752a09b9b68SKumar Gala ft_srio_setup(blob); 753a09b9b68SKumar Gala #endif 754f5feb5afSbhaskar upadhaya 755f5feb5afSbhaskar upadhaya /* 756f5feb5afSbhaskar upadhaya * system-clock = CCB clock/2 757f5feb5afSbhaskar upadhaya * Here gd->bus_clk = CCB clock 758f5feb5afSbhaskar upadhaya * We are using the system clock as 1588 Timer reference 759f5feb5afSbhaskar upadhaya * clock source select 760f5feb5afSbhaskar upadhaya */ 761f5feb5afSbhaskar upadhaya do_fixup_by_compat_u32(blob, "fsl,gianfar-ptp-timer", 762f5feb5afSbhaskar upadhaya "timer-frequency", gd->bus_clk/2, 1); 76365bb8b06SBhaskar Upadhaya 76433c87536SJia Hongtao /* 76533c87536SJia Hongtao * clock-freq should change to clock-frequency and 76633c87536SJia Hongtao * flexcan-v1.0 should change to p1010-flexcan respectively 76733c87536SJia Hongtao * in the future. 76833c87536SJia Hongtao */ 76965bb8b06SBhaskar Upadhaya do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0", 77033c87536SJia Hongtao "clock_freq", gd->bus_clk/2, 1); 77133c87536SJia Hongtao 77233c87536SJia Hongtao do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0", 77333c87536SJia Hongtao "clock-frequency", gd->bus_clk/2, 1); 77433c87536SJia Hongtao 77533c87536SJia Hongtao do_fixup_by_compat_u32(blob, "fsl,p1010-flexcan", 77633c87536SJia Hongtao "clock-frequency", gd->bus_clk/2, 1); 777f81f19faSShengzhou Liu 778f81f19faSShengzhou Liu fdt_fixup_usb(blob); 779d616fc58SCodrin Ciubotariu 780d616fc58SCodrin Ciubotariu fdt_fixup_l2_switch(blob); 781a47a12beSStefan Roese } 78290f89f09STimur Tabi 78390f89f09STimur Tabi /* 78490f89f09STimur Tabi * For some CCSR devices, we only have the virtual address, not the physical 78590f89f09STimur Tabi * address. This is because we map CCSR as a whole, so we typically don't need 78690f89f09STimur Tabi * a macro for the physical address of any device within CCSR. In this case, 78790f89f09STimur Tabi * we calculate the physical address of that device using it's the difference 78890f89f09STimur Tabi * between the virtual address of the device and the virtual address of the 78990f89f09STimur Tabi * beginning of CCSR. 79090f89f09STimur Tabi */ 79190f89f09STimur Tabi #define CCSR_VIRT_TO_PHYS(x) \ 79290f89f09STimur Tabi (CONFIG_SYS_CCSRBAR_PHYS + ((x) - CONFIG_SYS_CCSRBAR)) 79390f89f09STimur Tabi 794cc15df57STimur Tabi static void msg(const char *name, uint64_t uaddr, uint64_t daddr) 795cc15df57STimur Tabi { 796cc15df57STimur Tabi printf("Warning: U-Boot configured %s at address %llx,\n" 797cc15df57STimur Tabi "but the device tree has it at %llx\n", name, uaddr, daddr); 798cc15df57STimur Tabi } 799cc15df57STimur Tabi 80090f89f09STimur Tabi /* 80190f89f09STimur Tabi * Verify the device tree 80290f89f09STimur Tabi * 80390f89f09STimur Tabi * This function compares several CONFIG_xxx macros that contain physical 80490f89f09STimur Tabi * addresses with the corresponding nodes in the device tree, to see if 80590f89f09STimur Tabi * the physical addresses are all correct. For example, if 80690f89f09STimur Tabi * CONFIG_SYS_NS16550_COM1 is defined, then it contains the virtual address 80790f89f09STimur Tabi * of the first UART. We convert this to a physical address and compare 80890f89f09STimur Tabi * that with the physical address of the first ns16550-compatible node 80990f89f09STimur Tabi * in the device tree. If they don't match, then we display a warning. 81090f89f09STimur Tabi * 81190f89f09STimur Tabi * Returns 1 on success, 0 on failure 81290f89f09STimur Tabi */ 81390f89f09STimur Tabi int ft_verify_fdt(void *fdt) 81490f89f09STimur Tabi { 815cc15df57STimur Tabi uint64_t addr = 0; 81690f89f09STimur Tabi int aliases; 81790f89f09STimur Tabi int off; 81890f89f09STimur Tabi 81990f89f09STimur Tabi /* First check the CCSR base address */ 82090f89f09STimur Tabi off = fdt_node_offset_by_prop_value(fdt, -1, "device_type", "soc", 4); 82190f89f09STimur Tabi if (off > 0) 822cc15df57STimur Tabi addr = fdt_get_base_address(fdt, off); 82390f89f09STimur Tabi 824cc15df57STimur Tabi if (!addr) { 82590f89f09STimur Tabi printf("Warning: could not determine base CCSR address in " 82690f89f09STimur Tabi "device tree\n"); 82790f89f09STimur Tabi /* No point in checking anything else */ 82890f89f09STimur Tabi return 0; 82990f89f09STimur Tabi } 83090f89f09STimur Tabi 831cc15df57STimur Tabi if (addr != CONFIG_SYS_CCSRBAR_PHYS) { 832cc15df57STimur Tabi msg("CCSR", CONFIG_SYS_CCSRBAR_PHYS, addr); 83390f89f09STimur Tabi /* No point in checking anything else */ 83490f89f09STimur Tabi return 0; 83590f89f09STimur Tabi } 83690f89f09STimur Tabi 83790f89f09STimur Tabi /* 838cc15df57STimur Tabi * Check some nodes via aliases. We assume that U-Boot and the device 839cc15df57STimur Tabi * tree enumerate the devices equally. E.g. the first serial port in 840cc15df57STimur Tabi * U-Boot is the same as "serial0" in the device tree. 84190f89f09STimur Tabi */ 84290f89f09STimur Tabi aliases = fdt_path_offset(fdt, "/aliases"); 84390f89f09STimur Tabi if (aliases > 0) { 84490f89f09STimur Tabi #ifdef CONFIG_SYS_NS16550_COM1 84590f89f09STimur Tabi if (!fdt_verify_alias_address(fdt, aliases, "serial0", 84690f89f09STimur Tabi CCSR_VIRT_TO_PHYS(CONFIG_SYS_NS16550_COM1))) 84790f89f09STimur Tabi return 0; 84890f89f09STimur Tabi #endif 84990f89f09STimur Tabi 85090f89f09STimur Tabi #ifdef CONFIG_SYS_NS16550_COM2 85190f89f09STimur Tabi if (!fdt_verify_alias_address(fdt, aliases, "serial1", 85290f89f09STimur Tabi CCSR_VIRT_TO_PHYS(CONFIG_SYS_NS16550_COM2))) 85390f89f09STimur Tabi return 0; 85490f89f09STimur Tabi #endif 85590f89f09STimur Tabi } 85690f89f09STimur Tabi 857cc15df57STimur Tabi /* 858cc15df57STimur Tabi * The localbus node is typically a root node, even though the lbc 859cc15df57STimur Tabi * controller is part of CCSR. If we were to put the lbc node under 860cc15df57STimur Tabi * the SOC node, then the 'ranges' property in the lbc node would 861cc15df57STimur Tabi * translate through the 'ranges' property of the parent SOC node, and 862cc15df57STimur Tabi * we don't want that. Since it's a separate node, it's possible for 863cc15df57STimur Tabi * the 'reg' property to be wrong, so check it here. For now, we 864cc15df57STimur Tabi * only check for "fsl,elbc" nodes. 865cc15df57STimur Tabi */ 866cc15df57STimur Tabi #ifdef CONFIG_SYS_LBC_ADDR 867cc15df57STimur Tabi off = fdt_node_offset_by_compatible(fdt, -1, "fsl,elbc"); 868cc15df57STimur Tabi if (off > 0) { 8698aa5ec6eSKim Phillips const fdt32_t *reg = fdt_getprop(fdt, off, "reg", NULL); 870cc15df57STimur Tabi if (reg) { 871cc15df57STimur Tabi uint64_t uaddr = CCSR_VIRT_TO_PHYS(CONFIG_SYS_LBC_ADDR); 872cc15df57STimur Tabi 873cc15df57STimur Tabi addr = fdt_translate_address(fdt, off, reg); 874cc15df57STimur Tabi if (uaddr != addr) { 875cc15df57STimur Tabi msg("the localbus", uaddr, addr); 876cc15df57STimur Tabi return 0; 877cc15df57STimur Tabi } 878cc15df57STimur Tabi } 879cc15df57STimur Tabi } 880cc15df57STimur Tabi #endif 881cc15df57STimur Tabi 88290f89f09STimur Tabi return 1; 88390f89f09STimur Tabi } 884