1a47a12beSStefan Roese /* 2a09b9b68SKumar Gala * Copyright 2007-2011 Freescale Semiconductor, Inc. 3a47a12beSStefan Roese * 4a47a12beSStefan Roese * (C) Copyright 2000 5a47a12beSStefan Roese * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 6a47a12beSStefan Roese * 7a47a12beSStefan Roese * See file CREDITS for list of people who contributed to this 8a47a12beSStefan Roese * project. 9a47a12beSStefan Roese * 10a47a12beSStefan Roese * This program is free software; you can redistribute it and/or 11a47a12beSStefan Roese * modify it under the terms of the GNU General Public License as 12a47a12beSStefan Roese * published by the Free Software Foundation; either version 2 of 13a47a12beSStefan Roese * the License, or (at your option) any later version. 14a47a12beSStefan Roese * 15a47a12beSStefan Roese * This program is distributed in the hope that it will be useful, 16a47a12beSStefan Roese * but WITHOUT ANY WARRANTY; without even the implied warranty of 17a47a12beSStefan Roese * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18a47a12beSStefan Roese * GNU General Public License for more details. 19a47a12beSStefan Roese * 20a47a12beSStefan Roese * You should have received a copy of the GNU General Public License 21a47a12beSStefan Roese * along with this program; if not, write to the Free Software 22a47a12beSStefan Roese * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 23a47a12beSStefan Roese * MA 02111-1307 USA 24a47a12beSStefan Roese */ 25a47a12beSStefan Roese 26a47a12beSStefan Roese #include <common.h> 27a47a12beSStefan Roese #include <libfdt.h> 28a47a12beSStefan Roese #include <fdt_support.h> 29a47a12beSStefan Roese #include <asm/processor.h> 30a47a12beSStefan Roese #include <linux/ctype.h> 316aba33e9SKumar Gala #include <asm/io.h> 32db977abfSKumar Gala #include <asm/fsl_portals.h> 33a47a12beSStefan Roese #ifdef CONFIG_FSL_ESDHC 34a47a12beSStefan Roese #include <fsl_esdhc.h> 35a47a12beSStefan Roese #endif 36ffadc441STimur Tabi #include "../../../../drivers/qe/qe.h" /* For struct qe_firmware */ 37a47a12beSStefan Roese 38a47a12beSStefan Roese DECLARE_GLOBAL_DATA_PTR; 39a47a12beSStefan Roese 40a47a12beSStefan Roese extern void ft_qe_setup(void *blob); 41a47a12beSStefan Roese extern void ft_fixup_num_cores(void *blob); 42a09b9b68SKumar Gala extern void ft_srio_setup(void *blob); 43a47a12beSStefan Roese 44a47a12beSStefan Roese #ifdef CONFIG_MP 45a47a12beSStefan Roese #include "mp.h" 46a47a12beSStefan Roese 47a47a12beSStefan Roese void ft_fixup_cpu(void *blob, u64 memory_limit) 48a47a12beSStefan Roese { 49a47a12beSStefan Roese int off; 50a47a12beSStefan Roese ulong spin_tbl_addr = get_spin_phys_addr(); 51a47a12beSStefan Roese u32 bootpg = determine_mp_bootpg(); 52a47a12beSStefan Roese u32 id = get_my_id(); 539d64c6bbSAaron Sierra const char *enable_method; 54a47a12beSStefan Roese 55a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 56a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 57a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 58a47a12beSStefan Roese 59a47a12beSStefan Roese if (reg) { 60a47a12beSStefan Roese u64 val = *reg * SIZE_BOOT_ENTRY + spin_tbl_addr; 61a47a12beSStefan Roese val = cpu_to_fdt32(val); 62b80d3054SMatthew McClintock if (*reg == id) { 63b80d3054SMatthew McClintock fdt_setprop_string(blob, off, "status", 64b80d3054SMatthew McClintock "okay"); 65b80d3054SMatthew McClintock } else { 66a47a12beSStefan Roese fdt_setprop_string(blob, off, "status", 67a47a12beSStefan Roese "disabled"); 68b80d3054SMatthew McClintock } 699d64c6bbSAaron Sierra 709d64c6bbSAaron Sierra if (hold_cores_in_reset(0)) { 719d64c6bbSAaron Sierra #ifdef CONFIG_FSL_CORENET 729d64c6bbSAaron Sierra /* Cores held in reset, use BRR to release */ 739d64c6bbSAaron Sierra enable_method = "fsl,brr-holdoff"; 749d64c6bbSAaron Sierra #else 759d64c6bbSAaron Sierra /* Cores held in reset, use EEBPCR to release */ 769d64c6bbSAaron Sierra enable_method = "fsl,eebpcr-holdoff"; 779d64c6bbSAaron Sierra #endif 789d64c6bbSAaron Sierra } else { 799d64c6bbSAaron Sierra /* Cores out of reset and in a spin-loop */ 809d64c6bbSAaron Sierra enable_method = "spin-table"; 819d64c6bbSAaron Sierra 82a47a12beSStefan Roese fdt_setprop(blob, off, "cpu-release-addr", 83a47a12beSStefan Roese &val, sizeof(val)); 849d64c6bbSAaron Sierra } 859d64c6bbSAaron Sierra 869d64c6bbSAaron Sierra fdt_setprop_string(blob, off, "enable-method", 879d64c6bbSAaron Sierra enable_method); 88a47a12beSStefan Roese } else { 89a47a12beSStefan Roese printf ("cpu NULL\n"); 90a47a12beSStefan Roese } 91a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, 92a47a12beSStefan Roese "device_type", "cpu", 4); 93a47a12beSStefan Roese } 94a47a12beSStefan Roese 95a47a12beSStefan Roese /* Reserve the boot page so OSes dont use it */ 96a47a12beSStefan Roese if ((u64)bootpg < memory_limit) { 97a47a12beSStefan Roese off = fdt_add_mem_rsv(blob, bootpg, (u64)4096); 98a47a12beSStefan Roese if (off < 0) 99a47a12beSStefan Roese printf("%s: %s\n", __FUNCTION__, fdt_strerror(off)); 100a47a12beSStefan Roese } 101a47a12beSStefan Roese } 102a47a12beSStefan Roese #endif 103a47a12beSStefan Roese 1046aba33e9SKumar Gala #ifdef CONFIG_SYS_FSL_CPC 1056aba33e9SKumar Gala static inline void ft_fixup_l3cache(void *blob, int off) 1066aba33e9SKumar Gala { 1076aba33e9SKumar Gala u32 line_size, num_ways, size, num_sets; 1086aba33e9SKumar Gala cpc_corenet_t *cpc = (void *)CONFIG_SYS_FSL_CPC_ADDR; 1096aba33e9SKumar Gala u32 cfg0 = in_be32(&cpc->cpccfg0); 1106aba33e9SKumar Gala 1116aba33e9SKumar Gala size = CPC_CFG0_SZ_K(cfg0) * 1024 * CONFIG_SYS_NUM_CPC; 1126aba33e9SKumar Gala num_ways = CPC_CFG0_NUM_WAYS(cfg0); 1136aba33e9SKumar Gala line_size = CPC_CFG0_LINE_SZ(cfg0); 1146aba33e9SKumar Gala num_sets = size / (line_size * num_ways); 1156aba33e9SKumar Gala 1166aba33e9SKumar Gala fdt_setprop(blob, off, "cache-unified", NULL, 0); 1176aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-block-size", line_size); 1186aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-size", size); 1196aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-sets", num_sets); 1206aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-level", 3); 1216aba33e9SKumar Gala #ifdef CONFIG_SYS_CACHE_STASHING 1226aba33e9SKumar Gala fdt_setprop_cell(blob, off, "cache-stash-id", 1); 1236aba33e9SKumar Gala #endif 1246aba33e9SKumar Gala } 1256aba33e9SKumar Gala #else 126a47a12beSStefan Roese #define ft_fixup_l3cache(x, y) 1276aba33e9SKumar Gala #endif 128a47a12beSStefan Roese 129a47a12beSStefan Roese #if defined(CONFIG_L2_CACHE) 130a47a12beSStefan Roese /* return size in kilobytes */ 131a47a12beSStefan Roese static inline u32 l2cache_size(void) 132a47a12beSStefan Roese { 133a47a12beSStefan Roese volatile ccsr_l2cache_t *l2cache = (void *)CONFIG_SYS_MPC85xx_L2_ADDR; 134a47a12beSStefan Roese volatile u32 l2siz_field = (l2cache->l2ctl >> 28) & 0x3; 135a47a12beSStefan Roese u32 ver = SVR_SOC_VER(get_svr()); 136a47a12beSStefan Roese 137a47a12beSStefan Roese switch (l2siz_field) { 138a47a12beSStefan Roese case 0x0: 139a47a12beSStefan Roese break; 140a47a12beSStefan Roese case 0x1: 141a47a12beSStefan Roese if (ver == SVR_8540 || ver == SVR_8560 || 142a47a12beSStefan Roese ver == SVR_8541 || ver == SVR_8541_E || 143a47a12beSStefan Roese ver == SVR_8555 || ver == SVR_8555_E) 144a47a12beSStefan Roese return 128; 145a47a12beSStefan Roese else 146a47a12beSStefan Roese return 256; 147a47a12beSStefan Roese break; 148a47a12beSStefan Roese case 0x2: 149a47a12beSStefan Roese if (ver == SVR_8540 || ver == SVR_8560 || 150a47a12beSStefan Roese ver == SVR_8541 || ver == SVR_8541_E || 151a47a12beSStefan Roese ver == SVR_8555 || ver == SVR_8555_E) 152a47a12beSStefan Roese return 256; 153a47a12beSStefan Roese else 154a47a12beSStefan Roese return 512; 155a47a12beSStefan Roese break; 156a47a12beSStefan Roese case 0x3: 157a47a12beSStefan Roese return 1024; 158a47a12beSStefan Roese break; 159a47a12beSStefan Roese } 160a47a12beSStefan Roese 161a47a12beSStefan Roese return 0; 162a47a12beSStefan Roese } 163a47a12beSStefan Roese 164a47a12beSStefan Roese static inline void ft_fixup_l2cache(void *blob) 165a47a12beSStefan Roese { 166a47a12beSStefan Roese int len, off; 167a47a12beSStefan Roese u32 *ph; 168a47a12beSStefan Roese struct cpu_type *cpu = identify_cpu(SVR_SOC_VER(get_svr())); 169a47a12beSStefan Roese 170a47a12beSStefan Roese const u32 line_size = 32; 171a47a12beSStefan Roese const u32 num_ways = 8; 172a47a12beSStefan Roese const u32 size = l2cache_size() * 1024; 173a47a12beSStefan Roese const u32 num_sets = size / (line_size * num_ways); 174a47a12beSStefan Roese 175a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 176a47a12beSStefan Roese if (off < 0) { 177a47a12beSStefan Roese debug("no cpu node fount\n"); 178a47a12beSStefan Roese return; 179a47a12beSStefan Roese } 180a47a12beSStefan Roese 181a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0); 182a47a12beSStefan Roese 183a47a12beSStefan Roese if (ph == NULL) { 184a47a12beSStefan Roese debug("no next-level-cache property\n"); 185a47a12beSStefan Roese return ; 186a47a12beSStefan Roese } 187a47a12beSStefan Roese 188a47a12beSStefan Roese off = fdt_node_offset_by_phandle(blob, *ph); 189a47a12beSStefan Roese if (off < 0) { 190a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off)); 191a47a12beSStefan Roese return ; 192a47a12beSStefan Roese } 193a47a12beSStefan Roese 194a47a12beSStefan Roese if (cpu) { 195ee4756d4STimur Tabi char buf[40]; 196a47a12beSStefan Roese 197ee4756d4STimur Tabi if (isdigit(cpu->name[0])) { 198ee4756d4STimur Tabi /* MPCxxxx, where xxxx == 4-digit number */ 199ee4756d4STimur Tabi len = sprintf(buf, "fsl,mpc%s-l2-cache-controller", 200ee4756d4STimur Tabi cpu->name) + 1; 201ee4756d4STimur Tabi } else { 202ee4756d4STimur Tabi /* Pxxxx or Txxxx, where xxxx == 4-digit number */ 203ee4756d4STimur Tabi len = sprintf(buf, "fsl,%c%s-l2-cache-controller", 204ee4756d4STimur Tabi tolower(cpu->name[0]), cpu->name + 1) + 1; 205ee4756d4STimur Tabi } 206ee4756d4STimur Tabi 207ee4756d4STimur Tabi /* 208ee4756d4STimur Tabi * append "cache" after the NULL character that the previous 209ee4756d4STimur Tabi * sprintf wrote. This is how a device tree stores multiple 210ee4756d4STimur Tabi * strings in a property. 211ee4756d4STimur Tabi */ 212ee4756d4STimur Tabi len += sprintf(buf + len, "cache") + 1; 213ee4756d4STimur Tabi 214ee4756d4STimur Tabi fdt_setprop(blob, off, "compatible", buf, len); 215a47a12beSStefan Roese } 216a47a12beSStefan Roese fdt_setprop(blob, off, "cache-unified", NULL, 0); 217a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-block-size", line_size); 218a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-size", size); 219a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-sets", num_sets); 220a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-level", 2); 221a47a12beSStefan Roese 222a47a12beSStefan Roese /* we dont bother w/L3 since no platform of this type has one */ 223a47a12beSStefan Roese } 224a47a12beSStefan Roese #elif defined(CONFIG_BACKSIDE_L2_CACHE) 225a47a12beSStefan Roese static inline void ft_fixup_l2cache(void *blob) 226a47a12beSStefan Roese { 227a47a12beSStefan Roese int off, l2_off, l3_off = -1; 228a47a12beSStefan Roese u32 *ph; 229a47a12beSStefan Roese u32 l2cfg0 = mfspr(SPRN_L2CFG0); 230a47a12beSStefan Roese u32 size, line_size, num_ways, num_sets; 231acf3f8daSKumar Gala int has_l2 = 1; 232acf3f8daSKumar Gala 233acf3f8daSKumar Gala /* P2040/P2040E has no L2, so dont set any L2 props */ 234acf3f8daSKumar Gala if ((SVR_SOC_VER(get_svr()) == SVR_P2040) || 235acf3f8daSKumar Gala (SVR_SOC_VER(get_svr()) == SVR_P2040_E)) 236acf3f8daSKumar Gala has_l2 = 0; 237a47a12beSStefan Roese 238a47a12beSStefan Roese size = (l2cfg0 & 0x3fff) * 64 * 1024; 239a47a12beSStefan Roese num_ways = ((l2cfg0 >> 14) & 0x1f) + 1; 240a47a12beSStefan Roese line_size = (((l2cfg0 >> 23) & 0x3) + 1) * 32; 241a47a12beSStefan Roese num_sets = size / (line_size * num_ways); 242a47a12beSStefan Roese 243a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 244a47a12beSStefan Roese 245a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 246a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, off, "next-level-cache", 0); 247a47a12beSStefan Roese 248a47a12beSStefan Roese if (ph == NULL) { 249a47a12beSStefan Roese debug("no next-level-cache property\n"); 250a47a12beSStefan Roese goto next; 251a47a12beSStefan Roese } 252a47a12beSStefan Roese 253a47a12beSStefan Roese l2_off = fdt_node_offset_by_phandle(blob, *ph); 254a47a12beSStefan Roese if (l2_off < 0) { 255a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off)); 256a47a12beSStefan Roese goto next; 257a47a12beSStefan Roese } 258a47a12beSStefan Roese 259acf3f8daSKumar Gala if (has_l2) { 260a47a12beSStefan Roese #ifdef CONFIG_SYS_CACHE_STASHING 261a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 262a47a12beSStefan Roese if (reg) 263a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-stash-id", 264a47a12beSStefan Roese (*reg * 2) + 32 + 1); 265a47a12beSStefan Roese #endif 266a47a12beSStefan Roese 267a47a12beSStefan Roese fdt_setprop(blob, l2_off, "cache-unified", NULL, 0); 268acf3f8daSKumar Gala fdt_setprop_cell(blob, l2_off, "cache-block-size", 269acf3f8daSKumar Gala line_size); 270a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-size", size); 271a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-sets", num_sets); 272a47a12beSStefan Roese fdt_setprop_cell(blob, l2_off, "cache-level", 2); 273a47a12beSStefan Roese fdt_setprop(blob, l2_off, "compatible", "cache", 6); 274acf3f8daSKumar Gala } 275a47a12beSStefan Roese 276a47a12beSStefan Roese if (l3_off < 0) { 277a47a12beSStefan Roese ph = (u32 *)fdt_getprop(blob, l2_off, "next-level-cache", 0); 278a47a12beSStefan Roese 279a47a12beSStefan Roese if (ph == NULL) { 280a47a12beSStefan Roese debug("no next-level-cache property\n"); 281a47a12beSStefan Roese goto next; 282a47a12beSStefan Roese } 283a47a12beSStefan Roese l3_off = *ph; 284a47a12beSStefan Roese } 285a47a12beSStefan Roese next: 286a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, 287a47a12beSStefan Roese "device_type", "cpu", 4); 288a47a12beSStefan Roese } 289a47a12beSStefan Roese if (l3_off > 0) { 290a47a12beSStefan Roese l3_off = fdt_node_offset_by_phandle(blob, l3_off); 291a47a12beSStefan Roese if (l3_off < 0) { 292a47a12beSStefan Roese printf("%s: %s\n", __func__, fdt_strerror(off)); 293a47a12beSStefan Roese return ; 294a47a12beSStefan Roese } 295a47a12beSStefan Roese ft_fixup_l3cache(blob, l3_off); 296a47a12beSStefan Roese } 297a47a12beSStefan Roese } 298a47a12beSStefan Roese #else 299a47a12beSStefan Roese #define ft_fixup_l2cache(x) 300a47a12beSStefan Roese #endif 301a47a12beSStefan Roese 302a47a12beSStefan Roese static inline void ft_fixup_cache(void *blob) 303a47a12beSStefan Roese { 304a47a12beSStefan Roese int off; 305a47a12beSStefan Roese 306a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 307a47a12beSStefan Roese 308a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 309a47a12beSStefan Roese u32 l1cfg0 = mfspr(SPRN_L1CFG0); 310a47a12beSStefan Roese u32 l1cfg1 = mfspr(SPRN_L1CFG1); 311a47a12beSStefan Roese u32 isize, iline_size, inum_sets, inum_ways; 312a47a12beSStefan Roese u32 dsize, dline_size, dnum_sets, dnum_ways; 313a47a12beSStefan Roese 314a47a12beSStefan Roese /* d-side config */ 315a47a12beSStefan Roese dsize = (l1cfg0 & 0x7ff) * 1024; 316a47a12beSStefan Roese dnum_ways = ((l1cfg0 >> 11) & 0xff) + 1; 317a47a12beSStefan Roese dline_size = (((l1cfg0 >> 23) & 0x3) + 1) * 32; 318a47a12beSStefan Roese dnum_sets = dsize / (dline_size * dnum_ways); 319a47a12beSStefan Roese 320a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-block-size", dline_size); 321a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-size", dsize); 322a47a12beSStefan Roese fdt_setprop_cell(blob, off, "d-cache-sets", dnum_sets); 323a47a12beSStefan Roese 324a47a12beSStefan Roese #ifdef CONFIG_SYS_CACHE_STASHING 325a47a12beSStefan Roese { 326a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 327a47a12beSStefan Roese if (reg) 328a47a12beSStefan Roese fdt_setprop_cell(blob, off, "cache-stash-id", 329a47a12beSStefan Roese (*reg * 2) + 32 + 0); 330a47a12beSStefan Roese } 331a47a12beSStefan Roese #endif 332a47a12beSStefan Roese 333a47a12beSStefan Roese /* i-side config */ 334a47a12beSStefan Roese isize = (l1cfg1 & 0x7ff) * 1024; 335a47a12beSStefan Roese inum_ways = ((l1cfg1 >> 11) & 0xff) + 1; 336a47a12beSStefan Roese iline_size = (((l1cfg1 >> 23) & 0x3) + 1) * 32; 337a47a12beSStefan Roese inum_sets = isize / (iline_size * inum_ways); 338a47a12beSStefan Roese 339a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-block-size", iline_size); 340a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-size", isize); 341a47a12beSStefan Roese fdt_setprop_cell(blob, off, "i-cache-sets", inum_sets); 342a47a12beSStefan Roese 343a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, 344a47a12beSStefan Roese "device_type", "cpu", 4); 345a47a12beSStefan Roese } 346a47a12beSStefan Roese 347a47a12beSStefan Roese ft_fixup_l2cache(blob); 348a47a12beSStefan Roese } 349a47a12beSStefan Roese 350a47a12beSStefan Roese 351a47a12beSStefan Roese void fdt_add_enet_stashing(void *fdt) 352a47a12beSStefan Roese { 353a47a12beSStefan Roese do_fixup_by_compat(fdt, "gianfar", "bd-stash", NULL, 0, 1); 354a47a12beSStefan Roese 355a47a12beSStefan Roese do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-len", 96, 1); 356a47a12beSStefan Roese 357a47a12beSStefan Roese do_fixup_by_compat_u32(fdt, "gianfar", "rx-stash-idx", 0, 1); 358eea9a123SPankaj Chauhan do_fixup_by_compat(fdt, "fsl,etsec2", "bd-stash", NULL, 0, 1); 359eea9a123SPankaj Chauhan do_fixup_by_compat_u32(fdt, "fsl,etsec2", "rx-stash-len", 96, 1); 360eea9a123SPankaj Chauhan do_fixup_by_compat_u32(fdt, "fsl,etsec2", "rx-stash-idx", 0, 1); 361a47a12beSStefan Roese } 362a47a12beSStefan Roese 363a47a12beSStefan Roese #if defined(CONFIG_SYS_DPAA_FMAN) || defined(CONFIG_SYS_DPAA_PME) 3641b942f74SKumar Gala static void ft_fixup_clks(void *blob, const char *compat, u32 offset, 3651b942f74SKumar Gala unsigned long freq) 366a47a12beSStefan Roese { 3671b942f74SKumar Gala phys_addr_t phys = offset + CONFIG_SYS_CCSRBAR_PHYS; 3681b942f74SKumar Gala int off = fdt_node_offset_by_compat_reg(blob, compat, phys); 369a47a12beSStefan Roese 370a47a12beSStefan Roese if (off >= 0) { 371a47a12beSStefan Roese off = fdt_setprop_cell(blob, off, "clock-frequency", freq); 372a47a12beSStefan Roese if (off > 0) 373a47a12beSStefan Roese printf("WARNING enable to set clock-frequency " 3741b942f74SKumar Gala "for %s: %s\n", compat, fdt_strerror(off)); 375a47a12beSStefan Roese } 376a47a12beSStefan Roese } 377a47a12beSStefan Roese 378a47a12beSStefan Roese static void ft_fixup_dpaa_clks(void *blob) 379a47a12beSStefan Roese { 380a47a12beSStefan Roese sys_info_t sysinfo; 381a47a12beSStefan Roese 382a47a12beSStefan Roese get_sys_info(&sysinfo); 3831b942f74SKumar Gala ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM1_OFFSET, 3841b942f74SKumar Gala sysinfo.freqFMan[0]); 385a47a12beSStefan Roese 386a47a12beSStefan Roese #if (CONFIG_SYS_NUM_FMAN == 2) 3871b942f74SKumar Gala ft_fixup_clks(blob, "fsl,fman", CONFIG_SYS_FSL_FM2_OFFSET, 3881b942f74SKumar Gala sysinfo.freqFMan[1]); 389a47a12beSStefan Roese #endif 390a47a12beSStefan Roese 391a47a12beSStefan Roese #ifdef CONFIG_SYS_DPAA_PME 3921b942f74SKumar Gala do_fixup_by_compat_u32(blob, "fsl,pme", 3931b942f74SKumar Gala "clock-frequency", sysinfo.freqPME, 1); 394a47a12beSStefan Roese #endif 395a47a12beSStefan Roese } 396a47a12beSStefan Roese #else 397a47a12beSStefan Roese #define ft_fixup_dpaa_clks(x) 398a47a12beSStefan Roese #endif 399a47a12beSStefan Roese 400a47a12beSStefan Roese #ifdef CONFIG_QE 401a47a12beSStefan Roese static void ft_fixup_qe_snum(void *blob) 402a47a12beSStefan Roese { 403a47a12beSStefan Roese unsigned int svr; 404a47a12beSStefan Roese 405a47a12beSStefan Roese svr = mfspr(SPRN_SVR); 406a47a12beSStefan Roese if (SVR_SOC_VER(svr) == SVR_8569_E) { 407a47a12beSStefan Roese if(IS_SVR_REV(svr, 1, 0)) 408a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,qe", 409a47a12beSStefan Roese "fsl,qe-num-snums", 46, 1); 410a47a12beSStefan Roese else 411a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,qe", 412a47a12beSStefan Roese "fsl,qe-num-snums", 76, 1); 413a47a12beSStefan Roese } 414a47a12beSStefan Roese } 415a47a12beSStefan Roese #endif 416a47a12beSStefan Roese 417ffadc441STimur Tabi /** 418ffadc441STimur Tabi * fdt_fixup_fman_firmware -- insert the Fman firmware into the device tree 419ffadc441STimur Tabi * 420ffadc441STimur Tabi * The binding for an Fman firmware node is documented in 421ffadc441STimur Tabi * Documentation/powerpc/dts-bindings/fsl/dpaa/fman.txt. This node contains 422ffadc441STimur Tabi * the actual Fman firmware binary data. The operating system is expected to 423ffadc441STimur Tabi * be able to parse the binary data to determine any attributes it needs. 424ffadc441STimur Tabi */ 425ffadc441STimur Tabi #ifdef CONFIG_SYS_DPAA_FMAN 426ffadc441STimur Tabi void fdt_fixup_fman_firmware(void *blob) 427ffadc441STimur Tabi { 428ffadc441STimur Tabi int rc, fmnode, fwnode = -1; 429ffadc441STimur Tabi uint32_t phandle; 430ffadc441STimur Tabi struct qe_firmware *fmanfw; 431ffadc441STimur Tabi const struct qe_header *hdr; 432ffadc441STimur Tabi unsigned int length; 433ffadc441STimur Tabi uint32_t crc; 434ffadc441STimur Tabi const char *p; 435ffadc441STimur Tabi 436ffadc441STimur Tabi /* The first Fman we find will contain the actual firmware. */ 437ffadc441STimur Tabi fmnode = fdt_node_offset_by_compatible(blob, -1, "fsl,fman"); 438ffadc441STimur Tabi if (fmnode < 0) 439ffadc441STimur Tabi /* Exit silently if there are no Fman devices */ 440ffadc441STimur Tabi return; 441ffadc441STimur Tabi 442ffadc441STimur Tabi /* If we already have a firmware node, then also exit silently. */ 443ffadc441STimur Tabi if (fdt_node_offset_by_compatible(blob, -1, "fsl,fman-firmware") > 0) 444ffadc441STimur Tabi return; 445ffadc441STimur Tabi 446ffadc441STimur Tabi /* If the environment variable is not set, then exit silently */ 447ffadc441STimur Tabi p = getenv("fman_ucode"); 448ffadc441STimur Tabi if (!p) 449ffadc441STimur Tabi return; 450ffadc441STimur Tabi 451ffadc441STimur Tabi fmanfw = (struct qe_firmware *) simple_strtoul(p, NULL, 0); 452ffadc441STimur Tabi if (!fmanfw) 453ffadc441STimur Tabi return; 454ffadc441STimur Tabi 455ffadc441STimur Tabi hdr = &fmanfw->header; 456ffadc441STimur Tabi length = be32_to_cpu(hdr->length); 457ffadc441STimur Tabi 458ffadc441STimur Tabi /* Verify the firmware. */ 459ffadc441STimur Tabi if ((hdr->magic[0] != 'Q') || (hdr->magic[1] != 'E') || 460ffadc441STimur Tabi (hdr->magic[2] != 'F')) { 461ffadc441STimur Tabi printf("Data at %p is not an Fman firmware\n", fmanfw); 462ffadc441STimur Tabi return; 463ffadc441STimur Tabi } 464ffadc441STimur Tabi 465ffadc441STimur Tabi if (length > CONFIG_SYS_FMAN_FW_LENGTH) { 466ffadc441STimur Tabi printf("Fman firmware at %p is too large (size=%u)\n", 467ffadc441STimur Tabi fmanfw, length); 468ffadc441STimur Tabi return; 469ffadc441STimur Tabi } 470ffadc441STimur Tabi 471ffadc441STimur Tabi length -= sizeof(u32); /* Subtract the size of the CRC */ 472ffadc441STimur Tabi crc = be32_to_cpu(*(u32 *)((void *)fmanfw + length)); 473ffadc441STimur Tabi if (crc != crc32_no_comp(0, (void *)fmanfw, length)) { 474ffadc441STimur Tabi printf("Fman firmware at %p has invalid CRC\n", fmanfw); 475ffadc441STimur Tabi return; 476ffadc441STimur Tabi } 477ffadc441STimur Tabi 478ffadc441STimur Tabi /* Increase the size of the fdt to make room for the node. */ 479ffadc441STimur Tabi rc = fdt_increase_size(blob, fmanfw->header.length); 480ffadc441STimur Tabi if (rc < 0) { 481ffadc441STimur Tabi printf("Unable to make room for Fman firmware: %s\n", 482ffadc441STimur Tabi fdt_strerror(rc)); 483ffadc441STimur Tabi return; 484ffadc441STimur Tabi } 485ffadc441STimur Tabi 486ffadc441STimur Tabi /* Create the firmware node. */ 487ffadc441STimur Tabi fwnode = fdt_add_subnode(blob, fmnode, "fman-firmware"); 488ffadc441STimur Tabi if (fwnode < 0) { 489ffadc441STimur Tabi char s[64]; 490ffadc441STimur Tabi fdt_get_path(blob, fmnode, s, sizeof(s)); 491ffadc441STimur Tabi printf("Could not add firmware node to %s: %s\n", s, 492ffadc441STimur Tabi fdt_strerror(fwnode)); 493ffadc441STimur Tabi return; 494ffadc441STimur Tabi } 495ffadc441STimur Tabi rc = fdt_setprop_string(blob, fwnode, "compatible", "fsl,fman-firmware"); 496ffadc441STimur Tabi if (rc < 0) { 497ffadc441STimur Tabi char s[64]; 498ffadc441STimur Tabi fdt_get_path(blob, fwnode, s, sizeof(s)); 499ffadc441STimur Tabi printf("Could not add compatible property to node %s: %s\n", s, 500ffadc441STimur Tabi fdt_strerror(rc)); 501ffadc441STimur Tabi return; 502ffadc441STimur Tabi } 503ffadc441STimur Tabi phandle = fdt_alloc_phandle(blob); 504ffadc441STimur Tabi rc = fdt_setprop_cell(blob, fwnode, "linux,phandle", phandle); 505ffadc441STimur Tabi if (rc < 0) { 506ffadc441STimur Tabi char s[64]; 507ffadc441STimur Tabi fdt_get_path(blob, fwnode, s, sizeof(s)); 508ffadc441STimur Tabi printf("Could not add phandle property to node %s: %s\n", s, 509ffadc441STimur Tabi fdt_strerror(rc)); 510ffadc441STimur Tabi return; 511ffadc441STimur Tabi } 512ffadc441STimur Tabi rc = fdt_setprop(blob, fwnode, "fsl,firmware", fmanfw, fmanfw->header.length); 513ffadc441STimur Tabi if (rc < 0) { 514ffadc441STimur Tabi char s[64]; 515ffadc441STimur Tabi fdt_get_path(blob, fwnode, s, sizeof(s)); 516ffadc441STimur Tabi printf("Could not add firmware property to node %s: %s\n", s, 517ffadc441STimur Tabi fdt_strerror(rc)); 518ffadc441STimur Tabi return; 519ffadc441STimur Tabi } 520ffadc441STimur Tabi 521ffadc441STimur Tabi /* Find all other Fman nodes and point them to the firmware node. */ 522ffadc441STimur Tabi while ((fmnode = fdt_node_offset_by_compatible(blob, fmnode, "fsl,fman")) > 0) { 523ffadc441STimur Tabi rc = fdt_setprop_cell(blob, fmnode, "fsl,firmware-phandle", phandle); 524ffadc441STimur Tabi if (rc < 0) { 525ffadc441STimur Tabi char s[64]; 526ffadc441STimur Tabi fdt_get_path(blob, fmnode, s, sizeof(s)); 527ffadc441STimur Tabi printf("Could not add pointer property to node %s: %s\n", 528ffadc441STimur Tabi s, fdt_strerror(rc)); 529ffadc441STimur Tabi return; 530ffadc441STimur Tabi } 531ffadc441STimur Tabi } 532ffadc441STimur Tabi } 533ffadc441STimur Tabi #else 534ffadc441STimur Tabi #define fdt_fixup_fman_firmware(x) 535ffadc441STimur Tabi #endif 536ffadc441STimur Tabi 537a47a12beSStefan Roese void ft_cpu_setup(void *blob, bd_t *bd) 538a47a12beSStefan Roese { 539a47a12beSStefan Roese int off; 540a47a12beSStefan Roese int val; 541a47a12beSStefan Roese sys_info_t sysinfo; 542a47a12beSStefan Roese 543a47a12beSStefan Roese /* delete crypto node if not on an E-processor */ 544a47a12beSStefan Roese if (!IS_E_PROCESSOR(get_svr())) 545a47a12beSStefan Roese fdt_fixup_crypto_node(blob, 0); 546a47a12beSStefan Roese 547a47a12beSStefan Roese fdt_fixup_ethernet(blob); 548a47a12beSStefan Roese 549a47a12beSStefan Roese fdt_add_enet_stashing(blob); 550a47a12beSStefan Roese 551a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, 552a47a12beSStefan Roese "timebase-frequency", get_tbclk(), 1); 553a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, 554a47a12beSStefan Roese "bus-frequency", bd->bi_busfreq, 1); 555a47a12beSStefan Roese get_sys_info(&sysinfo); 556a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); 557a47a12beSStefan Roese while (off != -FDT_ERR_NOTFOUND) { 558a47a12beSStefan Roese u32 *reg = (u32 *)fdt_getprop(blob, off, "reg", 0); 559a47a12beSStefan Roese val = cpu_to_fdt32(sysinfo.freqProcessor[*reg]); 560a47a12beSStefan Roese fdt_setprop(blob, off, "clock-frequency", &val, 4); 561a47a12beSStefan Roese off = fdt_node_offset_by_prop_value(blob, off, "device_type", 562a47a12beSStefan Roese "cpu", 4); 563a47a12beSStefan Roese } 564a47a12beSStefan Roese do_fixup_by_prop_u32(blob, "device_type", "soc", 4, 565a47a12beSStefan Roese "bus-frequency", bd->bi_busfreq, 1); 566a47a12beSStefan Roese 567a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,pq3-localbus", 568a47a12beSStefan Roese "bus-frequency", gd->lbc_clk, 1); 569a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,elbc", 570a47a12beSStefan Roese "bus-frequency", gd->lbc_clk, 1); 571a47a12beSStefan Roese #ifdef CONFIG_QE 572a47a12beSStefan Roese ft_qe_setup(blob); 573a47a12beSStefan Roese ft_fixup_qe_snum(blob); 574a47a12beSStefan Roese #endif 575a47a12beSStefan Roese 576ffadc441STimur Tabi fdt_fixup_fman_firmware(blob); 577ffadc441STimur Tabi 578a47a12beSStefan Roese #ifdef CONFIG_SYS_NS16550 579a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "ns16550", 580a47a12beSStefan Roese "clock-frequency", CONFIG_SYS_NS16550_CLK, 1); 581a47a12beSStefan Roese #endif 582a47a12beSStefan Roese 583a47a12beSStefan Roese #ifdef CONFIG_CPM2 584a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,cpm2-scc-uart", 585a47a12beSStefan Roese "current-speed", bd->bi_baudrate, 1); 586a47a12beSStefan Roese 587a47a12beSStefan Roese do_fixup_by_compat_u32(blob, "fsl,cpm2-brg", 588a47a12beSStefan Roese "clock-frequency", bd->bi_brgfreq, 1); 589a47a12beSStefan Roese #endif 590a47a12beSStefan Roese 59185f8cda3SKumar Gala #ifdef CONFIG_FSL_CORENET 59285f8cda3SKumar Gala do_fixup_by_compat_u32(blob, "fsl,qoriq-clockgen-1.0", 59385f8cda3SKumar Gala "clock-frequency", CONFIG_SYS_CLK_FREQ, 1); 59485f8cda3SKumar Gala #endif 59585f8cda3SKumar Gala 596a47a12beSStefan Roese fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize); 597a47a12beSStefan Roese 598a47a12beSStefan Roese #ifdef CONFIG_MP 599a47a12beSStefan Roese ft_fixup_cpu(blob, (u64)bd->bi_memstart + (u64)bd->bi_memsize); 600a47a12beSStefan Roese ft_fixup_num_cores(blob); 6018f3a7fa4SKumar Gala #endif 602a47a12beSStefan Roese 603a47a12beSStefan Roese ft_fixup_cache(blob); 604a47a12beSStefan Roese 605a47a12beSStefan Roese #if defined(CONFIG_FSL_ESDHC) 606a47a12beSStefan Roese fdt_fixup_esdhc(blob, bd); 607a47a12beSStefan Roese #endif 608a47a12beSStefan Roese 609a47a12beSStefan Roese ft_fixup_dpaa_clks(blob); 610db977abfSKumar Gala 611db977abfSKumar Gala #if defined(CONFIG_SYS_BMAN_MEM_PHYS) 612db977abfSKumar Gala fdt_portal(blob, "fsl,bman-portal", "bman-portals", 613db977abfSKumar Gala (u64)CONFIG_SYS_BMAN_MEM_PHYS, 614db977abfSKumar Gala CONFIG_SYS_BMAN_MEM_SIZE); 6152a0ffb84SHaiying Wang fdt_fixup_bportals(blob); 616db977abfSKumar Gala #endif 617db977abfSKumar Gala 618db977abfSKumar Gala #if defined(CONFIG_SYS_QMAN_MEM_PHYS) 619db977abfSKumar Gala fdt_portal(blob, "fsl,qman-portal", "qman-portals", 620db977abfSKumar Gala (u64)CONFIG_SYS_QMAN_MEM_PHYS, 621db977abfSKumar Gala CONFIG_SYS_QMAN_MEM_SIZE); 622db977abfSKumar Gala 623db977abfSKumar Gala fdt_fixup_qportals(blob); 624db977abfSKumar Gala #endif 625a09b9b68SKumar Gala 626a09b9b68SKumar Gala #ifdef CONFIG_SYS_SRIO 627a09b9b68SKumar Gala ft_srio_setup(blob); 628a09b9b68SKumar Gala #endif 629f5feb5afSbhaskar upadhaya 630f5feb5afSbhaskar upadhaya /* 631f5feb5afSbhaskar upadhaya * system-clock = CCB clock/2 632f5feb5afSbhaskar upadhaya * Here gd->bus_clk = CCB clock 633f5feb5afSbhaskar upadhaya * We are using the system clock as 1588 Timer reference 634f5feb5afSbhaskar upadhaya * clock source select 635f5feb5afSbhaskar upadhaya */ 636f5feb5afSbhaskar upadhaya do_fixup_by_compat_u32(blob, "fsl,gianfar-ptp-timer", 637f5feb5afSbhaskar upadhaya "timer-frequency", gd->bus_clk/2, 1); 638*65bb8b06SBhaskar Upadhaya 639*65bb8b06SBhaskar Upadhaya do_fixup_by_compat_u32(blob, "fsl,flexcan-v1.0", 640*65bb8b06SBhaskar Upadhaya "clock_freq", gd->bus_clk, 1); 641a47a12beSStefan Roese } 642