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