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 183a47a12beSStefan Roese #if defined(CONFIG_L2_CACHE) 184a47a12beSStefan Roese /* return size in kilobytes */ 185a47a12beSStefan Roese static inline u32 l2cache_size(void) 186a47a12beSStefan Roese { 187a47a12beSStefan Roese volatile ccsr_l2cache_t *l2cache = (void *)CONFIG_SYS_MPC85xx_L2_ADDR; 188a47a12beSStefan Roese volatile u32 l2siz_field = (l2cache->l2ctl >> 28) & 0x3; 189a47a12beSStefan Roese u32 ver = SVR_SOC_VER(get_svr()); 190a47a12beSStefan Roese 191a47a12beSStefan Roese switch (l2siz_field) { 192a47a12beSStefan Roese case 0x0: 193a47a12beSStefan Roese break; 194a47a12beSStefan Roese case 0x1: 195a47a12beSStefan Roese if (ver == SVR_8540 || ver == SVR_8560 || 19648f6a5c3SYork Sun ver == SVR_8541 || ver == SVR_8555) 197a47a12beSStefan Roese return 128; 198a47a12beSStefan Roese else 199a47a12beSStefan Roese return 256; 200a47a12beSStefan Roese break; 201a47a12beSStefan Roese case 0x2: 202a47a12beSStefan Roese if (ver == SVR_8540 || ver == SVR_8560 || 20348f6a5c3SYork Sun ver == SVR_8541 || ver == SVR_8555) 204a47a12beSStefan Roese return 256; 205a47a12beSStefan Roese else 206a47a12beSStefan Roese return 512; 207a47a12beSStefan Roese break; 208a47a12beSStefan Roese case 0x3: 209a47a12beSStefan Roese return 1024; 210a47a12beSStefan Roese break; 211a47a12beSStefan Roese } 212a47a12beSStefan Roese 213a47a12beSStefan Roese return 0; 214a47a12beSStefan Roese } 215a47a12beSStefan Roese 216a47a12beSStefan Roese static inline void ft_fixup_l2cache(void *blob) 217a47a12beSStefan Roese { 218a47a12beSStefan Roese int len, off; 219a47a12beSStefan Roese u32 *ph; 220a47a12beSStefan Roese struct cpu_type *cpu = identify_cpu(SVR_SOC_VER(get_svr())); 221a47a12beSStefan Roese 222a47a12beSStefan Roese const u32 line_size = 32; 223a47a12beSStefan Roese const u32 num_ways = 8; 224a47a12beSStefan Roese const u32 size = l2cache_size() * 1024; 225a47a12beSStefan Roese const u32 num_sets = size / (line_size * num_ways); 226a47a12beSStefan Roese 227a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 228a47a12beSStefan Roese if (off < 0) { 229a47a12beSStefan Roese debug("no cpu node fount\n"); 230a47a12beSStefan Roese return; 231a47a12beSStefan Roese } 232a47a12beSStefan Roese 233a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0); 234a47a12beSStefan Roese 235a47a12beSStefan Roese if (ph == NULL) { 236a47a12beSStefan Roese debug("no next-level-cache property\n"); 237a47a12beSStefan Roese return ; 238a47a12beSStefan Roese } 239a47a12beSStefan Roese 240a47a12beSStefan Roese off = fdt_node_offset_by_phandle(blob, *ph); 241a47a12beSStefan Roese if (off < 0) { 242a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off)); 243a47a12beSStefan Roese return ; 244a47a12beSStefan Roese } 245a47a12beSStefan Roese 246a47a12beSStefan Roese if (cpu) { 247ee4756d4STimur Tabi char buf[40]; 248a47a12beSStefan Roese 249ee4756d4STimur Tabi if (isdigit(cpu->name[0])) { 250ee4756d4STimur Tabi /* MPCxxxx, where xxxx == 4-digit number */ 251ee4756d4STimur Tabi len = sprintf(buf, "fsl,mpc%s-l2-cache-controller", 252ee4756d4STimur Tabi cpu->name) + 1; 253ee4756d4STimur Tabi } else { 254ee4756d4STimur Tabi /* Pxxxx or Txxxx, where xxxx == 4-digit number */ 255ee4756d4STimur Tabi len = sprintf(buf, "fsl,%c%s-l2-cache-controller", 256ee4756d4STimur Tabi tolower(cpu->name[0]), cpu->name + 1) + 1; 257ee4756d4STimur Tabi } 258ee4756d4STimur Tabi 259ee4756d4STimur Tabi /* 260ee4756d4STimur Tabi * append "cache" after the NULL character that the previous 261ee4756d4STimur Tabi * sprintf wrote. This is how a device tree stores multiple 262ee4756d4STimur Tabi * strings in a property. 263ee4756d4STimur Tabi */ 264ee4756d4STimur Tabi len += sprintf(buf + len, "cache") + 1; 265ee4756d4STimur Tabi 266ee4756d4STimur Tabi fdt_setprop(blob, off, "compatible", buf, len); 267a47a12beSStefan Roese } 268a47a12beSStefan Roese fdt_setprop(blob, off, "cache-unified", NULL, 0); 269a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-block-size", line_size); 270a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-size", size); 271a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-sets", num_sets); 272a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-level", 2); 273a47a12beSStefan Roese 274a47a12beSStefan Roese /* we dont bother w/L3 since no platform of this type has one */ 275a47a12beSStefan Roese } 2766d2b9da1SYork Sun #elif defined(CONFIG_BACKSIDE_L2_CACHE) || \ 2776d2b9da1SYork Sun defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) 278a47a12beSStefan Roese static inline void ft_fixup_l2cache(void *blob) 279a47a12beSStefan Roese { 280a47a12beSStefan Roese int off, l2_off, l3_off = -1; 281a47a12beSStefan Roese u32 *ph; 2826d2b9da1SYork Sun #ifdef CONFIG_BACKSIDE_L2_CACHE 283a47a12beSStefan Roese u32 l2cfg0 = mfspr(SPRN_L2CFG0); 2846d2b9da1SYork Sun #else 2856d2b9da1SYork Sun struct ccsr_cluster_l2 *l2cache = 2866d2b9da1SYork Sun (struct ccsr_cluster_l2 __iomem *)(CONFIG_SYS_FSL_CLUSTER_1_L2); 2876d2b9da1SYork Sun u32 l2cfg0 = in_be32(&l2cache->l2cfg0); 2886d2b9da1SYork Sun #endif 289a47a12beSStefan Roese u32 size, line_size, num_ways, num_sets; 290acf3f8daSKumar Gala int has_l2 = 1; 291acf3f8daSKumar Gala 292acf3f8daSKumar Gala /* P2040/P2040E has no L2, so dont set any L2 props */ 29348f6a5c3SYork Sun if (SVR_SOC_VER(get_svr()) == SVR_P2040) 294acf3f8daSKumar Gala has_l2 = 0; 295a47a12beSStefan Roese 296a47a12beSStefan Roese size = (l2cfg0 & 0x3fff) * 64 * 1024; 297a47a12beSStefan Roese num_ways = ((l2cfg0 >> 14) & 0x1f) + 1; 298a47a12beSStefan Roese line_size = (((l2cfg0 >> 23) & 0x3) + 1) * 32; 299a47a12beSStefan Roese num_sets = size / (line_size * num_ways); 300a47a12beSStefan Roese 301a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 302a47a12beSStefan Roese 303a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 304a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0); 305a47a12beSStefan Roese 306a47a12beSStefan Roese if (ph == NULL) { 307a47a12beSStefan Roese debug("no next-level-cache property\n"); 308a47a12beSStefan Roese goto next; 309a47a12beSStefan Roese } 310a47a12beSStefan Roese 311a47a12beSStefan Roese l2_off = fdt_node_offset_by_phandle(blob, *ph); 312a47a12beSStefan Roese if (l2_off < 0) { 313a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off)); 314a47a12beSStefan Roese goto next; 315a47a12beSStefan Roese } 316a47a12beSStefan Roese 317acf3f8daSKumar Gala if (has_l2) { 318a47a12beSStefan Roese #ifdef CONFIG_SYS_CACHE_STASHING 319a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 320e9827468SPrabhakar Kushwaha #if defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500) 3216d2b9da1SYork Sun /* Only initialize every eighth thread */ 3228d451a71SScott Wood if (reg && !((*reg) % 8)) { 3238d451a71SScott Wood fdt_setprop_cell(blob, l2_off, "cache-stash-id", 3248d451a71SScott Wood (*reg / 4) + 32 + 1); 3258d451a71SScott Wood } 3266d2b9da1SYork Sun #else 3278d451a71SScott Wood if (reg) { 328a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-stash-id", 329a47a12beSStefan Roese (*reg * 2) + 32 + 1); 3308d451a71SScott Wood } 3318d451a71SScott Wood #endif 332a47a12beSStefan Roese #endif 333a47a12beSStefan Roese 334a47a12beSStefan Roese fdt_setprop(blob, l2_off, "cache-unified", NULL, 0); 335acf3f8daSKumar Gala fdt_setprop_cell(blob, l2_off, "cache-block-size", 336acf3f8daSKumar Gala line_size); 337a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-size", size); 338a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-sets", num_sets); 339a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-level", 2); 340a47a12beSStefan Roese fdt_setprop(blob, l2_off, "compatible", "cache", 6); 341acf3f8daSKumar Gala } 342a47a12beSStefan Roese 343a47a12beSStefan Roese if (l3_off < 0) { 344a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, l2_off, "next-level-cache", 0); 345a47a12beSStefan Roese 346a47a12beSStefan Roese if (ph == NULL) { 347a47a12beSStefan Roese debug("no next-level-cache property\n"); 348a47a12beSStefan Roese goto next; 349a47a12beSStefan Roese } 350a47a12beSStefan Roese l3_off = *ph; 351a47a12beSStefan Roese } 352a47a12beSStefan Roese next: 353a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, 354a47a12beSStefan Roese "device_type", "cpu", 4); 355a47a12beSStefan Roese } 356a47a12beSStefan Roese if (l3_off > 0) { 357a47a12beSStefan Roese l3_off = fdt_node_offset_by_phandle(blob, l3_off); 358a47a12beSStefan Roese if (l3_off < 0) { 359a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off)); 360a47a12beSStefan Roese return ; 361a47a12beSStefan Roese } 362a47a12beSStefan Roese ft_fixup_l3cache(blob, l3_off); 363a47a12beSStefan Roese } 364a47a12beSStefan Roese } 365a47a12beSStefan Roese #else 366a47a12beSStefan Roese #define ft_fixup_l2cache(x) 367a47a12beSStefan Roese #endif 368a47a12beSStefan Roese 369a47a12beSStefan Roese static inline void ft_fixup_cache(void *blob) 370a47a12beSStefan Roese { 371a47a12beSStefan Roese int off; 372a47a12beSStefan Roese 373a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 374a47a12beSStefan Roese 375a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 376a47a12beSStefan Roese u32 l1cfg0 = mfspr(SPRN_L1CFG0); 377a47a12beSStefan Roese u32 l1cfg1 = mfspr(SPRN_L1CFG1); 378a47a12beSStefan Roese u32 isize, iline_size, inum_sets, inum_ways; 379a47a12beSStefan Roese u32 dsize, dline_size, dnum_sets, dnum_ways; 380a47a12beSStefan Roese 381a47a12beSStefan Roese /* d-side config */ 382a47a12beSStefan Roese dsize = (l1cfg0 & 0x7ff) * 1024; 383a47a12beSStefan Roese dnum_ways = ((l1cfg0 >> 11) & 0xff) + 1; 384a47a12beSStefan Roese dline_size = (((l1cfg0 >> 23) & 0x3) + 1) * 32; 385a47a12beSStefan Roese dnum_sets = dsize / (dline_size * dnum_ways); 386a47a12beSStefan Roese 387a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-block-size", dline_size); 388a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-size", dsize); 389a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-sets", dnum_sets); 390a47a12beSStefan Roese 391a47a12beSStefan Roese #ifdef CONFIG_SYS_CACHE_STASHING 392a47a12beSStefan Roese { 393a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 394a47a12beSStefan Roese if (reg) 395a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-stash-id", 396a47a12beSStefan Roese (*reg * 2) + 32 + 0); 397a47a12beSStefan Roese } 398a47a12beSStefan Roese #endif 399a47a12beSStefan Roese 400a47a12beSStefan Roese /* i-side config */ 401a47a12beSStefan Roese isize = (l1cfg1 & 0x7ff) * 1024; 402a47a12beSStefan Roese inum_ways = ((l1cfg1 >> 11) & 0xff) + 1; 403a47a12beSStefan Roese iline_size = (((l1cfg1 >> 23) & 0x3) + 1) * 32; 404a47a12beSStefan Roese inum_sets = isize / (iline_size * inum_ways); 405a47a12beSStefan Roese 406a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-block-size", iline_size); 407a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-size", isize); 408a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-sets", inum_sets); 409a47a12beSStefan Roese 410a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, 411a47a12beSStefan Roese "device_type", "cpu", 4); 412a47a12beSStefan Roese } 413a47a12beSStefan Roese 414a47a12beSStefan Roese ft_fixup_l2cache(blob); 415a47a12beSStefan Roese } 416a47a12beSStefan Roese 417a47a12beSStefan Roese 418a47a12beSStefan Roese void fdt_add_enet_stashing(void *fdt) 419a47a12beSStefan Roese { 420a47a12beSStefan Roese do_fixup_by_compat(fdt, "gianfar", "bd-stash", NULL, 0, 1); 421a47a12beSStefan Roese 422a47a12beSStefan Roese do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-len", 96, 1); 423a47a12beSStefan Roese 424a47a12beSStefan Roese do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-idx", 0, 1); 425eea9a123SPankaj Chauhan do_fixup_by_compat(fdt, "fsl,etsec2", "bd-stash", NULL, 0, 1); 426eea9a123SPankaj Chauhan do_fixup_by_compat_u32(fdt, "fsl,etsec2", "rx-stash-len", 96, 1); 427eea9a123SPankaj Chauhan do_fixup_by_compat_u32(fdt, "fsl,etsec2", "rx-stash-idx", 0, 1); 428a47a12beSStefan Roese } 429a47a12beSStefan Roese 430a47a12beSStefan Roese #if defined(CONFIG_SYS_DPAA_FMAN) || defined(CONFIG_SYS_DPAA_PME) 431e2d0f255SKumar Gala #ifdef CONFIG_SYS_DPAA_FMAN 4321b942f74SKumar Gala static void ft_fixup_clks(void *blob, const char *compat, u32 offset, 4331b942f74SKumar Gala unsigned long freq) 434a47a12beSStefan Roese { 4351b942f74SKumar Gala phys_addr_t phys = offset + CONFIG_SYS_CCSRBAR_PHYS; 4361b942f74SKumar Gala int off = fdt_node_offset_by_compat_reg(blob, compat, phys); 437a47a12beSStefan Roese 438a47a12beSStefan Roese if (off >= 0) { 439a47a12beSStefan Roese off = fdt_setprop_cell(blob, off, "clock-frequency", freq); 440a47a12beSStefan Roese if (off > 0) 441a47a12beSStefan Roese printf("WARNING enable to set clock-frequency " 4421b942f74SKumar Gala "for %s: %s\n", compat, fdt_strerror(off)); 443a47a12beSStefan Roese } 444a47a12beSStefan Roese } 445e2d0f255SKumar Gala #endif 446a47a12beSStefan Roese 447a47a12beSStefan Roese static void ft_fixup_dpaa_clks(void *blob) 448a47a12beSStefan Roese { 449a47a12beSStefan Roese sys_info_t sysinfo; 450a47a12beSStefan Roese 451a47a12beSStefan Roese get_sys_info(&sysinfo); 452e2d0f255SKumar Gala #ifdef CONFIG_SYS_DPAA_FMAN 4531b942f74SKumar Gala ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM1_OFFSET, 454997399faSPrabhakar Kushwaha sysinfo.freq_fman[0]); 455a47a12beSStefan Roese 456a47a12beSStefan Roese #if (CONFIG_SYS_NUM_FMAN == 2) 4571b942f74SKumar Gala ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM2_OFFSET, 458997399faSPrabhakar Kushwaha sysinfo.freq_fman[1]); 459a47a12beSStefan Roese #endif 460e2d0f255SKumar Gala #endif 461a47a12beSStefan Roese 462990e1a8cSHaiying Wang #ifdef CONFIG_SYS_DPAA_QBMAN 463990e1a8cSHaiying Wang do_fixup_by_compat_u32(blob, "fsl,qman", 464997399faSPrabhakar Kushwaha "clock-frequency", sysinfo.freq_qman, 1); 465990e1a8cSHaiying Wang #endif 466990e1a8cSHaiying Wang 467a47a12beSStefan Roese #ifdef CONFIG_SYS_DPAA_PME 4681b942f74SKumar Gala do_fixup_by_compat_u32(blob, "fsl,pme", 469997399faSPrabhakar Kushwaha "clock-frequency", sysinfo.freq_pme, 1); 470a47a12beSStefan Roese #endif 471a47a12beSStefan Roese } 472a47a12beSStefan Roese #else 473a47a12beSStefan Roese #define ft_fixup_dpaa_clks(x) 474a47a12beSStefan Roese #endif 475a47a12beSStefan Roese 476a47a12beSStefan Roese #ifdef CONFIG_QE 477a47a12beSStefan Roese static void ft_fixup_qe_snum(void *blob) 478a47a12beSStefan Roese { 479a47a12beSStefan Roese unsigned int svr; 480a47a12beSStefan Roese 481a47a12beSStefan Roese svr = mfspr(SPRN_SVR); 48248f6a5c3SYork Sun if (SVR_SOC_VER(svr) == SVR_8569) { 483a47a12beSStefan Roese if(IS_SVR_REV(svr, 1, 0)) 484a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,qe", 485a47a12beSStefan Roese "fsl,qe-num-snums", 46, 1); 486a47a12beSStefan Roese else 487a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,qe", 488a47a12beSStefan Roese "fsl,qe-num-snums", 76, 1); 489a47a12beSStefan Roese } 490a47a12beSStefan Roese } 491a47a12beSStefan Roese #endif 492a47a12beSStefan Roese 493e71372cbSYork Sun #if defined(CONFIG_ARCH_P4080) 494f81f19faSShengzhou Liu static void fdt_fixup_usb(void *fdt) 495f81f19faSShengzhou Liu { 496f81f19faSShengzhou Liu ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 497f81f19faSShengzhou Liu u32 rcwsr11 = in_be32(&gur->rcwsr[11]); 498f81f19faSShengzhou Liu int off; 499f81f19faSShengzhou Liu 500f81f19faSShengzhou Liu off = fdt_node_offset_by_compatible(fdt, -1, "fsl,mpc85xx-usb2-mph"); 501f81f19faSShengzhou Liu if ((rcwsr11 & FSL_CORENET_RCWSR11_EC1) != 502f81f19faSShengzhou Liu FSL_CORENET_RCWSR11_EC1_FM1_USB1) 503f81f19faSShengzhou Liu fdt_status_disabled(fdt, off); 504f81f19faSShengzhou Liu 505f81f19faSShengzhou Liu off = fdt_node_offset_by_compatible(fdt, -1, "fsl,mpc85xx-usb2-dr"); 506f81f19faSShengzhou Liu if ((rcwsr11 & FSL_CORENET_RCWSR11_EC2) != 507f81f19faSShengzhou Liu FSL_CORENET_RCWSR11_EC2_USB2) 508f81f19faSShengzhou Liu fdt_status_disabled(fdt, off); 509f81f19faSShengzhou Liu } 510f81f19faSShengzhou Liu #else 511f81f19faSShengzhou Liu #define fdt_fixup_usb(x) 512f81f19faSShengzhou Liu #endif 513f81f19faSShengzhou Liu 51426bc57daSYork Sun #if defined(CONFIG_ARCH_T2080) || defined(CONFIG_ARCH_T4240) || \ 515*cdb72c52SYork Sun defined(CONFIG_ARCH_T4160) 516605714f6SShengzhou Liu void fdt_fixup_dma3(void *blob) 517605714f6SShengzhou Liu { 518605714f6SShengzhou Liu /* the 3rd DMA is not functional if SRIO2 is chosen */ 519605714f6SShengzhou Liu int nodeoff; 520605714f6SShengzhou Liu ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 521605714f6SShengzhou Liu 522605714f6SShengzhou Liu #define CONFIG_SYS_ELO3_DMA3 (0xffe000000 + 0x102300) 5230f3d80e9SYork Sun #if defined(CONFIG_ARCH_T2080) 524605714f6SShengzhou Liu u32 srds_prtcl_s2 = in_be32(&gur->rcwsr[4]) & 525605714f6SShengzhou Liu FSL_CORENET2_RCWSR4_SRDS2_PRTCL; 526605714f6SShengzhou Liu srds_prtcl_s2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT; 527605714f6SShengzhou Liu 528605714f6SShengzhou Liu switch (srds_prtcl_s2) { 529605714f6SShengzhou Liu case 0x29: 530605714f6SShengzhou Liu case 0x2d: 531605714f6SShengzhou Liu case 0x2e: 532*cdb72c52SYork Sun #elif defined(CONFIG_ARCH_T4240) || defined(CONFIG_ARCH_T4160) 533605714f6SShengzhou Liu u32 srds_prtcl_s4 = in_be32(&gur->rcwsr[4]) & 534605714f6SShengzhou Liu FSL_CORENET2_RCWSR4_SRDS4_PRTCL; 535605714f6SShengzhou Liu srds_prtcl_s4 >>= FSL_CORENET2_RCWSR4_SRDS4_PRTCL_SHIFT; 536605714f6SShengzhou Liu 537605714f6SShengzhou Liu switch (srds_prtcl_s4) { 538605714f6SShengzhou Liu case 6: 539605714f6SShengzhou Liu case 8: 540605714f6SShengzhou Liu case 14: 541605714f6SShengzhou Liu case 16: 542605714f6SShengzhou Liu #endif 543605714f6SShengzhou Liu nodeoff = fdt_node_offset_by_compat_reg(blob, "fsl,elo3-dma", 544605714f6SShengzhou Liu CONFIG_SYS_ELO3_DMA3); 545605714f6SShengzhou Liu if (nodeoff > 0) 546605714f6SShengzhou Liu fdt_status_disabled(blob, nodeoff); 547605714f6SShengzhou Liu else 548605714f6SShengzhou Liu printf("WARNING: unable to disable dma3\n"); 549605714f6SShengzhou Liu break; 550605714f6SShengzhou Liu default: 551605714f6SShengzhou Liu break; 552605714f6SShengzhou Liu } 553605714f6SShengzhou Liu } 554605714f6SShengzhou Liu #else 555605714f6SShengzhou Liu #define fdt_fixup_dma3(x) 556605714f6SShengzhou Liu #endif 557605714f6SShengzhou Liu 5585d737010SYork Sun #if defined(CONFIG_ARCH_T1040) 559d616fc58SCodrin Ciubotariu static void fdt_fixup_l2_switch(void *blob) 560d616fc58SCodrin Ciubotariu { 561d616fc58SCodrin Ciubotariu uchar l2swaddr[6]; 562d616fc58SCodrin Ciubotariu int node; 563d616fc58SCodrin Ciubotariu 564d616fc58SCodrin Ciubotariu /* The l2switch node from device-tree has 565d616fc58SCodrin Ciubotariu * compatible string "vitesse-9953" */ 566d616fc58SCodrin Ciubotariu node = fdt_node_offset_by_compatible(blob, -1, "vitesse-9953"); 567d616fc58SCodrin Ciubotariu if (node == -FDT_ERR_NOTFOUND) 568d616fc58SCodrin Ciubotariu /* no l2switch node has been found */ 569d616fc58SCodrin Ciubotariu return; 570d616fc58SCodrin Ciubotariu 571d616fc58SCodrin Ciubotariu /* Get MAC address for the l2switch from "l2switchaddr"*/ 572d616fc58SCodrin Ciubotariu if (!eth_getenv_enetaddr("l2switchaddr", l2swaddr)) { 573d616fc58SCodrin Ciubotariu printf("Warning: MAC address for l2switch not found\n"); 574d616fc58SCodrin Ciubotariu memset(l2swaddr, 0, sizeof(l2swaddr)); 575d616fc58SCodrin Ciubotariu } 576d616fc58SCodrin Ciubotariu 577d616fc58SCodrin Ciubotariu /* Add MAC address to l2switch node */ 578d616fc58SCodrin Ciubotariu fdt_setprop(blob, node, "local-mac-address", l2swaddr, 579d616fc58SCodrin Ciubotariu sizeof(l2swaddr)); 580d616fc58SCodrin Ciubotariu } 581d616fc58SCodrin Ciubotariu #else 582d616fc58SCodrin Ciubotariu #define fdt_fixup_l2_switch(x) 583d616fc58SCodrin Ciubotariu #endif 584d616fc58SCodrin Ciubotariu 585a47a12beSStefan Roese void ft_cpu_setup(void *blob, bd_t *bd) 586a47a12beSStefan Roese { 587a47a12beSStefan Roese int off; 588a47a12beSStefan Roese int val; 58951abee64SLaurentiu TUDOR int len; 590a47a12beSStefan Roese sys_info_t sysinfo; 591a47a12beSStefan Roese 592a47a12beSStefan Roese /* delete crypto node if not on an E-processor */ 593a47a12beSStefan Roese if (!IS_E_PROCESSOR(get_svr())) 594a47a12beSStefan Roese fdt_fixup_crypto_node(blob, 0); 5955e95e2d8SVakul Garg #if CONFIG_SYS_FSL_SEC_COMPAT >= 4 5965e95e2d8SVakul Garg else { 5975e95e2d8SVakul Garg ccsr_sec_t __iomem *sec; 5985e95e2d8SVakul Garg 5995e95e2d8SVakul Garg sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR; 600028dbb8dSRuchika Gupta fdt_fixup_crypto_node(blob, sec_in32(&sec->secvid_ms)); 6015e95e2d8SVakul Garg } 6025e95e2d8SVakul Garg #endif 603a47a12beSStefan Roese 604a47a12beSStefan Roese fdt_fixup_ethernet(blob); 605a47a12beSStefan Roese 606a47a12beSStefan Roese fdt_add_enet_stashing(blob); 607a47a12beSStefan Roese 608cb93071bSYork Sun #ifndef CONFIG_FSL_TBCLK_EXTRA_DIV 609cb93071bSYork Sun #define CONFIG_FSL_TBCLK_EXTRA_DIV 1 610cb93071bSYork Sun #endif 611a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, 612cb93071bSYork Sun "timebase-frequency", get_tbclk() / CONFIG_FSL_TBCLK_EXTRA_DIV, 613cb93071bSYork Sun 1); 614a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, 615a47a12beSStefan Roese "bus-frequency", bd->bi_busfreq, 1); 616a47a12beSStefan Roese get_sys_info(&sysinfo); 617a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 618a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 61951abee64SLaurentiu TUDOR u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", &len); 62051abee64SLaurentiu TUDOR val = cpu_to_fdt32(sysinfo.freq_processor[(*reg) / (len / 4)]); 621a47a12beSStefan Roese fdt_setprop(blob, off, "clock-frequency", &val, 4); 622a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, "device_type", 623a47a12beSStefan Roese "cpu", 4); 624a47a12beSStefan Roese } 625a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "soc", 4, 626a47a12beSStefan Roese "bus-frequency", bd->bi_busfreq, 1); 627a47a12beSStefan Roese 628a47a12beSStefan Roese #ifdef CONFIG_QE 629a47a12beSStefan Roese ft_qe_setup(blob); 630a47a12beSStefan Roese ft_fixup_qe_snum(blob); 631a47a12beSStefan Roese #endif 632a47a12beSStefan Roese 633075affb1SQianyu Gong #ifdef CONFIG_SYS_DPAA_FMAN 634ffadc441STimur Tabi fdt_fixup_fman_firmware(blob); 635075affb1SQianyu Gong #endif 636ffadc441STimur Tabi 637a47a12beSStefan Roese #ifdef CONFIG_SYS_NS16550 638a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "ns16550", 639a47a12beSStefan Roese "clock-frequency", CONFIG_SYS_NS16550_CLK, 1); 640a47a12beSStefan Roese #endif 641a47a12beSStefan Roese 642a47a12beSStefan Roese #ifdef CONFIG_CPM2 643a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,cpm2-scc-uart", 6448e261575SMasahiro Yamada "current-speed", gd->baudrate, 1); 645a47a12beSStefan Roese 646a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,cpm2-brg", 647a47a12beSStefan Roese "clock-frequency", bd->bi_brgfreq, 1); 648a47a12beSStefan Roese #endif 649a47a12beSStefan Roese 65085f8cda3SKumar Gala #ifdef CONFIG_FSL_CORENET 65185f8cda3SKumar Gala do_fixup_by_compat_u32(blob, "fsl,qoriq-clockgen-1.0", 65285f8cda3SKumar Gala "clock-frequency", CONFIG_SYS_CLK_FREQ, 1); 6537dd09b54SAndy Fleming do_fixup_by_compat_u32(blob, "fsl,qoriq-clockgen-2.0", 6547b700d21STang Yuantian "clock-frequency", CONFIG_SYS_CLK_FREQ, 1); 655f5c2623dSDongsheng.wang@freescale.com do_fixup_by_compat_u32(blob, "fsl,mpic", 656f5c2623dSDongsheng.wang@freescale.com "clock-frequency", get_bus_freq(0)/2, 1); 657f5c2623dSDongsheng.wang@freescale.com #else 658f5c2623dSDongsheng.wang@freescale.com do_fixup_by_compat_u32(blob, "fsl,mpic", 659f5c2623dSDongsheng.wang@freescale.com "clock-frequency", get_bus_freq(0), 1); 66085f8cda3SKumar Gala #endif 66185f8cda3SKumar Gala 662a47a12beSStefan Roese fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize); 663a47a12beSStefan Roese 664a47a12beSStefan Roese #ifdef CONFIG_MP 665a47a12beSStefan Roese ft_fixup_cpu(blob, (u64)bd->bi_memstart + (u64)bd->bi_memsize); 666a47a12beSStefan Roese ft_fixup_num_cores(blob); 6678f3a7fa4SKumar Gala #endif 668a47a12beSStefan Roese 669a47a12beSStefan Roese ft_fixup_cache(blob); 670a47a12beSStefan Roese 671a47a12beSStefan Roese #if defined(CONFIG_FSL_ESDHC) 672a47a12beSStefan Roese fdt_fixup_esdhc(blob, bd); 673a47a12beSStefan Roese #endif 674a47a12beSStefan Roese 675a47a12beSStefan Roese ft_fixup_dpaa_clks(blob); 676db977abfSKumar Gala 677db977abfSKumar Gala #if defined(CONFIG_SYS_BMAN_MEM_PHYS) 678db977abfSKumar Gala fdt_portal(blob, "fsl,bman-portal", "bman-portals", 679db977abfSKumar Gala (u64)CONFIG_SYS_BMAN_MEM_PHYS, 680db977abfSKumar Gala CONFIG_SYS_BMAN_MEM_SIZE); 6812a0ffb84SHaiying Wang fdt_fixup_bportals(blob); 682db977abfSKumar Gala #endif 683db977abfSKumar Gala 684db977abfSKumar Gala #if defined(CONFIG_SYS_QMAN_MEM_PHYS) 685db977abfSKumar Gala fdt_portal(blob, "fsl,qman-portal", "qman-portals", 686db977abfSKumar Gala (u64)CONFIG_SYS_QMAN_MEM_PHYS, 687db977abfSKumar Gala CONFIG_SYS_QMAN_MEM_SIZE); 688db977abfSKumar Gala 689db977abfSKumar Gala fdt_fixup_qportals(blob); 690db977abfSKumar Gala #endif 691a09b9b68SKumar Gala 692a09b9b68SKumar Gala #ifdef CONFIG_SYS_SRIO 693a09b9b68SKumar Gala ft_srio_setup(blob); 694a09b9b68SKumar Gala #endif 695f5feb5afSbhaskar upadhaya 696f5feb5afSbhaskar upadhaya /* 697f5feb5afSbhaskar upadhaya * system-clock = CCB clock/2 698f5feb5afSbhaskar upadhaya * Here gd->bus_clk = CCB clock 699f5feb5afSbhaskar upadhaya * We are using the system clock as 1588 Timer reference 700f5feb5afSbhaskar upadhaya * clock source select 701f5feb5afSbhaskar upadhaya */ 702f5feb5afSbhaskar upadhaya do_fixup_by_compat_u32(blob, "fsl,gianfar-ptp-timer", 703f5feb5afSbhaskar upadhaya "timer-frequency", gd->bus_clk/2, 1); 70465bb8b06SBhaskar Upadhaya 70533c87536SJia Hongtao /* 70633c87536SJia Hongtao * clock-freq should change to clock-frequency and 70733c87536SJia Hongtao * flexcan-v1.0 should change to p1010-flexcan respectively 70833c87536SJia Hongtao * in the future. 70933c87536SJia Hongtao */ 71065bb8b06SBhaskar Upadhaya do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0", 71133c87536SJia Hongtao "clock_freq", gd->bus_clk/2, 1); 71233c87536SJia Hongtao 71333c87536SJia Hongtao do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0", 71433c87536SJia Hongtao "clock-frequency", gd->bus_clk/2, 1); 71533c87536SJia Hongtao 71633c87536SJia Hongtao do_fixup_by_compat_u32(blob, "fsl,p1010-flexcan", 71733c87536SJia Hongtao "clock-frequency", gd->bus_clk/2, 1); 718f81f19faSShengzhou Liu 719f81f19faSShengzhou Liu fdt_fixup_usb(blob); 720d616fc58SCodrin Ciubotariu 721d616fc58SCodrin Ciubotariu fdt_fixup_l2_switch(blob); 722605714f6SShengzhou Liu 723605714f6SShengzhou Liu fdt_fixup_dma3(blob); 724a47a12beSStefan Roese } 72590f89f09STimur Tabi 72690f89f09STimur Tabi /* 72790f89f09STimur Tabi * For some CCSR devices, we only have the virtual address, not the physical 72890f89f09STimur Tabi * address. This is because we map CCSR as a whole, so we typically don't need 72990f89f09STimur Tabi * a macro for the physical address of any device within CCSR. In this case, 73090f89f09STimur Tabi * we calculate the physical address of that device using it's the difference 73190f89f09STimur Tabi * between the virtual address of the device and the virtual address of the 73290f89f09STimur Tabi * beginning of CCSR. 73390f89f09STimur Tabi */ 73490f89f09STimur Tabi #define CCSR_VIRT_TO_PHYS(x) \ 73590f89f09STimur Tabi (CONFIG_SYS_CCSRBAR_PHYS + ((x) - CONFIG_SYS_CCSRBAR)) 73690f89f09STimur Tabi 737cc15df57STimur Tabi static void msg(const char *name, uint64_t uaddr, uint64_t daddr) 738cc15df57STimur Tabi { 739cc15df57STimur Tabi printf("Warning: U-Boot configured %s at address %llx,\n" 740cc15df57STimur Tabi "but the device tree has it at %llx\n", name, uaddr, daddr); 741cc15df57STimur Tabi } 742cc15df57STimur Tabi 74390f89f09STimur Tabi /* 74490f89f09STimur Tabi * Verify the device tree 74590f89f09STimur Tabi * 74690f89f09STimur Tabi * This function compares several CONFIG_xxx macros that contain physical 74790f89f09STimur Tabi * addresses with the corresponding nodes in the device tree, to see if 74890f89f09STimur Tabi * the physical addresses are all correct. For example, if 74990f89f09STimur Tabi * CONFIG_SYS_NS16550_COM1 is defined, then it contains the virtual address 75090f89f09STimur Tabi * of the first UART. We convert this to a physical address and compare 75190f89f09STimur Tabi * that with the physical address of the first ns16550-compatible node 75290f89f09STimur Tabi * in the device tree. If they don't match, then we display a warning. 75390f89f09STimur Tabi * 75490f89f09STimur Tabi * Returns 1 on success, 0 on failure 75590f89f09STimur Tabi */ 75690f89f09STimur Tabi int ft_verify_fdt(void *fdt) 75790f89f09STimur Tabi { 758cc15df57STimur Tabi uint64_t addr = 0; 75990f89f09STimur Tabi int aliases; 76090f89f09STimur Tabi int off; 76190f89f09STimur Tabi 76290f89f09STimur Tabi /* First check the CCSR base address */ 76390f89f09STimur Tabi off = fdt_node_offset_by_prop_value(fdt, -1, "device_type", "soc", 4); 76490f89f09STimur Tabi if (off > 0) 765cc15df57STimur Tabi addr = fdt_get_base_address(fdt, off); 76690f89f09STimur Tabi 767cc15df57STimur Tabi if (!addr) { 76890f89f09STimur Tabi printf("Warning: could not determine base CCSR address in " 76990f89f09STimur Tabi "device tree\n"); 77090f89f09STimur Tabi /* No point in checking anything else */ 77190f89f09STimur Tabi return 0; 77290f89f09STimur Tabi } 77390f89f09STimur Tabi 774cc15df57STimur Tabi if (addr != CONFIG_SYS_CCSRBAR_PHYS) { 775cc15df57STimur Tabi msg("CCSR", CONFIG_SYS_CCSRBAR_PHYS, addr); 77690f89f09STimur Tabi /* No point in checking anything else */ 77790f89f09STimur Tabi return 0; 77890f89f09STimur Tabi } 77990f89f09STimur Tabi 78090f89f09STimur Tabi /* 781cc15df57STimur Tabi * Check some nodes via aliases. We assume that U-Boot and the device 782cc15df57STimur Tabi * tree enumerate the devices equally. E.g. the first serial port in 783cc15df57STimur Tabi * U-Boot is the same as "serial0" in the device tree. 78490f89f09STimur Tabi */ 78590f89f09STimur Tabi aliases = fdt_path_offset(fdt, "/aliases"); 78690f89f09STimur Tabi if (aliases > 0) { 78790f89f09STimur Tabi #ifdef CONFIG_SYS_NS16550_COM1 78890f89f09STimur Tabi if (!fdt_verify_alias_address(fdt, aliases, "serial0", 78990f89f09STimur Tabi CCSR_VIRT_TO_PHYS(CONFIG_SYS_NS16550_COM1))) 79090f89f09STimur Tabi return 0; 79190f89f09STimur Tabi #endif 79290f89f09STimur Tabi 79390f89f09STimur Tabi #ifdef CONFIG_SYS_NS16550_COM2 79490f89f09STimur Tabi if (!fdt_verify_alias_address(fdt, aliases, "serial1", 79590f89f09STimur Tabi CCSR_VIRT_TO_PHYS(CONFIG_SYS_NS16550_COM2))) 79690f89f09STimur Tabi return 0; 79790f89f09STimur Tabi #endif 79890f89f09STimur Tabi } 79990f89f09STimur Tabi 800cc15df57STimur Tabi /* 801cc15df57STimur Tabi * The localbus node is typically a root node, even though the lbc 802cc15df57STimur Tabi * controller is part of CCSR. If we were to put the lbc node under 803cc15df57STimur Tabi * the SOC node, then the 'ranges' property in the lbc node would 804cc15df57STimur Tabi * translate through the 'ranges' property of the parent SOC node, and 805cc15df57STimur Tabi * we don't want that. Since it's a separate node, it's possible for 806cc15df57STimur Tabi * the 'reg' property to be wrong, so check it here. For now, we 807cc15df57STimur Tabi * only check for "fsl,elbc" nodes. 808cc15df57STimur Tabi */ 809cc15df57STimur Tabi #ifdef CONFIG_SYS_LBC_ADDR 810cc15df57STimur Tabi off = fdt_node_offset_by_compatible(fdt, -1, "fsl,elbc"); 811cc15df57STimur Tabi if (off > 0) { 8128aa5ec6eSKim Phillips const fdt32_t *reg = fdt_getprop(fdt, off, "reg", NULL); 813cc15df57STimur Tabi if (reg) { 814cc15df57STimur Tabi uint64_t uaddr = CCSR_VIRT_TO_PHYS(CONFIG_SYS_LBC_ADDR); 815cc15df57STimur Tabi 816cc15df57STimur Tabi addr = fdt_translate_address(fdt, off, reg); 817cc15df57STimur Tabi if (uaddr != addr) { 818cc15df57STimur Tabi msg("the localbus", uaddr, addr); 819cc15df57STimur Tabi return 0; 820cc15df57STimur Tabi } 821cc15df57STimur Tabi } 822cc15df57STimur Tabi } 823cc15df57STimur Tabi #endif 824cc15df57STimur Tabi 82590f89f09STimur Tabi return 1; 82690f89f09STimur Tabi } 827d4683776SZhao Qiang 828d4683776SZhao Qiang void fdt_del_diu(void *blob) 829d4683776SZhao Qiang { 830d4683776SZhao Qiang int nodeoff = 0; 831d4683776SZhao Qiang 832d4683776SZhao Qiang while ((nodeoff = fdt_node_offset_by_compatible(blob, 0, 833d4683776SZhao Qiang "fsl,diu")) >= 0) { 834d4683776SZhao Qiang fdt_del_node(blob, nodeoff); 835d4683776SZhao Qiang } 836d4683776SZhao Qiang } 837