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> 16d4683776SZhao Qiang #include <asm/fsl_fdt.h> 17db977abfSKumar Gala #include <asm/fsl_portals.h> 18377ffcfaSSandeep Singh #include <hwconfig.h> 19a47a12beSStefan Roese #ifdef CONFIG_FSL_ESDHC 20a47a12beSStefan Roese #include <fsl_esdhc.h> 21a47a12beSStefan Roese #endif 22075affb1SQianyu Gong #ifdef CONFIG_SYS_DPAA_FMAN 23075affb1SQianyu Gong #include <fsl_fman.h> 24075affb1SQianyu Gong #endif 25a47a12beSStefan Roese 26a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR; 27a47a12beSStefan Roese 28a47a12beSStefan Roese extern void ft_qe_setup(void *blob); 29a47a12beSStefan Roese extern void ft_fixup_num_cores(void *blob); 30a09b9b68SKumar Gala extern void ft_srio_setup(void *blob); 31a47a12beSStefan Roese 32a47a12beSStefan Roese #ifdef CONFIG_MP 33a47a12beSStefan Roese #include "mp.h" 34a47a12beSStefan Roese 35a47a12beSStefan Roese void ft_fixup_cpu(void *blob, u64 memory_limit) 36a47a12beSStefan Roese { 37a47a12beSStefan Roese int off; 38ffd06e02SYork Sun phys_addr_t spin_tbl_addr = get_spin_phys_addr(); 39eb539412SYork Sun u32 bootpg = determine_mp_bootpg(NULL); 40a47a12beSStefan Roese u32 id = get_my_id(); 419d64c6bbSAaron Sierra const char *enable_method; 42377ffcfaSSandeep Singh #if defined(T1040_TDM_QUIRK_CCSR_BASE) 43377ffcfaSSandeep Singh int ret; 44377ffcfaSSandeep Singh int tdm_hwconfig_enabled = 0; 45377ffcfaSSandeep Singh char buffer[HWCONFIG_BUFFER_SIZE] = {0}; 46377ffcfaSSandeep Singh #endif 47a47a12beSStefan Roese 48a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 49a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 50a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 51a47a12beSStefan Roese 52a47a12beSStefan Roese if (reg) { 53709389b6SYork Sun u32 phys_cpu_id = thread_to_core(*reg); 54709389b6SYork Sun u64 val = phys_cpu_id * SIZE_BOOT_ENTRY + spin_tbl_addr; 55709389b6SYork Sun val = cpu_to_fdt64(val); 56b80d3054SMatthew McClintock if (*reg == id) { 57b80d3054SMatthew McClintock fdt_setprop_string(blob, off, "status", 58b80d3054SMatthew McClintock "okay"); 59b80d3054SMatthew McClintock } else { 60a47a12beSStefan Roese fdt_setprop_string(blob, off, "status", 61a47a12beSStefan Roese "disabled"); 62b80d3054SMatthew McClintock } 639d64c6bbSAaron Sierra 649d64c6bbSAaron Sierra if (hold_cores_in_reset(0)) { 659d64c6bbSAaron Sierra #ifdef CONFIG_FSL_CORENET 669d64c6bbSAaron Sierra /* Cores held in reset, use BRR to release */ 679d64c6bbSAaron Sierra enable_method = "fsl,brr-holdoff"; 689d64c6bbSAaron Sierra #else 699d64c6bbSAaron Sierra /* Cores held in reset, use EEBPCR to release */ 709d64c6bbSAaron Sierra enable_method = "fsl,eebpcr-holdoff"; 719d64c6bbSAaron Sierra #endif 729d64c6bbSAaron Sierra } else { 739d64c6bbSAaron Sierra /* Cores out of reset and in a spin-loop */ 749d64c6bbSAaron Sierra enable_method = "spin-table"; 759d64c6bbSAaron Sierra 76a47a12beSStefan Roese fdt_setprop(blob, off, "cpu-release-addr", 77a47a12beSStefan Roese &val, sizeof(val)); 789d64c6bbSAaron Sierra } 799d64c6bbSAaron Sierra 809d64c6bbSAaron Sierra fdt_setprop_string(blob, off, "enable-method", 819d64c6bbSAaron Sierra enable_method); 82a47a12beSStefan Roese } else { 83a47a12beSStefan Roese printf ("cpu NULL\n"); 84a47a12beSStefan Roese } 85a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, 86a47a12beSStefan Roese "device_type", "cpu", 4); 87a47a12beSStefan Roese } 88a47a12beSStefan Roese 89377ffcfaSSandeep Singh #if defined(T1040_TDM_QUIRK_CCSR_BASE) 90377ffcfaSSandeep Singh #define CONFIG_MEM_HOLE_16M 0x1000000 91377ffcfaSSandeep Singh /* 92377ffcfaSSandeep Singh * Extract hwconfig from environment. 93377ffcfaSSandeep Singh * Search for tdm entry in hwconfig. 94377ffcfaSSandeep Singh */ 95377ffcfaSSandeep Singh ret = getenv_f("hwconfig", buffer, sizeof(buffer)); 96377ffcfaSSandeep Singh if (ret > 0) 97377ffcfaSSandeep Singh tdm_hwconfig_enabled = hwconfig_f("tdm", buffer); 98377ffcfaSSandeep Singh 99377ffcfaSSandeep Singh /* Reserve the memory hole created by TDM LAW, so OSes dont use it */ 100377ffcfaSSandeep Singh if (tdm_hwconfig_enabled) { 101377ffcfaSSandeep Singh off = fdt_add_mem_rsv(blob, T1040_TDM_QUIRK_CCSR_BASE, 102377ffcfaSSandeep Singh CONFIG_MEM_HOLE_16M); 103377ffcfaSSandeep Singh if (off < 0) 104377ffcfaSSandeep Singh printf("Failed to reserve memory for tdm: %s\n", 105377ffcfaSSandeep Singh fdt_strerror(off)); 106377ffcfaSSandeep Singh } 107377ffcfaSSandeep Singh #endif 108377ffcfaSSandeep Singh 109a47a12beSStefan Roese /* Reserve the boot page so OSes dont use it */ 110a47a12beSStefan Roese if ((u64)bootpg < memory_limit) { 111a47a12beSStefan Roese off = fdt_add_mem_rsv(blob, bootpg, (u64)4096); 112a47a12beSStefan Roese if (off < 0) 113ffd06e02SYork Sun printf("Failed to reserve memory for bootpg: %s\n", 114ffd06e02SYork Sun fdt_strerror(off)); 115ffd06e02SYork Sun } 1162d9f26b6SYork Sun 1172d9f26b6SYork Sun #ifndef CONFIG_MPC8xxx_DISABLE_BPTR 1182d9f26b6SYork Sun /* 1192d9f26b6SYork Sun * Reserve the default boot page so OSes dont use it. 1202d9f26b6SYork Sun * The default boot page is always mapped to bootpg above using 1212d9f26b6SYork Sun * boot page translation. 1222d9f26b6SYork Sun */ 1232d9f26b6SYork Sun if (0xfffff000ull < memory_limit) { 1242d9f26b6SYork Sun off = fdt_add_mem_rsv(blob, 0xfffff000ull, (u64)4096); 1252d9f26b6SYork Sun if (off < 0) { 1262d9f26b6SYork Sun printf("Failed to reserve memory for 0xfffff000: %s\n", 1272d9f26b6SYork Sun fdt_strerror(off)); 1282d9f26b6SYork Sun } 1292d9f26b6SYork Sun } 1302d9f26b6SYork Sun #endif 1312d9f26b6SYork Sun 132ffd06e02SYork Sun /* Reserve spin table page */ 133ffd06e02SYork Sun if (spin_tbl_addr < memory_limit) { 134ffd06e02SYork Sun off = fdt_add_mem_rsv(blob, 135ffd06e02SYork Sun (spin_tbl_addr & ~0xffful), 4096); 136ffd06e02SYork Sun if (off < 0) 137ffd06e02SYork Sun printf("Failed to reserve memory for spin table: %s\n", 138ffd06e02SYork Sun fdt_strerror(off)); 139a47a12beSStefan Roese } 140ce249d95STang Yuantian #ifdef CONFIG_DEEP_SLEEP 141ce249d95STang Yuantian #ifdef CONFIG_SPL_MMC_BOOT 142ce249d95STang Yuantian off = fdt_add_mem_rsv(blob, CONFIG_SYS_MMC_U_BOOT_START, 143ce249d95STang Yuantian CONFIG_SYS_MMC_U_BOOT_SIZE); 144ce249d95STang Yuantian if (off < 0) 145ce249d95STang Yuantian printf("Failed to reserve memory for SD deep sleep: %s\n", 146ce249d95STang Yuantian fdt_strerror(off)); 147ce249d95STang Yuantian #elif defined(CONFIG_SPL_SPI_BOOT) 148ce249d95STang Yuantian off = fdt_add_mem_rsv(blob, CONFIG_SYS_SPI_FLASH_U_BOOT_START, 149ce249d95STang Yuantian CONFIG_SYS_SPI_FLASH_U_BOOT_SIZE); 150ce249d95STang Yuantian if (off < 0) 151ce249d95STang Yuantian printf("Failed to reserve memory for SPI deep sleep: %s\n", 152ce249d95STang Yuantian fdt_strerror(off)); 153ce249d95STang Yuantian #endif 154ce249d95STang Yuantian #endif 155a47a12beSStefan Roese } 156a47a12beSStefan Roese #endif 157a47a12beSStefan Roese 1586aba33e9SKumar Gala #ifdef CONFIG_SYS_FSL_CPC 1596aba33e9SKumar Gala static inline void ft_fixup_l3cache(void *blob, int off) 1606aba33e9SKumar Gala { 1616aba33e9SKumar Gala u32 line_size, num_ways, size, num_sets; 1626aba33e9SKumar Gala cpc_corenet_t *cpc = (void *)CONFIG_SYS_FSL_CPC_ADDR; 1636aba33e9SKumar Gala u32 cfg0 = in_be32(&cpc->cpccfg0); 1646aba33e9SKumar Gala 1656aba33e9SKumar Gala size = CPC_CFG0_SZ_K(cfg0) * 1024 * CONFIG_SYS_NUM_CPC; 1666aba33e9SKumar Gala num_ways = CPC_CFG0_NUM_WAYS(cfg0); 1676aba33e9SKumar Gala line_size = CPC_CFG0_LINE_SZ(cfg0); 1686aba33e9SKumar Gala num_sets = size / (line_size * num_ways); 1696aba33e9SKumar Gala 1706aba33e9SKumar Gala fdt_setprop(blob, off, "cache-unified", NULL, 0); 1716aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-block-size", line_size); 1726aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-size", size); 1736aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-sets", num_sets); 1746aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-level", 3); 1756aba33e9SKumar Gala #ifdef CONFIG_SYS_CACHE_STASHING 1766aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-stash-id", 1); 1776aba33e9SKumar Gala #endif 1786aba33e9SKumar Gala } 1796aba33e9SKumar Gala #else 180a47a12beSStefan Roese #define ft_fixup_l3cache(x, y) 1816aba33e9SKumar Gala #endif 182a47a12beSStefan Roese 183*01b25d42SChris Packham #if defined(CONFIG_L2_CACHE) || \ 184*01b25d42SChris Packham defined(CONFIG_BACKSIDE_L2_CACHE) || \ 185*01b25d42SChris Packham defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) 186*01b25d42SChris Packham static inline void ft_fixup_l2cache_compatible(void *blob, int off) 187*01b25d42SChris Packham { 188*01b25d42SChris Packham int len; 189*01b25d42SChris Packham struct cpu_type *cpu = identify_cpu(SVR_SOC_VER(get_svr())); 190*01b25d42SChris Packham 191*01b25d42SChris Packham if (cpu) { 192*01b25d42SChris Packham char buf[40]; 193*01b25d42SChris Packham 194*01b25d42SChris Packham if (isdigit(cpu->name[0])) { 195*01b25d42SChris Packham /* MPCxxxx, where xxxx == 4-digit number */ 196*01b25d42SChris Packham len = sprintf(buf, "fsl,mpc%s-l2-cache-controller", 197*01b25d42SChris Packham cpu->name) + 1; 198*01b25d42SChris Packham } else { 199*01b25d42SChris Packham /* Pxxxx or Txxxx, where xxxx == 4-digit number */ 200*01b25d42SChris Packham len = sprintf(buf, "fsl,%c%s-l2-cache-controller", 201*01b25d42SChris Packham tolower(cpu->name[0]), cpu->name + 1) + 1; 202*01b25d42SChris Packham } 203*01b25d42SChris Packham 204*01b25d42SChris Packham /* 205*01b25d42SChris Packham * append "cache" after the NULL character that the previous 206*01b25d42SChris Packham * sprintf wrote. This is how a device tree stores multiple 207*01b25d42SChris Packham * strings in a property. 208*01b25d42SChris Packham */ 209*01b25d42SChris Packham len += sprintf(buf + len, "cache") + 1; 210*01b25d42SChris Packham 211*01b25d42SChris Packham fdt_setprop(blob, off, "compatible", buf, len); 212*01b25d42SChris Packham } 213*01b25d42SChris Packham } 214*01b25d42SChris Packham #endif 215*01b25d42SChris Packham 216a47a12beSStefan Roese #if defined(CONFIG_L2_CACHE) 217a47a12beSStefan Roese /* return size in kilobytes */ 218a47a12beSStefan Roese static inline u32 l2cache_size(void) 219a47a12beSStefan Roese { 220a47a12beSStefan Roese volatile ccsr_l2cache_t *l2cache = (void *)CONFIG_SYS_MPC85xx_L2_ADDR; 221a47a12beSStefan Roese volatile u32 l2siz_field = (l2cache->l2ctl >> 28) & 0x3; 222a47a12beSStefan Roese u32 ver = SVR_SOC_VER(get_svr()); 223a47a12beSStefan Roese 224a47a12beSStefan Roese switch (l2siz_field) { 225a47a12beSStefan Roese case 0x0: 226a47a12beSStefan Roese break; 227a47a12beSStefan Roese case 0x1: 228a47a12beSStefan Roese if (ver == SVR_8540 || ver == SVR_8560 || 22948f6a5c3SYork Sun ver == SVR_8541 || ver == SVR_8555) 230a47a12beSStefan Roese return 128; 231a47a12beSStefan Roese else 232a47a12beSStefan Roese return 256; 233a47a12beSStefan Roese break; 234a47a12beSStefan Roese case 0x2: 235a47a12beSStefan Roese if (ver == SVR_8540 || ver == SVR_8560 || 23648f6a5c3SYork Sun ver == SVR_8541 || ver == SVR_8555) 237a47a12beSStefan Roese return 256; 238a47a12beSStefan Roese else 239a47a12beSStefan Roese return 512; 240a47a12beSStefan Roese break; 241a47a12beSStefan Roese case 0x3: 242a47a12beSStefan Roese return 1024; 243a47a12beSStefan Roese break; 244a47a12beSStefan Roese } 245a47a12beSStefan Roese 246a47a12beSStefan Roese return 0; 247a47a12beSStefan Roese } 248a47a12beSStefan Roese 249a47a12beSStefan Roese static inline void ft_fixup_l2cache(void *blob) 250a47a12beSStefan Roese { 251*01b25d42SChris Packham int off; 252a47a12beSStefan Roese u32 *ph; 253a47a12beSStefan Roese 254a47a12beSStefan Roese const u32 line_size = 32; 255a47a12beSStefan Roese const u32 num_ways = 8; 256a47a12beSStefan Roese const u32 size = l2cache_size() * 1024; 257a47a12beSStefan Roese const u32 num_sets = size / (line_size * num_ways); 258a47a12beSStefan Roese 259a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 260a47a12beSStefan Roese if (off < 0) { 261a47a12beSStefan Roese debug("no cpu node fount\n"); 262a47a12beSStefan Roese return; 263a47a12beSStefan Roese } 264a47a12beSStefan Roese 265a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0); 266a47a12beSStefan Roese 267a47a12beSStefan Roese if (ph == NULL) { 268a47a12beSStefan Roese debug("no next-level-cache property\n"); 269a47a12beSStefan Roese return ; 270a47a12beSStefan Roese } 271a47a12beSStefan Roese 272a47a12beSStefan Roese off = fdt_node_offset_by_phandle(blob, *ph); 273a47a12beSStefan Roese if (off < 0) { 274a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off)); 275a47a12beSStefan Roese return ; 276a47a12beSStefan Roese } 277a47a12beSStefan Roese 278*01b25d42SChris Packham ft_fixup_l2cache_compatible(blob, off); 279a47a12beSStefan Roese fdt_setprop(blob, off, "cache-unified", NULL, 0); 280a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-block-size", line_size); 281a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-size", size); 282a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-sets", num_sets); 283a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-level", 2); 284a47a12beSStefan Roese 285a47a12beSStefan Roese /* we dont bother w/L3 since no platform of this type has one */ 286a47a12beSStefan Roese } 2876d2b9da1SYork Sun #elif defined(CONFIG_BACKSIDE_L2_CACHE) || \ 2886d2b9da1SYork Sun defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) 289a47a12beSStefan Roese static inline void ft_fixup_l2cache(void *blob) 290a47a12beSStefan Roese { 291a47a12beSStefan Roese int off, l2_off, l3_off = -1; 292a47a12beSStefan Roese u32 *ph; 2936d2b9da1SYork Sun #ifdef CONFIG_BACKSIDE_L2_CACHE 294a47a12beSStefan Roese u32 l2cfg0 = mfspr(SPRN_L2CFG0); 2956d2b9da1SYork Sun #else 2966d2b9da1SYork Sun struct ccsr_cluster_l2 *l2cache = 2976d2b9da1SYork Sun (struct ccsr_cluster_l2 __iomem *)(CONFIG_SYS_FSL_CLUSTER_1_L2); 2986d2b9da1SYork Sun u32 l2cfg0 = in_be32(&l2cache->l2cfg0); 2996d2b9da1SYork Sun #endif 300a47a12beSStefan Roese u32 size, line_size, num_ways, num_sets; 301acf3f8daSKumar Gala int has_l2 = 1; 302acf3f8daSKumar Gala 303acf3f8daSKumar Gala /* P2040/P2040E has no L2, so dont set any L2 props */ 30448f6a5c3SYork Sun if (SVR_SOC_VER(get_svr()) == SVR_P2040) 305acf3f8daSKumar Gala has_l2 = 0; 306a47a12beSStefan Roese 307a47a12beSStefan Roese size = (l2cfg0 & 0x3fff) * 64 * 1024; 308a47a12beSStefan Roese num_ways = ((l2cfg0 >> 14) & 0x1f) + 1; 309a47a12beSStefan Roese line_size = (((l2cfg0 >> 23) & 0x3) + 1) * 32; 310a47a12beSStefan Roese num_sets = size / (line_size * num_ways); 311a47a12beSStefan Roese 312a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 313a47a12beSStefan Roese 314a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 315a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0); 316a47a12beSStefan Roese 317a47a12beSStefan Roese if (ph == NULL) { 318a47a12beSStefan Roese debug("no next-level-cache property\n"); 319a47a12beSStefan Roese goto next; 320a47a12beSStefan Roese } 321a47a12beSStefan Roese 322a47a12beSStefan Roese l2_off = fdt_node_offset_by_phandle(blob, *ph); 323a47a12beSStefan Roese if (l2_off < 0) { 324a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off)); 325a47a12beSStefan Roese goto next; 326a47a12beSStefan Roese } 327a47a12beSStefan Roese 328acf3f8daSKumar Gala if (has_l2) { 329a47a12beSStefan Roese #ifdef CONFIG_SYS_CACHE_STASHING 330a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 331e9827468SPrabhakar Kushwaha #if defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500) 3326d2b9da1SYork Sun /* Only initialize every eighth thread */ 3338d451a71SScott Wood if (reg && !((*reg) % 8)) { 3348d451a71SScott Wood fdt_setprop_cell(blob, l2_off, "cache-stash-id", 3358d451a71SScott Wood (*reg / 4) + 32 + 1); 3368d451a71SScott Wood } 3376d2b9da1SYork Sun #else 3388d451a71SScott Wood if (reg) { 339a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-stash-id", 340a47a12beSStefan Roese (*reg * 2) + 32 + 1); 3418d451a71SScott Wood } 3428d451a71SScott Wood #endif 343a47a12beSStefan Roese #endif 344a47a12beSStefan Roese 345a47a12beSStefan Roese fdt_setprop(blob, l2_off, "cache-unified", NULL, 0); 346acf3f8daSKumar Gala fdt_setprop_cell(blob, l2_off, "cache-block-size", 347acf3f8daSKumar Gala line_size); 348a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-size", size); 349a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-sets", num_sets); 350a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-level", 2); 351*01b25d42SChris Packham ft_fixup_l2cache_compatible(blob, l2_off); 352acf3f8daSKumar Gala } 353a47a12beSStefan Roese 354a47a12beSStefan Roese if (l3_off < 0) { 355a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, l2_off, "next-level-cache", 0); 356a47a12beSStefan Roese 357a47a12beSStefan Roese if (ph == NULL) { 358a47a12beSStefan Roese debug("no next-level-cache property\n"); 359a47a12beSStefan Roese goto next; 360a47a12beSStefan Roese } 361a47a12beSStefan Roese l3_off = *ph; 362a47a12beSStefan Roese } 363a47a12beSStefan Roese next: 364a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, 365a47a12beSStefan Roese "device_type", "cpu", 4); 366a47a12beSStefan Roese } 367a47a12beSStefan Roese if (l3_off > 0) { 368a47a12beSStefan Roese l3_off = fdt_node_offset_by_phandle(blob, l3_off); 369a47a12beSStefan Roese if (l3_off < 0) { 370a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off)); 371a47a12beSStefan Roese return ; 372a47a12beSStefan Roese } 373a47a12beSStefan Roese ft_fixup_l3cache(blob, l3_off); 374a47a12beSStefan Roese } 375a47a12beSStefan Roese } 376a47a12beSStefan Roese #else 377a47a12beSStefan Roese #define ft_fixup_l2cache(x) 378a47a12beSStefan Roese #endif 379a47a12beSStefan Roese 380a47a12beSStefan Roese static inline void ft_fixup_cache(void *blob) 381a47a12beSStefan Roese { 382a47a12beSStefan Roese int off; 383a47a12beSStefan Roese 384a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 385a47a12beSStefan Roese 386a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 387a47a12beSStefan Roese u32 l1cfg0 = mfspr(SPRN_L1CFG0); 388a47a12beSStefan Roese u32 l1cfg1 = mfspr(SPRN_L1CFG1); 389a47a12beSStefan Roese u32 isize, iline_size, inum_sets, inum_ways; 390a47a12beSStefan Roese u32 dsize, dline_size, dnum_sets, dnum_ways; 391a47a12beSStefan Roese 392a47a12beSStefan Roese /* d-side config */ 393a47a12beSStefan Roese dsize = (l1cfg0 & 0x7ff) * 1024; 394a47a12beSStefan Roese dnum_ways = ((l1cfg0 >> 11) & 0xff) + 1; 395a47a12beSStefan Roese dline_size = (((l1cfg0 >> 23) & 0x3) + 1) * 32; 396a47a12beSStefan Roese dnum_sets = dsize / (dline_size * dnum_ways); 397a47a12beSStefan Roese 398a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-block-size", dline_size); 399a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-size", dsize); 400a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-sets", dnum_sets); 401a47a12beSStefan Roese 402a47a12beSStefan Roese #ifdef CONFIG_SYS_CACHE_STASHING 403a47a12beSStefan Roese { 404a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 405a47a12beSStefan Roese if (reg) 406a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-stash-id", 407a47a12beSStefan Roese (*reg * 2) + 32 + 0); 408a47a12beSStefan Roese } 409a47a12beSStefan Roese #endif 410a47a12beSStefan Roese 411a47a12beSStefan Roese /* i-side config */ 412a47a12beSStefan Roese isize = (l1cfg1 & 0x7ff) * 1024; 413a47a12beSStefan Roese inum_ways = ((l1cfg1 >> 11) & 0xff) + 1; 414a47a12beSStefan Roese iline_size = (((l1cfg1 >> 23) & 0x3) + 1) * 32; 415a47a12beSStefan Roese inum_sets = isize / (iline_size * inum_ways); 416a47a12beSStefan Roese 417a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-block-size", iline_size); 418a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-size", isize); 419a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-sets", inum_sets); 420a47a12beSStefan Roese 421a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, 422a47a12beSStefan Roese "device_type", "cpu", 4); 423a47a12beSStefan Roese } 424a47a12beSStefan Roese 425a47a12beSStefan Roese ft_fixup_l2cache(blob); 426a47a12beSStefan Roese } 427a47a12beSStefan Roese 428a47a12beSStefan Roese 429a47a12beSStefan Roese void fdt_add_enet_stashing(void *fdt) 430a47a12beSStefan Roese { 431a47a12beSStefan Roese do_fixup_by_compat(fdt, "gianfar", "bd-stash", NULL, 0, 1); 432a47a12beSStefan Roese 433a47a12beSStefan Roese do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-len", 96, 1); 434a47a12beSStefan Roese 435a47a12beSStefan Roese do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-idx", 0, 1); 436eea9a123SPankaj Chauhan do_fixup_by_compat(fdt, "fsl,etsec2", "bd-stash", NULL, 0, 1); 437eea9a123SPankaj Chauhan do_fixup_by_compat_u32(fdt, "fsl,etsec2", "rx-stash-len", 96, 1); 438eea9a123SPankaj Chauhan do_fixup_by_compat_u32(fdt, "fsl,etsec2", "rx-stash-idx", 0, 1); 439a47a12beSStefan Roese } 440a47a12beSStefan Roese 441a47a12beSStefan Roese #if defined(CONFIG_SYS_DPAA_FMAN) || defined(CONFIG_SYS_DPAA_PME) 442e2d0f255SKumar Gala #ifdef CONFIG_SYS_DPAA_FMAN 4431b942f74SKumar Gala static void ft_fixup_clks(void *blob, const char *compat, u32 offset, 4441b942f74SKumar Gala unsigned long freq) 445a47a12beSStefan Roese { 4461b942f74SKumar Gala phys_addr_t phys = offset + CONFIG_SYS_CCSRBAR_PHYS; 4471b942f74SKumar Gala int off = fdt_node_offset_by_compat_reg(blob, compat, phys); 448a47a12beSStefan Roese 449a47a12beSStefan Roese if (off >= 0) { 450a47a12beSStefan Roese off = fdt_setprop_cell(blob, off, "clock-frequency", freq); 451a47a12beSStefan Roese if (off > 0) 452a47a12beSStefan Roese printf("WARNING enable to set clock-frequency " 4531b942f74SKumar Gala "for %s: %s\n", compat, fdt_strerror(off)); 454a47a12beSStefan Roese } 455a47a12beSStefan Roese } 456e2d0f255SKumar Gala #endif 457a47a12beSStefan Roese 458a47a12beSStefan Roese static void ft_fixup_dpaa_clks(void *blob) 459a47a12beSStefan Roese { 460a47a12beSStefan Roese sys_info_t sysinfo; 461a47a12beSStefan Roese 462a47a12beSStefan Roese get_sys_info(&sysinfo); 463e2d0f255SKumar Gala #ifdef CONFIG_SYS_DPAA_FMAN 4641b942f74SKumar Gala ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM1_OFFSET, 465997399faSPrabhakar Kushwaha sysinfo.freq_fman[0]); 466a47a12beSStefan Roese 467a47a12beSStefan Roese #if (CONFIG_SYS_NUM_FMAN == 2) 4681b942f74SKumar Gala ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM2_OFFSET, 469997399faSPrabhakar Kushwaha sysinfo.freq_fman[1]); 470a47a12beSStefan Roese #endif 471e2d0f255SKumar Gala #endif 472a47a12beSStefan Roese 473990e1a8cSHaiying Wang #ifdef CONFIG_SYS_DPAA_QBMAN 474990e1a8cSHaiying Wang do_fixup_by_compat_u32(blob, "fsl,qman", 475997399faSPrabhakar Kushwaha "clock-frequency", sysinfo.freq_qman, 1); 476990e1a8cSHaiying Wang #endif 477990e1a8cSHaiying Wang 478a47a12beSStefan Roese #ifdef CONFIG_SYS_DPAA_PME 4791b942f74SKumar Gala do_fixup_by_compat_u32(blob, "fsl,pme", 480997399faSPrabhakar Kushwaha "clock-frequency", sysinfo.freq_pme, 1); 481a47a12beSStefan Roese #endif 482a47a12beSStefan Roese } 483a47a12beSStefan Roese #else 484a47a12beSStefan Roese #define ft_fixup_dpaa_clks(x) 485a47a12beSStefan Roese #endif 486a47a12beSStefan Roese 487a47a12beSStefan Roese #ifdef CONFIG_QE 488a47a12beSStefan Roese static void ft_fixup_qe_snum(void *blob) 489a47a12beSStefan Roese { 490a47a12beSStefan Roese unsigned int svr; 491a47a12beSStefan Roese 492a47a12beSStefan Roese svr = mfspr(SPRN_SVR); 49348f6a5c3SYork Sun if (SVR_SOC_VER(svr) == SVR_8569) { 494a47a12beSStefan Roese if(IS_SVR_REV(svr, 1, 0)) 495a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,qe", 496a47a12beSStefan Roese "fsl,qe-num-snums", 46, 1); 497a47a12beSStefan Roese else 498a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,qe", 499a47a12beSStefan Roese "fsl,qe-num-snums", 76, 1); 500a47a12beSStefan Roese } 501a47a12beSStefan Roese } 502a47a12beSStefan Roese #endif 503a47a12beSStefan Roese 504e71372cbSYork Sun #if defined(CONFIG_ARCH_P4080) 505f81f19faSShengzhou Liu static void fdt_fixup_usb(void *fdt) 506f81f19faSShengzhou Liu { 507f81f19faSShengzhou Liu ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 508f81f19faSShengzhou Liu u32 rcwsr11 = in_be32(&gur->rcwsr[11]); 509f81f19faSShengzhou Liu int off; 510f81f19faSShengzhou Liu 511f81f19faSShengzhou Liu off = fdt_node_offset_by_compatible(fdt, -1, "fsl,mpc85xx-usb2-mph"); 512f81f19faSShengzhou Liu if ((rcwsr11 & FSL_CORENET_RCWSR11_EC1) != 513f81f19faSShengzhou Liu FSL_CORENET_RCWSR11_EC1_FM1_USB1) 514f81f19faSShengzhou Liu fdt_status_disabled(fdt, off); 515f81f19faSShengzhou Liu 516f81f19faSShengzhou Liu off = fdt_node_offset_by_compatible(fdt, -1, "fsl,mpc85xx-usb2-dr"); 517f81f19faSShengzhou Liu if ((rcwsr11 & FSL_CORENET_RCWSR11_EC2) != 518f81f19faSShengzhou Liu FSL_CORENET_RCWSR11_EC2_USB2) 519f81f19faSShengzhou Liu fdt_status_disabled(fdt, off); 520f81f19faSShengzhou Liu } 521f81f19faSShengzhou Liu #else 522f81f19faSShengzhou Liu #define fdt_fixup_usb(x) 523f81f19faSShengzhou Liu #endif 524f81f19faSShengzhou Liu 52526bc57daSYork Sun #if defined(CONFIG_ARCH_T2080) || defined(CONFIG_ARCH_T4240) || \ 526cdb72c52SYork Sun defined(CONFIG_ARCH_T4160) 527605714f6SShengzhou Liu void fdt_fixup_dma3(void *blob) 528605714f6SShengzhou Liu { 529605714f6SShengzhou Liu /* the 3rd DMA is not functional if SRIO2 is chosen */ 530605714f6SShengzhou Liu int nodeoff; 531605714f6SShengzhou Liu ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 532605714f6SShengzhou Liu 533605714f6SShengzhou Liu #define CONFIG_SYS_ELO3_DMA3 (0xffe000000 + 0x102300) 5340f3d80e9SYork Sun #if defined(CONFIG_ARCH_T2080) 535605714f6SShengzhou Liu u32 srds_prtcl_s2 = in_be32(&gur->rcwsr[4]) & 536605714f6SShengzhou Liu FSL_CORENET2_RCWSR4_SRDS2_PRTCL; 537605714f6SShengzhou Liu srds_prtcl_s2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT; 538605714f6SShengzhou Liu 539605714f6SShengzhou Liu switch (srds_prtcl_s2) { 540605714f6SShengzhou Liu case 0x29: 541605714f6SShengzhou Liu case 0x2d: 542605714f6SShengzhou Liu case 0x2e: 543cdb72c52SYork Sun #elif defined(CONFIG_ARCH_T4240) || defined(CONFIG_ARCH_T4160) 544605714f6SShengzhou Liu u32 srds_prtcl_s4 = in_be32(&gur->rcwsr[4]) & 545605714f6SShengzhou Liu FSL_CORENET2_RCWSR4_SRDS4_PRTCL; 546605714f6SShengzhou Liu srds_prtcl_s4 >>= FSL_CORENET2_RCWSR4_SRDS4_PRTCL_SHIFT; 547605714f6SShengzhou Liu 548605714f6SShengzhou Liu switch (srds_prtcl_s4) { 549605714f6SShengzhou Liu case 6: 550605714f6SShengzhou Liu case 8: 551605714f6SShengzhou Liu case 14: 552605714f6SShengzhou Liu case 16: 553605714f6SShengzhou Liu #endif 554605714f6SShengzhou Liu nodeoff = fdt_node_offset_by_compat_reg(blob, "fsl,elo3-dma", 555605714f6SShengzhou Liu CONFIG_SYS_ELO3_DMA3); 556605714f6SShengzhou Liu if (nodeoff > 0) 557605714f6SShengzhou Liu fdt_status_disabled(blob, nodeoff); 558605714f6SShengzhou Liu else 559605714f6SShengzhou Liu printf("WARNING: unable to disable dma3\n"); 560605714f6SShengzhou Liu break; 561605714f6SShengzhou Liu default: 562605714f6SShengzhou Liu break; 563605714f6SShengzhou Liu } 564605714f6SShengzhou Liu } 565605714f6SShengzhou Liu #else 566605714f6SShengzhou Liu #define fdt_fixup_dma3(x) 567605714f6SShengzhou Liu #endif 568605714f6SShengzhou Liu 5695d737010SYork Sun #if defined(CONFIG_ARCH_T1040) 570d616fc58SCodrin Ciubotariu static void fdt_fixup_l2_switch(void *blob) 571d616fc58SCodrin Ciubotariu { 572d616fc58SCodrin Ciubotariu uchar l2swaddr[6]; 573d616fc58SCodrin Ciubotariu int node; 574d616fc58SCodrin Ciubotariu 575d616fc58SCodrin Ciubotariu /* The l2switch node from device-tree has 576d616fc58SCodrin Ciubotariu * compatible string "vitesse-9953" */ 577d616fc58SCodrin Ciubotariu node = fdt_node_offset_by_compatible(blob, -1, "vitesse-9953"); 578d616fc58SCodrin Ciubotariu if (node == -FDT_ERR_NOTFOUND) 579d616fc58SCodrin Ciubotariu /* no l2switch node has been found */ 580d616fc58SCodrin Ciubotariu return; 581d616fc58SCodrin Ciubotariu 582d616fc58SCodrin Ciubotariu /* Get MAC address for the l2switch from "l2switchaddr"*/ 583d616fc58SCodrin Ciubotariu if (!eth_getenv_enetaddr("l2switchaddr", l2swaddr)) { 584d616fc58SCodrin Ciubotariu printf("Warning: MAC address for l2switch not found\n"); 585d616fc58SCodrin Ciubotariu memset(l2swaddr, 0, sizeof(l2swaddr)); 586d616fc58SCodrin Ciubotariu } 587d616fc58SCodrin Ciubotariu 588d616fc58SCodrin Ciubotariu /* Add MAC address to l2switch node */ 589d616fc58SCodrin Ciubotariu fdt_setprop(blob, node, "local-mac-address", l2swaddr, 590d616fc58SCodrin Ciubotariu sizeof(l2swaddr)); 591d616fc58SCodrin Ciubotariu } 592d616fc58SCodrin Ciubotariu #else 593d616fc58SCodrin Ciubotariu #define fdt_fixup_l2_switch(x) 594d616fc58SCodrin Ciubotariu #endif 595d616fc58SCodrin Ciubotariu 596a47a12beSStefan Roese void ft_cpu_setup(void *blob, bd_t *bd) 597a47a12beSStefan Roese { 598a47a12beSStefan Roese int off; 599a47a12beSStefan Roese int val; 60051abee64SLaurentiu TUDOR int len; 601a47a12beSStefan Roese sys_info_t sysinfo; 602a47a12beSStefan Roese 603a47a12beSStefan Roese /* delete crypto node if not on an E-processor */ 604a47a12beSStefan Roese if (!IS_E_PROCESSOR(get_svr())) 605a47a12beSStefan Roese fdt_fixup_crypto_node(blob, 0); 6065e95e2d8SVakul Garg #if CONFIG_SYS_FSL_SEC_COMPAT >= 4 6075e95e2d8SVakul Garg else { 6085e95e2d8SVakul Garg ccsr_sec_t __iomem *sec; 6095e95e2d8SVakul Garg 6105e95e2d8SVakul Garg sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR; 611028dbb8dSRuchika Gupta fdt_fixup_crypto_node(blob, sec_in32(&sec->secvid_ms)); 6125e95e2d8SVakul Garg } 6135e95e2d8SVakul Garg #endif 614a47a12beSStefan Roese 615a47a12beSStefan Roese fdt_fixup_ethernet(blob); 616a47a12beSStefan Roese 617a47a12beSStefan Roese fdt_add_enet_stashing(blob); 618a47a12beSStefan Roese 619cb93071bSYork Sun #ifndef CONFIG_FSL_TBCLK_EXTRA_DIV 620cb93071bSYork Sun #define CONFIG_FSL_TBCLK_EXTRA_DIV 1 621cb93071bSYork Sun #endif 622a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, 623cb93071bSYork Sun "timebase-frequency", get_tbclk() / CONFIG_FSL_TBCLK_EXTRA_DIV, 624cb93071bSYork Sun 1); 625a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, 626a47a12beSStefan Roese "bus-frequency", bd->bi_busfreq, 1); 627a47a12beSStefan Roese get_sys_info(&sysinfo); 628a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 629a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 63051abee64SLaurentiu TUDOR u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", &len); 63151abee64SLaurentiu TUDOR val = cpu_to_fdt32(sysinfo.freq_processor[(*reg) / (len / 4)]); 632a47a12beSStefan Roese fdt_setprop(blob, off, "clock-frequency", &val, 4); 633a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, "device_type", 634a47a12beSStefan Roese "cpu", 4); 635a47a12beSStefan Roese } 636a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "soc", 4, 637a47a12beSStefan Roese "bus-frequency", bd->bi_busfreq, 1); 638a47a12beSStefan Roese 639a47a12beSStefan Roese #ifdef CONFIG_QE 640a47a12beSStefan Roese ft_qe_setup(blob); 641a47a12beSStefan Roese ft_fixup_qe_snum(blob); 642a47a12beSStefan Roese #endif 643a47a12beSStefan Roese 644075affb1SQianyu Gong #ifdef CONFIG_SYS_DPAA_FMAN 645ffadc441STimur Tabi fdt_fixup_fman_firmware(blob); 646075affb1SQianyu Gong #endif 647ffadc441STimur Tabi 648a47a12beSStefan Roese #ifdef CONFIG_SYS_NS16550 649a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "ns16550", 650a47a12beSStefan Roese "clock-frequency", CONFIG_SYS_NS16550_CLK, 1); 651a47a12beSStefan Roese #endif 652a47a12beSStefan Roese 653a47a12beSStefan Roese #ifdef CONFIG_CPM2 654a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,cpm2-scc-uart", 6558e261575SMasahiro Yamada "current-speed", gd->baudrate, 1); 656a47a12beSStefan Roese 657a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,cpm2-brg", 658a47a12beSStefan Roese "clock-frequency", bd->bi_brgfreq, 1); 659a47a12beSStefan Roese #endif 660a47a12beSStefan Roese 66185f8cda3SKumar Gala #ifdef CONFIG_FSL_CORENET 66285f8cda3SKumar Gala do_fixup_by_compat_u32(blob, "fsl,qoriq-clockgen-1.0", 66385f8cda3SKumar Gala "clock-frequency", CONFIG_SYS_CLK_FREQ, 1); 6647dd09b54SAndy Fleming do_fixup_by_compat_u32(blob, "fsl,qoriq-clockgen-2.0", 6657b700d21STang Yuantian "clock-frequency", CONFIG_SYS_CLK_FREQ, 1); 666f5c2623dSDongsheng.wang@freescale.com do_fixup_by_compat_u32(blob, "fsl,mpic", 667f5c2623dSDongsheng.wang@freescale.com "clock-frequency", get_bus_freq(0)/2, 1); 668f5c2623dSDongsheng.wang@freescale.com #else 669f5c2623dSDongsheng.wang@freescale.com do_fixup_by_compat_u32(blob, "fsl,mpic", 670f5c2623dSDongsheng.wang@freescale.com "clock-frequency", get_bus_freq(0), 1); 67185f8cda3SKumar Gala #endif 67285f8cda3SKumar Gala 673a47a12beSStefan Roese fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize); 674a47a12beSStefan Roese 675a47a12beSStefan Roese #ifdef CONFIG_MP 676a47a12beSStefan Roese ft_fixup_cpu(blob, (u64)bd->bi_memstart + (u64)bd->bi_memsize); 677a47a12beSStefan Roese ft_fixup_num_cores(blob); 6788f3a7fa4SKumar Gala #endif 679a47a12beSStefan Roese 680a47a12beSStefan Roese ft_fixup_cache(blob); 681a47a12beSStefan Roese 682a47a12beSStefan Roese #if defined(CONFIG_FSL_ESDHC) 683a47a12beSStefan Roese fdt_fixup_esdhc(blob, bd); 684a47a12beSStefan Roese #endif 685a47a12beSStefan Roese 686a47a12beSStefan Roese ft_fixup_dpaa_clks(blob); 687db977abfSKumar Gala 688db977abfSKumar Gala #if defined(CONFIG_SYS_BMAN_MEM_PHYS) 689db977abfSKumar Gala fdt_portal(blob, "fsl,bman-portal", "bman-portals", 690db977abfSKumar Gala (u64)CONFIG_SYS_BMAN_MEM_PHYS, 691db977abfSKumar Gala CONFIG_SYS_BMAN_MEM_SIZE); 6922a0ffb84SHaiying Wang fdt_fixup_bportals(blob); 693db977abfSKumar Gala #endif 694db977abfSKumar Gala 695db977abfSKumar Gala #if defined(CONFIG_SYS_QMAN_MEM_PHYS) 696db977abfSKumar Gala fdt_portal(blob, "fsl,qman-portal", "qman-portals", 697db977abfSKumar Gala (u64)CONFIG_SYS_QMAN_MEM_PHYS, 698db977abfSKumar Gala CONFIG_SYS_QMAN_MEM_SIZE); 699db977abfSKumar Gala 700db977abfSKumar Gala fdt_fixup_qportals(blob); 701db977abfSKumar Gala #endif 702a09b9b68SKumar Gala 703a09b9b68SKumar Gala #ifdef CONFIG_SYS_SRIO 704a09b9b68SKumar Gala ft_srio_setup(blob); 705a09b9b68SKumar Gala #endif 706f5feb5afSbhaskar upadhaya 707f5feb5afSbhaskar upadhaya /* 708f5feb5afSbhaskar upadhaya * system-clock = CCB clock/2 709f5feb5afSbhaskar upadhaya * Here gd->bus_clk = CCB clock 710f5feb5afSbhaskar upadhaya * We are using the system clock as 1588 Timer reference 711f5feb5afSbhaskar upadhaya * clock source select 712f5feb5afSbhaskar upadhaya */ 713f5feb5afSbhaskar upadhaya do_fixup_by_compat_u32(blob, "fsl,gianfar-ptp-timer", 714f5feb5afSbhaskar upadhaya "timer-frequency", gd->bus_clk/2, 1); 71565bb8b06SBhaskar Upadhaya 71633c87536SJia Hongtao /* 71733c87536SJia Hongtao * clock-freq should change to clock-frequency and 71833c87536SJia Hongtao * flexcan-v1.0 should change to p1010-flexcan respectively 71933c87536SJia Hongtao * in the future. 72033c87536SJia Hongtao */ 72165bb8b06SBhaskar Upadhaya do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0", 72233c87536SJia Hongtao "clock_freq", gd->bus_clk/2, 1); 72333c87536SJia Hongtao 72433c87536SJia Hongtao do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0", 72533c87536SJia Hongtao "clock-frequency", gd->bus_clk/2, 1); 72633c87536SJia Hongtao 72733c87536SJia Hongtao do_fixup_by_compat_u32(blob, "fsl,p1010-flexcan", 72833c87536SJia Hongtao "clock-frequency", gd->bus_clk/2, 1); 729f81f19faSShengzhou Liu 730f81f19faSShengzhou Liu fdt_fixup_usb(blob); 731d616fc58SCodrin Ciubotariu 732d616fc58SCodrin Ciubotariu fdt_fixup_l2_switch(blob); 733605714f6SShengzhou Liu 734605714f6SShengzhou Liu fdt_fixup_dma3(blob); 735a47a12beSStefan Roese } 73690f89f09STimur Tabi 73790f89f09STimur Tabi /* 73890f89f09STimur Tabi * For some CCSR devices, we only have the virtual address, not the physical 73990f89f09STimur Tabi * address. This is because we map CCSR as a whole, so we typically don't need 74090f89f09STimur Tabi * a macro for the physical address of any device within CCSR. In this case, 74190f89f09STimur Tabi * we calculate the physical address of that device using it's the difference 74290f89f09STimur Tabi * between the virtual address of the device and the virtual address of the 74390f89f09STimur Tabi * beginning of CCSR. 74490f89f09STimur Tabi */ 74590f89f09STimur Tabi #define CCSR_VIRT_TO_PHYS(x) \ 74690f89f09STimur Tabi (CONFIG_SYS_CCSRBAR_PHYS + ((x) - CONFIG_SYS_CCSRBAR)) 74790f89f09STimur Tabi 748cc15df57STimur Tabi static void msg(const char *name, uint64_t uaddr, uint64_t daddr) 749cc15df57STimur Tabi { 750cc15df57STimur Tabi printf("Warning: U-Boot configured %s at address %llx,\n" 751cc15df57STimur Tabi "but the device tree has it at %llx\n", name, uaddr, daddr); 752cc15df57STimur Tabi } 753cc15df57STimur Tabi 75490f89f09STimur Tabi /* 75590f89f09STimur Tabi * Verify the device tree 75690f89f09STimur Tabi * 75790f89f09STimur Tabi * This function compares several CONFIG_xxx macros that contain physical 75890f89f09STimur Tabi * addresses with the corresponding nodes in the device tree, to see if 75990f89f09STimur Tabi * the physical addresses are all correct. For example, if 76090f89f09STimur Tabi * CONFIG_SYS_NS16550_COM1 is defined, then it contains the virtual address 76190f89f09STimur Tabi * of the first UART. We convert this to a physical address and compare 76290f89f09STimur Tabi * that with the physical address of the first ns16550-compatible node 76390f89f09STimur Tabi * in the device tree. If they don't match, then we display a warning. 76490f89f09STimur Tabi * 76590f89f09STimur Tabi * Returns 1 on success, 0 on failure 76690f89f09STimur Tabi */ 76790f89f09STimur Tabi int ft_verify_fdt(void *fdt) 76890f89f09STimur Tabi { 769cc15df57STimur Tabi uint64_t addr = 0; 77090f89f09STimur Tabi int aliases; 77190f89f09STimur Tabi int off; 77290f89f09STimur Tabi 77390f89f09STimur Tabi /* First check the CCSR base address */ 77490f89f09STimur Tabi off = fdt_node_offset_by_prop_value(fdt, -1, "device_type", "soc", 4); 77590f89f09STimur Tabi if (off > 0) 776cc15df57STimur Tabi addr = fdt_get_base_address(fdt, off); 77790f89f09STimur Tabi 778cc15df57STimur Tabi if (!addr) { 77990f89f09STimur Tabi printf("Warning: could not determine base CCSR address in " 78090f89f09STimur Tabi "device tree\n"); 78190f89f09STimur Tabi /* No point in checking anything else */ 78290f89f09STimur Tabi return 0; 78390f89f09STimur Tabi } 78490f89f09STimur Tabi 785cc15df57STimur Tabi if (addr != CONFIG_SYS_CCSRBAR_PHYS) { 786cc15df57STimur Tabi msg("CCSR", CONFIG_SYS_CCSRBAR_PHYS, addr); 78790f89f09STimur Tabi /* No point in checking anything else */ 78890f89f09STimur Tabi return 0; 78990f89f09STimur Tabi } 79090f89f09STimur Tabi 79190f89f09STimur Tabi /* 792cc15df57STimur Tabi * Check some nodes via aliases. We assume that U-Boot and the device 793cc15df57STimur Tabi * tree enumerate the devices equally. E.g. the first serial port in 794cc15df57STimur Tabi * U-Boot is the same as "serial0" in the device tree. 79590f89f09STimur Tabi */ 79690f89f09STimur Tabi aliases = fdt_path_offset(fdt, "/aliases"); 79790f89f09STimur Tabi if (aliases > 0) { 79890f89f09STimur Tabi #ifdef CONFIG_SYS_NS16550_COM1 79990f89f09STimur Tabi if (!fdt_verify_alias_address(fdt, aliases, "serial0", 80090f89f09STimur Tabi CCSR_VIRT_TO_PHYS(CONFIG_SYS_NS16550_COM1))) 80190f89f09STimur Tabi return 0; 80290f89f09STimur Tabi #endif 80390f89f09STimur Tabi 80490f89f09STimur Tabi #ifdef CONFIG_SYS_NS16550_COM2 80590f89f09STimur Tabi if (!fdt_verify_alias_address(fdt, aliases, "serial1", 80690f89f09STimur Tabi CCSR_VIRT_TO_PHYS(CONFIG_SYS_NS16550_COM2))) 80790f89f09STimur Tabi return 0; 80890f89f09STimur Tabi #endif 80990f89f09STimur Tabi } 81090f89f09STimur Tabi 811cc15df57STimur Tabi /* 812cc15df57STimur Tabi * The localbus node is typically a root node, even though the lbc 813cc15df57STimur Tabi * controller is part of CCSR. If we were to put the lbc node under 814cc15df57STimur Tabi * the SOC node, then the 'ranges' property in the lbc node would 815cc15df57STimur Tabi * translate through the 'ranges' property of the parent SOC node, and 816cc15df57STimur Tabi * we don't want that. Since it's a separate node, it's possible for 817cc15df57STimur Tabi * the 'reg' property to be wrong, so check it here. For now, we 818cc15df57STimur Tabi * only check for "fsl,elbc" nodes. 819cc15df57STimur Tabi */ 820cc15df57STimur Tabi #ifdef CONFIG_SYS_LBC_ADDR 821cc15df57STimur Tabi off = fdt_node_offset_by_compatible(fdt, -1, "fsl,elbc"); 822cc15df57STimur Tabi if (off > 0) { 8238aa5ec6eSKim Phillips const fdt32_t *reg = fdt_getprop(fdt, off, "reg", NULL); 824cc15df57STimur Tabi if (reg) { 825cc15df57STimur Tabi uint64_t uaddr = CCSR_VIRT_TO_PHYS(CONFIG_SYS_LBC_ADDR); 826cc15df57STimur Tabi 827cc15df57STimur Tabi addr = fdt_translate_address(fdt, off, reg); 828cc15df57STimur Tabi if (uaddr != addr) { 829cc15df57STimur Tabi msg("the localbus", uaddr, addr); 830cc15df57STimur Tabi return 0; 831cc15df57STimur Tabi } 832cc15df57STimur Tabi } 833cc15df57STimur Tabi } 834cc15df57STimur Tabi #endif 835cc15df57STimur Tabi 83690f89f09STimur Tabi return 1; 83790f89f09STimur Tabi } 838d4683776SZhao Qiang 839d4683776SZhao Qiang void fdt_del_diu(void *blob) 840d4683776SZhao Qiang { 841d4683776SZhao Qiang int nodeoff = 0; 842d4683776SZhao Qiang 843d4683776SZhao Qiang while ((nodeoff = fdt_node_offset_by_compatible(blob, 0, 844d4683776SZhao Qiang "fsl,diu")) >= 0) { 845d4683776SZhao Qiang fdt_del_node(blob, nodeoff); 846d4683776SZhao Qiang } 847d4683776SZhao Qiang } 848