blob: d5b71f7843036885a5cc1b7258f4708f941068b5 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mingkai Huf354b532011-07-07 12:29:15 +08002/*
ramneek mehresh3d339632012-04-18 19:39:53 +00003 * Copyright 2011,2012 Freescale Semiconductor, Inc.
Mingkai Huf354b532011-07-07 12:29:15 +08004 */
5
Tom Rinidec7ea02024-05-20 13:35:03 -06006#include <config.h>
Tom Rini8c70baa2021-12-14 13:36:40 -05007#include <clock_legacy.h>
Mingkai Huf354b532011-07-07 12:29:15 +08008#include <command.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -06009#include <env.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -070010#include <fdt_support.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060011#include <image.h>
Simon Glassa7b51302019-11-14 12:57:46 -070012#include <init.h>
Mingkai Huf354b532011-07-07 12:29:15 +080013#include <netdev.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Mingkai Huf354b532011-07-07 12:29:15 +080015#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 Huf354b532011-07-07 12:29:15 +080022#include <asm/fsl_liodn.h>
Mingkai Hu4c46d822011-07-19 16:20:13 +080023#include <fm_eth.h>
Mingkai Huf354b532011-07-07 12:29:15 +080024
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090025extern void pci_of_setup(void *blob, struct bd_info *bd);
Mingkai Huf354b532011-07-07 12:29:15 +080026
27#include "cpld.h"
28
29DECLARE_GLOBAL_DATA_PTR;
30
31int checkboard(void)
32{
33 u8 sw;
Simon Glassa8b57392012-12-13 20:48:48 +000034 struct cpu_type *cpu = gd->arch.cpu;
Mingkai Huf354b532011-07-07 12:29:15 +080035 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 Huf354b532011-07-07 12:29:15 +080044 /*
Mingkai Huf354b532011-07-07 12:29:15 +080045 * 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 Xieab9e5e62011-12-02 09:38:12 +080055 static const char * const freq[][3] = {{"0", "100", "125"},
56 {"100", "156.25", "125"}
57 };
Mingkai Huf354b532011-07-07 12:29:15 +080058 unsigned int clock = (sw >> (2 * i)) & 3;
59
Shaohui Xieab9e5e62011-12-02 09:38:12 +080060 printf("Bank%u=%sMhz ", i+1, freq[i][clock]);
Mingkai Huf354b532011-07-07 12:29:15 +080061 }
62 puts("\n");
63
64 return 0;
65}
66
67int board_early_init_f(void)
68{
Tom Rinid5c3bf22022-10-28 20:27:12 -040069 ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
Mingkai Huf354b532011-07-07 12:29:15 +080070
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 Xie498610c2012-12-03 21:36:32 +000077#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
82void board_config_lanes_mux(void)
83{
Tom Rinid5c3bf22022-10-28 20:27:12 -040084 ccsr_gur_t *gur = (void *)CFG_SYS_MPC85xx_GUTS_ADDR;
Shaohui Xie498610c2012-12-03 21:36:32 +000085 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 Huf354b532011-07-07 12:29:15 +0800120int board_early_init_r(void)
121{
Tom Rini6a5dccc2022-11-16 13:10:41 -0500122 const unsigned int flashbase = CFG_SYS_FLASH_BASE;
York Sun220c3462014-06-24 21:16:20 -0700123 int flash_esel = find_tlb_idx((void *)flashbase, 1);
Mingkai Huf354b532011-07-07 12:29:15 +0800124
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 Sun220c3462014-06-24 21:16:20 -0700134 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 Huf354b532011-07-07 12:29:15 +0800142
Tom Rini6a5dccc2022-11-16 13:10:41 -0500143 set_tlb(1, flashbase, CFG_SYS_FLASH_BASE_PHYS,
Mingkai Huf354b532011-07-07 12:29:15 +0800144 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
145 0, flash_esel, BOOKE_PAGESZ_256M, 1);
146
Shaohui Xie498610c2012-12-03 21:36:32 +0000147 board_config_lanes_mux();
Mingkai Huf354b532011-07-07 12:29:15 +0800148
149 return 0;
150}
151
Tom Riniaea2a992021-12-14 13:36:39 -0500152unsigned long get_board_sys_clk(void)
Shaohui Xieada02612011-09-13 17:55:11 +0800153{
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 Huf354b532011-07-07 12:29:15 +0800166#define NUM_SRDS_BANKS 2
167
168int misc_init_r(void)
169{
Tom Rini376b88a2022-10-28 20:27:13 -0400170 serdes_corenet_t *regs = (void *)CFG_SYS_FSL_CORENET_SERDES_ADDR;
Mingkai Huf354b532011-07-07 12:29:15 +0800171 u32 actual[NUM_SRDS_BANKS];
172 unsigned int i;
173 u8 sw;
Shaohui Xieab9e5e62011-12-02 09:38:12 +0800174 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 Huf354b532011-07-07 12:29:15 +0800179
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 Xieab9e5e62011-12-02 09:38:12 +0800183 if (clock == 0x3) {
Mingkai Huf354b532011-07-07 12:29:15 +0800184 printf("Warning: SDREFCLK%u switch setting of '11' is "
185 "unsupported\n", i + 1);
186 break;
187 }
Shaohui Xieab9e5e62011-12-02 09:38:12 +0800188 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 Xie6d14b422013-03-25 07:40:18 +0000193
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 Huf354b532011-07-07 12:29:15 +0800204 }
205
206 for (i = 0; i < NUM_SRDS_BANKS; i++) {
207 u32 expected = in_be32(&regs->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 Yamadaf7ed78b2020-06-26 15:13:33 +0900220int ft_board_setup(void *blob, struct bd_info *bd)
Mingkai Huf354b532011-07-07 12:29:15 +0800221{
222 phys_addr_t base;
223 phys_size_t size;
224
225 ft_cpu_setup(blob, bd);
226
Simon Glassda1a1342017-08-03 12:22:15 -0600227 base = env_get_bootm_low();
228 size = env_get_bootm_size();
Mingkai Huf354b532011-07-07 12:29:15 +0800229
230 fdt_fixup_memory(blob, (u64)base, (u64)size);
231
Tom Riniad22ef42022-06-08 08:24:34 -0400232#if defined(CONFIG_HAS_FSL_DR_USB)
Sriram Dash9fd465c2016-09-16 17:12:15 +0530233 fsl_fdt_fixup_dr_usb(blob, bd);
ramneek mehresh3d339632012-04-18 19:39:53 +0000234#endif
235
Mingkai Huf354b532011-07-07 12:29:15 +0800236#ifdef CONFIG_PCI
237 pci_of_setup(blob, bd);
238#endif
239
240 fdt_fixup_liodn(blob);
Mingkai Hu4c46d822011-07-19 16:20:13 +0800241#ifdef CONFIG_SYS_DPAA_FMAN
Madalin Bucur70848512020-04-30 15:59:58 +0300242#ifndef CONFIG_DM_ETH
Mingkai Hu4c46d822011-07-19 16:20:13 +0800243 fdt_fixup_fman_ethernet(blob);
244#endif
Madalin Bucur70848512020-04-30 15:59:58 +0300245#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600246
247 return 0;
Mingkai Huf354b532011-07-07 12:29:15 +0800248}