Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 1 | /* |
ramneek mehresh | 3d33963 | 2012-04-18 19:39:53 +0000 | [diff] [blame] | 2 | * Copyright 2011,2012 Freescale Semiconductor, Inc. |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 3 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <command.h> |
| 9 | #include <netdev.h> |
| 10 | #include <linux/compiler.h> |
| 11 | #include <asm/mmu.h> |
| 12 | #include <asm/processor.h> |
| 13 | #include <asm/cache.h> |
| 14 | #include <asm/immap_85xx.h> |
| 15 | #include <asm/fsl_law.h> |
| 16 | #include <asm/fsl_serdes.h> |
| 17 | #include <asm/fsl_portals.h> |
| 18 | #include <asm/fsl_liodn.h> |
Mingkai Hu | 4c46d82 | 2011-07-19 16:20:13 +0800 | [diff] [blame] | 19 | #include <fm_eth.h> |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 20 | |
| 21 | extern void pci_of_setup(void *blob, bd_t *bd); |
| 22 | |
| 23 | #include "cpld.h" |
| 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
| 27 | int checkboard(void) |
| 28 | { |
| 29 | u8 sw; |
Simon Glass | a8b5739 | 2012-12-13 20:48:48 +0000 | [diff] [blame] | 30 | struct cpu_type *cpu = gd->arch.cpu; |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 31 | unsigned int i; |
| 32 | |
| 33 | printf("Board: %sRDB, ", cpu->name); |
| 34 | printf("CPLD version: %d.%d ", CPLD_READ(cpld_ver), |
| 35 | CPLD_READ(cpld_ver_sub)); |
| 36 | |
| 37 | sw = CPLD_READ(fbank_sel); |
| 38 | printf("vBank: %d\n", sw & 0x1); |
| 39 | |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 40 | /* |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 41 | * Display the actual SERDES reference clocks as configured by the |
| 42 | * dip switches on the board. Note that the SWx registers could |
| 43 | * technically be set to force the reference clocks to match the |
| 44 | * values that the SERDES expects (or vice versa). For now, however, |
| 45 | * we just display both values and hope the user notices when they |
| 46 | * don't match. |
| 47 | */ |
| 48 | puts("SERDES Reference Clocks: "); |
| 49 | sw = in_8(&CPLD_SW(2)) >> 2; |
| 50 | for (i = 0; i < 2; i++) { |
Shaohui Xie | ab9e5e6 | 2011-12-02 09:38:12 +0800 | [diff] [blame] | 51 | static const char * const freq[][3] = {{"0", "100", "125"}, |
| 52 | {"100", "156.25", "125"} |
| 53 | }; |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 54 | unsigned int clock = (sw >> (2 * i)) & 3; |
| 55 | |
Shaohui Xie | ab9e5e6 | 2011-12-02 09:38:12 +0800 | [diff] [blame] | 56 | printf("Bank%u=%sMhz ", i+1, freq[i][clock]); |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 57 | } |
| 58 | puts("\n"); |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | int board_early_init_f(void) |
| 64 | { |
| 65 | ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
| 66 | |
| 67 | /* board only uses the DDR_MCK0/1, so disable the DDR_MCK2/3 */ |
| 68 | setbits_be32(&gur->ddrclkdr, 0x000f000f); |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
Shaohui Xie | 498610c | 2012-12-03 21:36:32 +0000 | [diff] [blame] | 73 | #define CPLD_LANE_A_SEL 0x1 |
| 74 | #define CPLD_LANE_G_SEL 0x2 |
| 75 | #define CPLD_LANE_C_SEL 0x4 |
| 76 | #define CPLD_LANE_D_SEL 0x8 |
| 77 | |
| 78 | void board_config_lanes_mux(void) |
| 79 | { |
| 80 | ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR; |
| 81 | int srds_prtcl = (in_be32(&gur->rcwsr[4]) & |
| 82 | FSL_CORENET_RCWSR4_SRDS_PRTCL) >> 26; |
| 83 | |
| 84 | u8 mux = 0; |
| 85 | switch (srds_prtcl) { |
| 86 | case 0x2: |
| 87 | case 0x5: |
| 88 | case 0x9: |
| 89 | case 0xa: |
| 90 | case 0xf: |
| 91 | break; |
| 92 | case 0x8: |
| 93 | mux |= CPLD_LANE_C_SEL | CPLD_LANE_D_SEL; |
| 94 | break; |
| 95 | case 0x14: |
| 96 | mux |= CPLD_LANE_A_SEL; |
| 97 | break; |
| 98 | case 0x17: |
| 99 | mux |= CPLD_LANE_G_SEL; |
| 100 | break; |
| 101 | case 0x16: |
| 102 | case 0x19: |
| 103 | case 0x1a: |
| 104 | mux |= CPLD_LANE_G_SEL | CPLD_LANE_C_SEL | CPLD_LANE_D_SEL; |
| 105 | break; |
| 106 | case 0x1c: |
| 107 | mux |= CPLD_LANE_G_SEL | CPLD_LANE_A_SEL; |
| 108 | break; |
| 109 | default: |
| 110 | printf("Fman:Unsupported SerDes Protocol 0x%02x\n", srds_prtcl); |
| 111 | break; |
| 112 | } |
| 113 | CPLD_WRITE(serdes_mux, mux); |
| 114 | } |
| 115 | |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 116 | int board_early_init_r(void) |
| 117 | { |
| 118 | const unsigned int flashbase = CONFIG_SYS_FLASH_BASE; |
| 119 | const u8 flash_esel = find_tlb_idx((void *)flashbase, 1); |
| 120 | |
| 121 | /* |
| 122 | * Remap Boot flash + PROMJET region to caching-inhibited |
| 123 | * so that flash can be erased properly. |
| 124 | */ |
| 125 | |
| 126 | /* Flush d-cache and invalidate i-cache of any FLASH data */ |
| 127 | flush_dcache(); |
| 128 | invalidate_icache(); |
| 129 | |
| 130 | /* invalidate existing TLB entry for flash + promjet */ |
| 131 | disable_tlb(flash_esel); |
| 132 | |
| 133 | set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS, |
| 134 | MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, |
| 135 | 0, flash_esel, BOOKE_PAGESZ_256M, 1); |
| 136 | |
| 137 | set_liodns(); |
| 138 | setup_portals(); |
Shaohui Xie | 498610c | 2012-12-03 21:36:32 +0000 | [diff] [blame] | 139 | board_config_lanes_mux(); |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
Shaohui Xie | ada0261 | 2011-09-13 17:55:11 +0800 | [diff] [blame] | 144 | unsigned long get_board_sys_clk(unsigned long dummy) |
| 145 | { |
| 146 | u8 sysclk_conf = CPLD_READ(sysclk_sw1); |
| 147 | |
| 148 | switch (sysclk_conf & 0x7) { |
| 149 | case CPLD_SYSCLK_83: |
| 150 | return 83333333; |
| 151 | case CPLD_SYSCLK_100: |
| 152 | return 100000000; |
| 153 | default: |
| 154 | return 66666666; |
| 155 | } |
| 156 | } |
| 157 | |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 158 | #define NUM_SRDS_BANKS 2 |
| 159 | |
| 160 | int misc_init_r(void) |
| 161 | { |
| 162 | serdes_corenet_t *regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR; |
| 163 | u32 actual[NUM_SRDS_BANKS]; |
| 164 | unsigned int i; |
| 165 | u8 sw; |
Shaohui Xie | ab9e5e6 | 2011-12-02 09:38:12 +0800 | [diff] [blame] | 166 | static const int freq[][3] = { |
| 167 | {0, SRDS_PLLCR0_RFCK_SEL_100, SRDS_PLLCR0_RFCK_SEL_125}, |
| 168 | {SRDS_PLLCR0_RFCK_SEL_100, SRDS_PLLCR0_RFCK_SEL_156_25, |
| 169 | SRDS_PLLCR0_RFCK_SEL_125} |
| 170 | }; |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 171 | |
| 172 | sw = in_8(&CPLD_SW(2)) >> 2; |
| 173 | for (i = 0; i < NUM_SRDS_BANKS; i++) { |
| 174 | unsigned int clock = (sw >> (2 * i)) & 3; |
Shaohui Xie | ab9e5e6 | 2011-12-02 09:38:12 +0800 | [diff] [blame] | 175 | if (clock == 0x3) { |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 176 | printf("Warning: SDREFCLK%u switch setting of '11' is " |
| 177 | "unsupported\n", i + 1); |
| 178 | break; |
| 179 | } |
Shaohui Xie | ab9e5e6 | 2011-12-02 09:38:12 +0800 | [diff] [blame] | 180 | if (i == 0 && clock == 0) |
| 181 | puts("Warning: SDREFCLK1 switch setting of" |
| 182 | "'00' is unsupported\n"); |
| 183 | else |
| 184 | actual[i] = freq[i][clock]; |
Shaohui Xie | 6d14b42 | 2013-03-25 07:40:18 +0000 | [diff] [blame] | 185 | |
| 186 | /* |
| 187 | * PC board uses a different CPLD with PB board, this CPLD |
| 188 | * has cpld_ver_sub = 1, and pcba_ver = 5. But CPLD on PB |
| 189 | * board has cpld_ver_sub = 0, and pcba_ver = 4. |
| 190 | */ |
| 191 | if ((i == 1) && (CPLD_READ(cpld_ver_sub) == 1) && |
| 192 | (CPLD_READ(pcba_ver) == 5)) { |
| 193 | /* PC board bank2 frequency */ |
| 194 | actual[i] = freq[i-1][clock]; |
| 195 | } |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | for (i = 0; i < NUM_SRDS_BANKS; i++) { |
| 199 | u32 expected = in_be32(®s->bank[i].pllcr0); |
| 200 | expected &= SRDS_PLLCR0_RFCK_SEL_MASK; |
| 201 | if (expected != actual[i]) { |
| 202 | printf("Warning: SERDES bank %u expects reference clock" |
| 203 | " %sMHz, but actual is %sMHz\n", i + 1, |
| 204 | serdes_clock_to_string(expected), |
| 205 | serdes_clock_to_string(actual[i])); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | void ft_board_setup(void *blob, bd_t *bd) |
| 213 | { |
| 214 | phys_addr_t base; |
| 215 | phys_size_t size; |
| 216 | |
| 217 | ft_cpu_setup(blob, bd); |
| 218 | |
| 219 | base = getenv_bootm_low(); |
| 220 | size = getenv_bootm_size(); |
| 221 | |
| 222 | fdt_fixup_memory(blob, (u64)base, (u64)size); |
| 223 | |
ramneek mehresh | 3d33963 | 2012-04-18 19:39:53 +0000 | [diff] [blame] | 224 | #if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB) |
| 225 | fdt_fixup_dr_usb(blob, bd); |
| 226 | #endif |
| 227 | |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 228 | #ifdef CONFIG_PCI |
| 229 | pci_of_setup(blob, bd); |
| 230 | #endif |
| 231 | |
| 232 | fdt_fixup_liodn(blob); |
Mingkai Hu | 4c46d82 | 2011-07-19 16:20:13 +0800 | [diff] [blame] | 233 | #ifdef CONFIG_SYS_DPAA_FMAN |
| 234 | fdt_fixup_fman_ethernet(blob); |
| 235 | #endif |
Mingkai Hu | f354b53 | 2011-07-07 12:29:15 +0800 | [diff] [blame] | 236 | } |