blob: 4ece1e6ea0a4fd94c90677555311f7b6c8430261 [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
6#include <common.h>
7#include <command.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -06008#include <env.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -07009#include <fdt_support.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060010#include <image.h>
Simon Glassa7b51302019-11-14 12:57:46 -070011#include <init.h>
Mingkai Huf354b532011-07-07 12:29:15 +080012#include <netdev.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Mingkai Huf354b532011-07-07 12:29:15 +080014#include <linux/compiler.h>
15#include <asm/mmu.h>
16#include <asm/processor.h>
17#include <asm/cache.h>
18#include <asm/immap_85xx.h>
19#include <asm/fsl_law.h>
20#include <asm/fsl_serdes.h>
Mingkai Huf354b532011-07-07 12:29:15 +080021#include <asm/fsl_liodn.h>
Mingkai Hu4c46d822011-07-19 16:20:13 +080022#include <fm_eth.h>
Mingkai Huf354b532011-07-07 12:29:15 +080023
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090024extern void pci_of_setup(void *blob, struct bd_info *bd);
Mingkai Huf354b532011-07-07 12:29:15 +080025
26#include "cpld.h"
27
28DECLARE_GLOBAL_DATA_PTR;
29
30int checkboard(void)
31{
32 u8 sw;
Simon Glassa8b57392012-12-13 20:48:48 +000033 struct cpu_type *cpu = gd->arch.cpu;
Mingkai Huf354b532011-07-07 12:29:15 +080034 unsigned int i;
35
36 printf("Board: %sRDB, ", cpu->name);
37 printf("CPLD version: %d.%d ", CPLD_READ(cpld_ver),
38 CPLD_READ(cpld_ver_sub));
39
40 sw = CPLD_READ(fbank_sel);
41 printf("vBank: %d\n", sw & 0x1);
42
Mingkai Huf354b532011-07-07 12:29:15 +080043 /*
Mingkai Huf354b532011-07-07 12:29:15 +080044 * Display the actual SERDES reference clocks as configured by the
45 * dip switches on the board. Note that the SWx registers could
46 * technically be set to force the reference clocks to match the
47 * values that the SERDES expects (or vice versa). For now, however,
48 * we just display both values and hope the user notices when they
49 * don't match.
50 */
51 puts("SERDES Reference Clocks: ");
52 sw = in_8(&CPLD_SW(2)) >> 2;
53 for (i = 0; i < 2; i++) {
Shaohui Xieab9e5e62011-12-02 09:38:12 +080054 static const char * const freq[][3] = {{"0", "100", "125"},
55 {"100", "156.25", "125"}
56 };
Mingkai Huf354b532011-07-07 12:29:15 +080057 unsigned int clock = (sw >> (2 * i)) & 3;
58
Shaohui Xieab9e5e62011-12-02 09:38:12 +080059 printf("Bank%u=%sMhz ", i+1, freq[i][clock]);
Mingkai Huf354b532011-07-07 12:29:15 +080060 }
61 puts("\n");
62
63 return 0;
64}
65
66int board_early_init_f(void)
67{
68 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
69
70 /* board only uses the DDR_MCK0/1, so disable the DDR_MCK2/3 */
71 setbits_be32(&gur->ddrclkdr, 0x000f000f);
72
73 return 0;
74}
75
Shaohui Xie498610c2012-12-03 21:36:32 +000076#define CPLD_LANE_A_SEL 0x1
77#define CPLD_LANE_G_SEL 0x2
78#define CPLD_LANE_C_SEL 0x4
79#define CPLD_LANE_D_SEL 0x8
80
81void board_config_lanes_mux(void)
82{
83 ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
84 int srds_prtcl = (in_be32(&gur->rcwsr[4]) &
85 FSL_CORENET_RCWSR4_SRDS_PRTCL) >> 26;
86
87 u8 mux = 0;
88 switch (srds_prtcl) {
89 case 0x2:
90 case 0x5:
91 case 0x9:
92 case 0xa:
93 case 0xf:
94 break;
95 case 0x8:
96 mux |= CPLD_LANE_C_SEL | CPLD_LANE_D_SEL;
97 break;
98 case 0x14:
99 mux |= CPLD_LANE_A_SEL;
100 break;
101 case 0x17:
102 mux |= CPLD_LANE_G_SEL;
103 break;
104 case 0x16:
105 case 0x19:
106 case 0x1a:
107 mux |= CPLD_LANE_G_SEL | CPLD_LANE_C_SEL | CPLD_LANE_D_SEL;
108 break;
109 case 0x1c:
110 mux |= CPLD_LANE_G_SEL | CPLD_LANE_A_SEL;
111 break;
112 default:
113 printf("Fman:Unsupported SerDes Protocol 0x%02x\n", srds_prtcl);
114 break;
115 }
116 CPLD_WRITE(serdes_mux, mux);
117}
118
Mingkai Huf354b532011-07-07 12:29:15 +0800119int board_early_init_r(void)
120{
121 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
York Sun220c3462014-06-24 21:16:20 -0700122 int flash_esel = find_tlb_idx((void *)flashbase, 1);
Mingkai Huf354b532011-07-07 12:29:15 +0800123
124 /*
125 * Remap Boot flash + PROMJET region to caching-inhibited
126 * so that flash can be erased properly.
127 */
128
129 /* Flush d-cache and invalidate i-cache of any FLASH data */
130 flush_dcache();
131 invalidate_icache();
132
York Sun220c3462014-06-24 21:16:20 -0700133 if (flash_esel == -1) {
134 /* very unlikely unless something is messed up */
135 puts("Error: Could not find TLB for FLASH BASE\n");
136 flash_esel = 2; /* give our best effort to continue */
137 } else {
138 /* invalidate existing TLB entry for flash + promjet */
139 disable_tlb(flash_esel);
140 }
Mingkai Huf354b532011-07-07 12:29:15 +0800141
142 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
143 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
144 0, flash_esel, BOOKE_PAGESZ_256M, 1);
145
Shaohui Xie498610c2012-12-03 21:36:32 +0000146 board_config_lanes_mux();
Mingkai Huf354b532011-07-07 12:29:15 +0800147
148 return 0;
149}
150
Shaohui Xieada02612011-09-13 17:55:11 +0800151unsigned long get_board_sys_clk(unsigned long dummy)
152{
153 u8 sysclk_conf = CPLD_READ(sysclk_sw1);
154
155 switch (sysclk_conf & 0x7) {
156 case CPLD_SYSCLK_83:
157 return 83333333;
158 case CPLD_SYSCLK_100:
159 return 100000000;
160 default:
161 return 66666666;
162 }
163}
164
Mingkai Huf354b532011-07-07 12:29:15 +0800165#define NUM_SRDS_BANKS 2
166
167int misc_init_r(void)
168{
169 serdes_corenet_t *regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
170 u32 actual[NUM_SRDS_BANKS];
171 unsigned int i;
172 u8 sw;
Shaohui Xieab9e5e62011-12-02 09:38:12 +0800173 static const int freq[][3] = {
174 {0, SRDS_PLLCR0_RFCK_SEL_100, SRDS_PLLCR0_RFCK_SEL_125},
175 {SRDS_PLLCR0_RFCK_SEL_100, SRDS_PLLCR0_RFCK_SEL_156_25,
176 SRDS_PLLCR0_RFCK_SEL_125}
177 };
Mingkai Huf354b532011-07-07 12:29:15 +0800178
179 sw = in_8(&CPLD_SW(2)) >> 2;
180 for (i = 0; i < NUM_SRDS_BANKS; i++) {
181 unsigned int clock = (sw >> (2 * i)) & 3;
Shaohui Xieab9e5e62011-12-02 09:38:12 +0800182 if (clock == 0x3) {
Mingkai Huf354b532011-07-07 12:29:15 +0800183 printf("Warning: SDREFCLK%u switch setting of '11' is "
184 "unsupported\n", i + 1);
185 break;
186 }
Shaohui Xieab9e5e62011-12-02 09:38:12 +0800187 if (i == 0 && clock == 0)
188 puts("Warning: SDREFCLK1 switch setting of"
189 "'00' is unsupported\n");
190 else
191 actual[i] = freq[i][clock];
Shaohui Xie6d14b422013-03-25 07:40:18 +0000192
193 /*
194 * PC board uses a different CPLD with PB board, this CPLD
195 * has cpld_ver_sub = 1, and pcba_ver = 5. But CPLD on PB
196 * board has cpld_ver_sub = 0, and pcba_ver = 4.
197 */
198 if ((i == 1) && (CPLD_READ(cpld_ver_sub) == 1) &&
199 (CPLD_READ(pcba_ver) == 5)) {
200 /* PC board bank2 frequency */
201 actual[i] = freq[i-1][clock];
202 }
Mingkai Huf354b532011-07-07 12:29:15 +0800203 }
204
205 for (i = 0; i < NUM_SRDS_BANKS; i++) {
206 u32 expected = in_be32(&regs->bank[i].pllcr0);
207 expected &= SRDS_PLLCR0_RFCK_SEL_MASK;
208 if (expected != actual[i]) {
209 printf("Warning: SERDES bank %u expects reference clock"
210 " %sMHz, but actual is %sMHz\n", i + 1,
211 serdes_clock_to_string(expected),
212 serdes_clock_to_string(actual[i]));
213 }
214 }
215
216 return 0;
217}
218
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900219int ft_board_setup(void *blob, struct bd_info *bd)
Mingkai Huf354b532011-07-07 12:29:15 +0800220{
221 phys_addr_t base;
222 phys_size_t size;
223
224 ft_cpu_setup(blob, bd);
225
Simon Glassda1a1342017-08-03 12:22:15 -0600226 base = env_get_bootm_low();
227 size = env_get_bootm_size();
Mingkai Huf354b532011-07-07 12:29:15 +0800228
229 fdt_fixup_memory(blob, (u64)base, (u64)size);
230
ramneek mehresh3d339632012-04-18 19:39:53 +0000231#if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB)
Sriram Dash9fd465c2016-09-16 17:12:15 +0530232 fsl_fdt_fixup_dr_usb(blob, bd);
ramneek mehresh3d339632012-04-18 19:39:53 +0000233#endif
234
Mingkai Huf354b532011-07-07 12:29:15 +0800235#ifdef CONFIG_PCI
236 pci_of_setup(blob, bd);
237#endif
238
239 fdt_fixup_liodn(blob);
Mingkai Hu4c46d822011-07-19 16:20:13 +0800240#ifdef CONFIG_SYS_DPAA_FMAN
Madalin Bucur70848512020-04-30 15:59:58 +0300241#ifndef CONFIG_DM_ETH
Mingkai Hu4c46d822011-07-19 16:20:13 +0800242 fdt_fixup_fman_ethernet(blob);
243#endif
Madalin Bucur70848512020-04-30 15:59:58 +0300244#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600245
246 return 0;
Mingkai Huf354b532011-07-07 12:29:15 +0800247}