1d1712369SKumar Gala /* 2561e710aSKumar Gala * Copyright 2009-2011 Freescale Semiconductor, Inc. 3d1712369SKumar Gala * 41a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+ 5d1712369SKumar Gala */ 6d1712369SKumar Gala 7d1712369SKumar Gala #include <common.h> 8d1712369SKumar Gala #include <command.h> 9d1712369SKumar Gala #include <netdev.h> 100e159024SLian Minghuan #include <linux/compiler.h> 11d1712369SKumar Gala #include <asm/mmu.h> 12d1712369SKumar Gala #include <asm/processor.h> 13d1712369SKumar Gala #include <asm/cache.h> 14d1712369SKumar Gala #include <asm/immap_85xx.h> 15d1712369SKumar Gala #include <asm/fsl_law.h> 16d1712369SKumar Gala #include <asm/fsl_serdes.h> 17d1712369SKumar Gala #include <asm/fsl_portals.h> 18d1712369SKumar Gala #include <asm/fsl_liodn.h> 192915609aSAndy Fleming #include <fm_eth.h> 20d1712369SKumar Gala 21d1712369SKumar Gala #include "../common/ngpixis.h" 222915609aSAndy Fleming #include "corenet_ds.h" 23d1712369SKumar Gala 24d1712369SKumar Gala DECLARE_GLOBAL_DATA_PTR; 25d1712369SKumar Gala 26d1712369SKumar Gala int checkboard (void) 27d1712369SKumar Gala { 28d1712369SKumar Gala u8 sw; 2967ac13b1SSimon Glass struct cpu_type *cpu = gd->arch.cpu; 30*f165bc35SYork Sun #if defined(CONFIG_P3041DS) || defined(CONFIG_P5020DS) || \ 31*f165bc35SYork Sun defined(CONFIG_P5040DS) 3246299078STimur Tabi unsigned int i; 33*f165bc35SYork Sun #endif 34d31e53b4STimur Tabi static const char * const freq[] = {"100", "125", "156.25", "212.5" }; 35d1712369SKumar Gala 36d1712369SKumar Gala printf("Board: %sDS, ", cpu->name); 37d1712369SKumar Gala printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ", 38d1712369SKumar Gala in_8(&pixis->id), in_8(&pixis->arch), in_8(&pixis->scver)); 39d1712369SKumar Gala 40d1712369SKumar Gala sw = in_8(&PIXIS_SW(PIXIS_LBMAP_SWITCH)); 41d1712369SKumar Gala sw = (sw & PIXIS_LBMAP_MASK) >> PIXIS_LBMAP_SHIFT; 42d1712369SKumar Gala 43d1712369SKumar Gala if (sw < 0x8) 44d1712369SKumar Gala printf("vBank: %d\n", sw); 45d1712369SKumar Gala else if (sw == 0x8) 46d1712369SKumar Gala puts("Promjet\n"); 47d1712369SKumar Gala else if (sw == 0x9) 48d1712369SKumar Gala puts("NAND\n"); 49d1712369SKumar Gala else 50d1712369SKumar Gala printf("invalid setting of SW%u\n", PIXIS_LBMAP_SWITCH); 51d1712369SKumar Gala 52d1712369SKumar Gala /* Display the actual SERDES reference clocks as configured by the 53d1712369SKumar Gala * dip switches on the board. Note that the SWx registers could 54d1712369SKumar Gala * technically be set to force the reference clocks to match the 55d1712369SKumar Gala * values that the SERDES expects (or vice versa). For now, however, 56d1712369SKumar Gala * we just display both values and hope the user notices when they 57d1712369SKumar Gala * don't match. 58d1712369SKumar Gala */ 59d1712369SKumar Gala puts("SERDES Reference Clocks: "); 60d31e53b4STimur Tabi #if defined(CONFIG_P3041DS) || defined(CONFIG_P5020DS) \ 61d31e53b4STimur Tabi || defined(CONFIG_P5040DS) 62e02aea61SKumar Gala sw = in_8(&PIXIS_SW(5)); 63e02aea61SKumar Gala for (i = 0; i < 3; i++) { 64e02aea61SKumar Gala unsigned int clock = (sw >> (6 - (2 * i))) & 3; 65e02aea61SKumar Gala 66e02aea61SKumar Gala printf("Bank%u=%sMhz ", i+1, freq[clock]); 67e02aea61SKumar Gala } 68d31e53b4STimur Tabi #ifdef CONFIG_P5040DS 69d31e53b4STimur Tabi /* On P5040DS, SW11[7:8] determines the Bank 4 frequency */ 70d31e53b4STimur Tabi sw = in_8(&PIXIS_SW(9)); 71d31e53b4STimur Tabi printf("Bank4=%sMhz ", freq[sw & 3]); 72d31e53b4STimur Tabi #endif 73e02aea61SKumar Gala puts("\n"); 74e02aea61SKumar Gala #else 75d1712369SKumar Gala sw = in_8(&PIXIS_SW(3)); 76d31e53b4STimur Tabi /* SW3[2]: 0 = 100 Mhz, 1 = 125 MHz */ 77d31e53b4STimur Tabi /* SW3[3]: 0 = 125 Mhz, 1 = 156.25 MHz */ 78d31e53b4STimur Tabi /* SW3[4]: 0 = 125 Mhz, 1 = 156.25 MHz */ 79d31e53b4STimur Tabi printf("Bank1=%sMHz ", freq[!!(sw & 0x40)]); 80d31e53b4STimur Tabi printf("Bank2=%sMHz ", freq[1 + !!(sw & 0x20)]); 81d31e53b4STimur Tabi printf("Bank3=%sMHz\n", freq[1 + !!(sw & 0x10)]); 82e02aea61SKumar Gala #endif 83d1712369SKumar Gala 84d1712369SKumar Gala return 0; 85d1712369SKumar Gala } 86d1712369SKumar Gala 87d1712369SKumar Gala int board_early_init_f(void) 88d1712369SKumar Gala { 89d1712369SKumar Gala volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); 90d1712369SKumar Gala 91d1712369SKumar Gala /* 92d1712369SKumar Gala * P4080 DS board only uses the DDR1_MCK0/3 and DDR2_MCK0/3 93d1712369SKumar Gala * disable the DDR1_MCK1/2/4/5 and DDR2_MCK1/2/4/5 to reduce 94d1712369SKumar Gala * the noise introduced by these unterminated and unused clock pairs. 95d1712369SKumar Gala */ 96d1712369SKumar Gala setbits_be32(&gur->ddrclkdr, 0x001B001B); 97d1712369SKumar Gala 98d1712369SKumar Gala return 0; 99d1712369SKumar Gala } 100d1712369SKumar Gala 101d1712369SKumar Gala int board_early_init_r(void) 102d1712369SKumar Gala { 103d1712369SKumar Gala const unsigned int flashbase = CONFIG_SYS_FLASH_BASE; 104d1712369SKumar Gala const u8 flash_esel = find_tlb_idx((void *)flashbase, 1); 105d1712369SKumar Gala 106d1712369SKumar Gala /* 107d1712369SKumar Gala * Remap Boot flash + PROMJET region to caching-inhibited 108d1712369SKumar Gala * so that flash can be erased properly. 109d1712369SKumar Gala */ 110d1712369SKumar Gala 111d1712369SKumar Gala /* Flush d-cache and invalidate i-cache of any FLASH data */ 112d1712369SKumar Gala flush_dcache(); 113d1712369SKumar Gala invalidate_icache(); 114d1712369SKumar Gala 115d1712369SKumar Gala /* invalidate existing TLB entry for flash + promjet */ 116d1712369SKumar Gala disable_tlb(flash_esel); 117d1712369SKumar Gala 118d1712369SKumar Gala set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS, /* tlb, epn, rpn */ 119d1712369SKumar Gala MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */ 120d1712369SKumar Gala 0, flash_esel, BOOKE_PAGESZ_256M, 1); /* ts, esel, tsize, iprot */ 121d1712369SKumar Gala 122d1712369SKumar Gala set_liodns(); 12358b2f96eSKumar Gala #ifdef CONFIG_SYS_DPAA_QBMAN 124d1712369SKumar Gala setup_portals(); 12558b2f96eSKumar Gala #endif 126d1712369SKumar Gala 127d1712369SKumar Gala return 0; 128d1712369SKumar Gala } 129d1712369SKumar Gala 130d1712369SKumar Gala static const char *serdes_clock_to_string(u32 clock) 131d1712369SKumar Gala { 132d1712369SKumar Gala switch(clock) { 133d1712369SKumar Gala case SRDS_PLLCR0_RFCK_SEL_100: 134d1712369SKumar Gala return "100"; 135d1712369SKumar Gala case SRDS_PLLCR0_RFCK_SEL_125: 136d1712369SKumar Gala return "125"; 137d1712369SKumar Gala case SRDS_PLLCR0_RFCK_SEL_156_25: 138d1712369SKumar Gala return "156.25"; 139d1712369SKumar Gala default: 140e02aea61SKumar Gala return "150"; 141d1712369SKumar Gala } 142d1712369SKumar Gala } 143d1712369SKumar Gala 144d1712369SKumar Gala #define NUM_SRDS_BANKS 3 145d1712369SKumar Gala 146d1712369SKumar Gala int misc_init_r(void) 147d1712369SKumar Gala { 148d1712369SKumar Gala serdes_corenet_t *srds_regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR; 149d1712369SKumar Gala u32 actual[NUM_SRDS_BANKS]; 150d1712369SKumar Gala unsigned int i; 151e02aea61SKumar Gala u8 sw; 152d1712369SKumar Gala 153d31e53b4STimur Tabi #if defined(CONFIG_P3041DS) || defined(CONFIG_P5020DS) \ 154d31e53b4STimur Tabi || defined(CONFIG_P5040DS) 155e02aea61SKumar Gala sw = in_8(&PIXIS_SW(5)); 156e02aea61SKumar Gala for (i = 0; i < 3; i++) { 157e02aea61SKumar Gala unsigned int clock = (sw >> (6 - (2 * i))) & 3; 158e02aea61SKumar Gala switch (clock) { 159e02aea61SKumar Gala case 0: 160e02aea61SKumar Gala actual[i] = SRDS_PLLCR0_RFCK_SEL_100; 161e02aea61SKumar Gala break; 162e02aea61SKumar Gala case 1: 163e02aea61SKumar Gala actual[i] = SRDS_PLLCR0_RFCK_SEL_125; 164e02aea61SKumar Gala break; 165e02aea61SKumar Gala case 2: 166e02aea61SKumar Gala actual[i] = SRDS_PLLCR0_RFCK_SEL_156_25; 167e02aea61SKumar Gala break; 168e02aea61SKumar Gala default: 169e02aea61SKumar Gala printf("Warning: SDREFCLK%u switch setting of '11' is " 170e02aea61SKumar Gala "unsupported\n", i + 1); 171e02aea61SKumar Gala break; 172e02aea61SKumar Gala } 173e02aea61SKumar Gala } 174e02aea61SKumar Gala #else 175d1712369SKumar Gala /* Warn if the expected SERDES reference clocks don't match the 176d1712369SKumar Gala * actual reference clocks. This needs to be done after calling 177d1712369SKumar Gala * p4080_erratum_serdes8(), since that function may modify the clocks. 178d1712369SKumar Gala */ 179e02aea61SKumar Gala sw = in_8(&PIXIS_SW(3)); 180e02aea61SKumar Gala actual[0] = (sw & 0x40) ? 181d1712369SKumar Gala SRDS_PLLCR0_RFCK_SEL_125 : SRDS_PLLCR0_RFCK_SEL_100; 182e02aea61SKumar Gala actual[1] = (sw & 0x20) ? 183d1712369SKumar Gala SRDS_PLLCR0_RFCK_SEL_156_25 : SRDS_PLLCR0_RFCK_SEL_125; 184e02aea61SKumar Gala actual[2] = (sw & 0x10) ? 185d1712369SKumar Gala SRDS_PLLCR0_RFCK_SEL_156_25 : SRDS_PLLCR0_RFCK_SEL_125; 186e02aea61SKumar Gala #endif 187d1712369SKumar Gala 188d1712369SKumar Gala for (i = 0; i < NUM_SRDS_BANKS; i++) { 189d1712369SKumar Gala u32 expected = srds_regs->bank[i].pllcr0 & SRDS_PLLCR0_RFCK_SEL_MASK; 190d1712369SKumar Gala if (expected != actual[i]) { 191d1712369SKumar Gala printf("Warning: SERDES bank %u expects reference clock" 192d1712369SKumar Gala " %sMHz, but actual is %sMHz\n", i + 1, 193d1712369SKumar Gala serdes_clock_to_string(expected), 194d1712369SKumar Gala serdes_clock_to_string(actual[i])); 195d1712369SKumar Gala } 196d1712369SKumar Gala } 197d1712369SKumar Gala 198d1712369SKumar Gala return 0; 199d1712369SKumar Gala } 200d1712369SKumar Gala 201d1712369SKumar Gala void ft_board_setup(void *blob, bd_t *bd) 202d1712369SKumar Gala { 203d1712369SKumar Gala phys_addr_t base; 204d1712369SKumar Gala phys_size_t size; 205d1712369SKumar Gala 206d1712369SKumar Gala ft_cpu_setup(blob, bd); 207d1712369SKumar Gala 208d1712369SKumar Gala base = getenv_bootm_low(); 209d1712369SKumar Gala size = getenv_bootm_size(); 210d1712369SKumar Gala 211d1712369SKumar Gala fdt_fixup_memory(blob, (u64)base, (u64)size); 212d1712369SKumar Gala 213d1712369SKumar Gala #ifdef CONFIG_PCI 214d1712369SKumar Gala pci_of_setup(blob, bd); 215d1712369SKumar Gala #endif 216d1712369SKumar Gala 217d1712369SKumar Gala fdt_fixup_liodn(blob); 218a3a3e7b2SShaohui Xie fdt_fixup_dr_usb(blob, bd); 219d1712369SKumar Gala 2202915609aSAndy Fleming #ifdef CONFIG_SYS_DPAA_FMAN 2212915609aSAndy Fleming fdt_fixup_fman_ethernet(blob); 2222915609aSAndy Fleming fdt_fixup_board_enet(blob); 2232915609aSAndy Fleming #endif 224d1712369SKumar Gala } 225