blob: 92a7e608ceb81ce5a5d3ebaf9fe256bef82a6250 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk9c53f402003-10-15 23:53:47 +00002/*
Kumar Gala8975d7a2010-12-30 12:09:53 -06003 * Copyright 2007-2011 Freescale Semiconductor, Inc.
Ed Swarthoutdd93d8f2007-07-27 01:50:47 -05004 *
wdenk9c53f402003-10-15 23:53:47 +00005 * (C) Copyright 2003 Motorola Inc.
6 * Modified by Xianghua Xiao, X.Xiao@motorola.com
7 *
8 * (C) Copyright 2000
9 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk9c53f402003-10-15 23:53:47 +000010 */
11
12#include <common.h>
Simon Glass1ab16922022-07-31 12:28:48 -060013#include <display_options.h>
Simon Glassdb229612019-08-01 09:46:42 -060014#include <env.h>
Simon Glassa7b51302019-11-14 12:57:46 -070015#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060016#include <net.h>
wdenk9c53f402003-10-15 23:53:47 +000017#include <watchdog.h>
18#include <asm/processor.h>
19#include <ioports.h>
Kumar Galaeb453df2010-04-20 10:21:25 -050020#include <sata.h>
Kumar Gala2683c532011-04-13 08:37:44 -050021#include <fm_eth.h>
wdenk9c53f402003-10-15 23:53:47 +000022#include <asm/io.h>
Kumar Gala6b245b92010-05-05 22:35:27 -050023#include <asm/cache.h>
Kumar Gala9772ee72008-01-16 22:38:34 -060024#include <asm/mmu.h>
Shengzhou Liu7d8dfb82015-11-20 15:52:03 +080025#include <fsl_errata.h>
Kumar Gala95fd2f62008-01-16 01:13:58 -060026#include <asm/fsl_law.h>
Kumar Galaeb453df2010-04-20 10:21:25 -050027#include <asm/fsl_serdes.h>
Liu Gang4cc85322012-03-08 00:33:17 +000028#include <asm/fsl_srio.h>
Prabhakar Kushwaha1de43cf2016-01-22 14:34:44 +053029#ifdef CONFIG_FSL_CORENET
30#include <asm/fsl_portals.h>
31#include <asm/fsl_liodn.h>
Ahmed Mansouraa270b42017-12-15 16:01:00 -050032#include <fsl_qbman.h>
Prabhakar Kushwaha1de43cf2016-01-22 14:34:44 +053033#endif
ramneek mehreshc65e8822013-08-05 16:00:16 +053034#include <fsl_usb.h>
York Sun53155532012-08-08 18:04:53 +000035#include <hwconfig.h>
Timur Tabid7acf5c2011-11-21 17:10:23 -060036#include <linux/compiler.h>
Simon Glassdbd79542020-05-10 11:40:11 -060037#include <linux/delay.h>
Kumar Gala36d6b3f2008-01-17 16:48:33 -060038#include "mp.h"
Aneesh Bansalc6249092016-01-22 16:37:27 +053039#ifdef CONFIG_CHAIN_OF_TRUST
40#include <fsl_validate.h>
41#endif
Ruchika Guptaac1b2692014-10-15 11:35:30 +053042#ifdef CONFIG_FSL_CAAM
43#include <fsl_sec.h>
44#endif
Udit Agarwald2dd2f72019-11-07 16:11:39 +000045#if defined(CONFIG_NXP_ESBC) && defined(CONFIG_FSL_CORENET)
Aneesh Bansal4b636c32016-01-22 17:05:59 +053046#include <asm/fsl_pamu.h>
47#include <fsl_secboot_err.h>
48#endif
Timur Tabi275f4bb2011-11-22 09:21:25 -060049#ifdef CONFIG_SYS_QE_FMAN_FW_IN_NAND
Haiying Wangc0938d62011-02-07 16:14:15 -050050#include <nand.h>
51#include <errno.h>
52#endif
Shengzhou Liu15875a52016-11-21 11:36:48 +080053#ifndef CONFIG_ARCH_QEMU_E500
54#include <fsl_ddr.h>
55#endif
Simon Glass2c844c42017-06-14 21:28:26 -060056#include "../../../../drivers/ata/fsl_sata.h"
Zhao Qiangb818ba22014-03-21 16:21:45 +080057#ifdef CONFIG_U_QE
Qianyu Gongae6a7582016-02-18 13:01:59 +080058#include <fsl_qe.h>
Zhao Qiangb818ba22014-03-21 16:21:45 +080059#endif
Gaurav Jain7f19c3b2022-03-24 11:50:37 +053060#include <dm.h>
Timur Tabid7acf5c2011-11-21 17:10:23 -060061
Nikhil Badola006e83a2014-04-15 14:44:52 +053062#ifdef CONFIG_SYS_FSL_SINGLE_SOURCE_CLK
63/*
64 * For deriving usb clock from 100MHz sysclk, reference divisor is set
65 * to a value of 5, which gives an intermediate value 20(100/5). The
66 * multiplication factor integer is set to 24, which when multiplied to
67 * above intermediate value provides clock for usb ip.
68 */
69void usb_single_source_clk_configure(struct ccsr_usb_phy *usb_phy)
70{
71 sys_info_t sysinfo;
72
73 get_sys_info(&sysinfo);
74 if (sysinfo.diff_sysclk == 1) {
75 clrbits_be32(&usb_phy->pllprg[1],
76 CONFIG_SYS_FSL_USB_PLLPRG2_MFI);
77 setbits_be32(&usb_phy->pllprg[1],
78 CONFIG_SYS_FSL_USB_PLLPRG2_REF_DIV_INTERNAL_CLK |
79 CONFIG_SYS_FSL_USB_PLLPRG2_MFI_INTERNAL_CLK |
80 CONFIG_SYS_FSL_USB_INTERNAL_SOC_CLK_EN);
81 }
82}
83#endif
84
Suresh Gupta086f0a72014-02-26 14:29:12 +053085#ifdef CONFIG_SYS_FSL_ERRATUM_A006261
86void fsl_erratum_a006261_workaround(struct ccsr_usb_phy __iomem *usb_phy)
87{
88#ifdef CONFIG_SYS_FSL_USB_DUAL_PHY_ENABLE
89 u32 xcvrprg = in_be32(&usb_phy->port1.xcvrprg);
90
91 /* Increase Disconnect Threshold by 50mV */
92 xcvrprg &= ~CONFIG_SYS_FSL_USB_XCVRPRG_HS_DCNT_PROG_MASK |
93 INC_DCNT_THRESHOLD_50MV;
94 /* Enable programming of USB High speed Disconnect threshold */
95 xcvrprg |= CONFIG_SYS_FSL_USB_XCVRPRG_HS_DCNT_PROG_EN;
96 out_be32(&usb_phy->port1.xcvrprg, xcvrprg);
97
98 xcvrprg = in_be32(&usb_phy->port2.xcvrprg);
99 /* Increase Disconnect Threshold by 50mV */
100 xcvrprg &= ~CONFIG_SYS_FSL_USB_XCVRPRG_HS_DCNT_PROG_MASK |
101 INC_DCNT_THRESHOLD_50MV;
102 /* Enable programming of USB High speed Disconnect threshold */
103 xcvrprg |= CONFIG_SYS_FSL_USB_XCVRPRG_HS_DCNT_PROG_EN;
104 out_be32(&usb_phy->port2.xcvrprg, xcvrprg);
105#else
106
107 u32 temp = 0;
108 u32 status = in_be32(&usb_phy->status1);
109
110 u32 squelch_prog_rd_0_2 =
111 (status >> CONFIG_SYS_FSL_USB_SQUELCH_PROG_RD_0)
112 & CONFIG_SYS_FSL_USB_SQUELCH_PROG_MASK;
113
114 u32 squelch_prog_rd_3_5 =
115 (status >> CONFIG_SYS_FSL_USB_SQUELCH_PROG_RD_3)
116 & CONFIG_SYS_FSL_USB_SQUELCH_PROG_MASK;
117
118 setbits_be32(&usb_phy->config1,
119 CONFIG_SYS_FSL_USB_HS_DISCNCT_INC);
120 setbits_be32(&usb_phy->config2,
121 CONFIG_SYS_FSL_USB_RX_AUTO_CAL_RD_WR_SEL);
122
Sriram Dash30c95ce2016-08-17 11:47:52 +0530123 temp = squelch_prog_rd_0_2 << CONFIG_SYS_FSL_USB_SQUELCH_PROG_WR_3;
Suresh Gupta086f0a72014-02-26 14:29:12 +0530124 out_be32(&usb_phy->config2, in_be32(&usb_phy->config2) | temp);
125
Sriram Dash30c95ce2016-08-17 11:47:52 +0530126 temp = squelch_prog_rd_3_5 << CONFIG_SYS_FSL_USB_SQUELCH_PROG_WR_0;
Suresh Gupta086f0a72014-02-26 14:29:12 +0530127 out_be32(&usb_phy->config2, in_be32(&usb_phy->config2) | temp);
128#endif
129}
130#endif
131
132
Zhao Qiangb818ba22014-03-21 16:21:45 +0800133#if defined(CONFIG_QE) && !defined(CONFIG_U_QE)
Andy Flemingee0e9172007-08-14 00:14:25 -0500134extern qe_iop_conf_t qe_iop_conf_tab[];
135extern void qe_config_iopin(u8 port, u8 pin, int dir,
136 int open_drain, int assign);
137extern void qe_init(uint qe_base);
138extern void qe_reset(void);
139
140static void config_qe_ioports(void)
141{
142 u8 port, pin;
143 int dir, open_drain, assign;
144 int i;
145
146 for (i = 0; qe_iop_conf_tab[i].assign != QE_IOP_TAB_END; i++) {
147 port = qe_iop_conf_tab[i].port;
148 pin = qe_iop_conf_tab[i].pin;
149 dir = qe_iop_conf_tab[i].dir;
150 open_drain = qe_iop_conf_tab[i].open_drain;
151 assign = qe_iop_conf_tab[i].assign;
152 qe_config_iopin(port, pin, dir, open_drain, assign);
153 }
154}
155#endif
Matthew McClintock148e26a2006-06-28 10:43:36 -0500156
Kumar Gala76eef3e2009-03-19 03:40:08 -0500157#ifdef CONFIG_SYS_FSL_CPC
Aneesh Bansal8bcbc272014-03-18 23:40:26 +0530158#if defined(CONFIG_RAMBOOT_PBL) || defined(CONFIG_SYS_CPC_REINIT_F)
Tang Yuantianefd6da62014-07-04 17:39:26 +0800159void disable_cpc_sram(void)
Kumar Gala76eef3e2009-03-19 03:40:08 -0500160{
161 int i;
Kumar Gala76eef3e2009-03-19 03:40:08 -0500162
163 cpc_corenet_t *cpc = (cpc_corenet_t *)CONFIG_SYS_FSL_CPC_ADDR;
164
165 for (i = 0; i < CONFIG_SYS_NUM_CPC; i++, cpc++) {
Shaohui Xie25a2b392011-03-16 10:10:32 +0800166 if (in_be32(&cpc->cpcsrcr0) & CPC_SRCR0_SRAMEN) {
167 /* find and disable LAW of SRAM */
168 struct law_entry law = find_law(CONFIG_SYS_INIT_L3_ADDR);
169
170 if (law.index == -1) {
171 printf("\nFatal error happened\n");
172 return;
173 }
174 disable_law(law.index);
175
176 clrbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_CDQ_SPEC_DIS);
177 out_be32(&cpc->cpccsr0, 0);
178 out_be32(&cpc->cpcsrcr0, 0);
179 }
Aneesh Bansal8bcbc272014-03-18 23:40:26 +0530180 }
181}
Shaohui Xie25a2b392011-03-16 10:10:32 +0800182#endif
Kumar Gala76eef3e2009-03-19 03:40:08 -0500183
Sandeep Singh4fb16a12014-06-05 18:49:57 +0530184#if defined(T1040_TDM_QUIRK_CCSR_BASE)
185#ifdef CONFIG_POST
186#error POST memory test cannot be enabled with TDM
187#endif
188static void enable_tdm_law(void)
189{
190 int ret;
191 char buffer[HWCONFIG_BUFFER_SIZE] = {0};
192 int tdm_hwconfig_enabled = 0;
193
194 /*
195 * Extract hwconfig from environment since environment
196 * is not setup properly yet. Search for tdm entry in
197 * hwconfig.
198 */
Simon Glass64b723f2017-08-03 12:22:12 -0600199 ret = env_get_f("hwconfig", buffer, sizeof(buffer));
Sandeep Singh4fb16a12014-06-05 18:49:57 +0530200 if (ret > 0) {
201 tdm_hwconfig_enabled = hwconfig_f("tdm", buffer);
202 /* If tdm is defined in hwconfig, set law for tdm workaround */
203 if (tdm_hwconfig_enabled)
204 set_next_law(T1040_TDM_QUIRK_CCSR_BASE, LAW_SIZE_16M,
205 LAW_TRGT_IF_CCSR);
206 }
207}
208#endif
209
Tang Yuantianefd6da62014-07-04 17:39:26 +0800210void enable_cpc(void)
Aneesh Bansal8bcbc272014-03-18 23:40:26 +0530211{
212 int i;
Shaveta Leekhaa7b70972014-07-02 11:44:15 +0530213 int ret;
Aneesh Bansal8bcbc272014-03-18 23:40:26 +0530214 u32 size = 0;
Shaveta Leekhaa7b70972014-07-02 11:44:15 +0530215 u32 cpccfg0;
216 char buffer[HWCONFIG_BUFFER_SIZE];
217 char cpc_subarg[16];
218 bool have_hwconfig = false;
219 int cpc_args = 0;
Aneesh Bansal8bcbc272014-03-18 23:40:26 +0530220 cpc_corenet_t *cpc = (cpc_corenet_t *)CONFIG_SYS_FSL_CPC_ADDR;
221
Shaveta Leekhaa7b70972014-07-02 11:44:15 +0530222 /* Extract hwconfig from environment */
Simon Glass64b723f2017-08-03 12:22:12 -0600223 ret = env_get_f("hwconfig", buffer, sizeof(buffer));
Shaveta Leekhaa7b70972014-07-02 11:44:15 +0530224 if (ret > 0) {
225 /*
226 * If "en_cpc" is not defined in hwconfig then by default all
227 * cpcs are enable. If this config is defined then individual
228 * cpcs which have to be enabled should also be defined.
229 * e.g en_cpc:cpc1,cpc2;
230 */
231 if (hwconfig_f("en_cpc", buffer))
232 have_hwconfig = true;
233 }
234
Aneesh Bansal8bcbc272014-03-18 23:40:26 +0530235 for (i = 0; i < CONFIG_SYS_NUM_CPC; i++, cpc++) {
Shaveta Leekhaa7b70972014-07-02 11:44:15 +0530236 if (have_hwconfig) {
237 sprintf(cpc_subarg, "cpc%u", i + 1);
238 cpc_args = hwconfig_sub_f("en_cpc", cpc_subarg, buffer);
239 if (cpc_args == 0)
240 continue;
241 }
242 cpccfg0 = in_be32(&cpc->cpccfg0);
Aneesh Bansal8bcbc272014-03-18 23:40:26 +0530243 size += CPC_CFG0_SZ_K(cpccfg0);
244
Kumar Gala9780b592011-01-13 01:54:01 -0600245#ifdef CONFIG_SYS_FSL_ERRATUM_CPC_A002
246 setbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_TAG_ECC_SCRUB_DIS);
247#endif
Kumar Gala887c0e12011-01-13 01:56:18 -0600248#ifdef CONFIG_SYS_FSL_ERRATUM_CPC_A003
249 setbits_be32(&cpc->cpchdbcr0, CPC_HDBCR0_DATA_ECC_SCRUB_DIS);
250#endif
Scott Wood3f4a5c42013-05-15 17:50:13 -0500251#ifdef CONFIG_SYS_FSL_ERRATUM_A006593
252 setbits_be32(&cpc->cpchdbcr0, 1 << (31 - 21));
253#endif
York Sunb1954252013-09-16 12:49:31 -0700254#ifdef CONFIG_SYS_FSL_ERRATUM_A006379
255 if (has_erratum_a006379()) {
256 setbits_be32(&cpc->cpchdbcr0,
257 CPC_HDBCR0_SPLRU_LEVEL_EN);
258 }
259#endif
Kumar Gala9780b592011-01-13 01:54:01 -0600260
Kumar Gala76eef3e2009-03-19 03:40:08 -0500261 out_be32(&cpc->cpccsr0, CPC_CSR0_CE | CPC_CSR0_PE);
262 /* Read back to sync write */
263 in_be32(&cpc->cpccsr0);
264
265 }
266
Shruti Kanetkar3adfb912013-08-15 11:25:37 -0500267 puts("Corenet Platform Cache: ");
268 print_size(size * 1024, " enabled\n");
Kumar Gala76eef3e2009-03-19 03:40:08 -0500269}
270
Kim Phillips402673f2012-10-29 13:34:38 +0000271static void invalidate_cpc(void)
Kumar Gala76eef3e2009-03-19 03:40:08 -0500272{
273 int i;
274 cpc_corenet_t *cpc = (cpc_corenet_t *)CONFIG_SYS_FSL_CPC_ADDR;
275
276 for (i = 0; i < CONFIG_SYS_NUM_CPC; i++, cpc++) {
Shaohui Xie25a2b392011-03-16 10:10:32 +0800277 /* skip CPC when it used as all SRAM */
278 if (in_be32(&cpc->cpcsrcr0) & CPC_SRCR0_SRAMEN)
279 continue;
Kumar Gala76eef3e2009-03-19 03:40:08 -0500280 /* Flash invalidate the CPC and clear all the locks */
281 out_be32(&cpc->cpccsr0, CPC_CSR0_FI | CPC_CSR0_LFC);
282 while (in_be32(&cpc->cpccsr0) & (CPC_CSR0_FI | CPC_CSR0_LFC))
283 ;
284 }
285}
286#else
287#define enable_cpc()
288#define invalidate_cpc()
Tang Yuantianefd6da62014-07-04 17:39:26 +0800289#define disable_cpc_sram()
Kumar Gala76eef3e2009-03-19 03:40:08 -0500290#endif /* CONFIG_SYS_FSL_CPC */
291
wdenk9c53f402003-10-15 23:53:47 +0000292/*
293 * Breathe some life into the CPU...
294 *
295 * Set up the memory map
296 * initialize a bunch of registers
297 */
298
Kumar Gala24f86a82009-09-17 01:52:37 -0500299#ifdef CONFIG_FSL_CORENET
300static void corenet_tb_init(void)
301{
302 volatile ccsr_rcpm_t *rcpm =
303 (void *)(CONFIG_SYS_FSL_CORENET_RCPM_ADDR);
304 volatile ccsr_pic_t *pic =
Kim Phillips2ecbfeb2010-08-09 18:39:57 -0500305 (void *)(CONFIG_SYS_MPC8xxx_PIC_ADDR);
Kumar Gala24f86a82009-09-17 01:52:37 -0500306 u32 whoami = in_be32(&pic->whoami);
307
308 /* Enable the timebase register for this core */
309 out_be32(&rcpm->ctbenrl, (1 << whoami));
310}
311#endif
312
York Sun7b083df2014-03-28 15:07:27 -0700313#ifdef CONFIG_SYS_FSL_ERRATUM_A007212
314void fsl_erratum_a007212_workaround(void)
315{
316 ccsr_gur_t __iomem *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
317 u32 ddr_pll_ratio;
318 u32 __iomem *plldgdcr1 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c20);
319 u32 __iomem *plldadcr1 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c28);
320 u32 __iomem *dpdovrcr4 = (void *)(CONFIG_SYS_DCSRBAR + 0x21e80);
York Sunfe845072016-12-28 08:43:45 -0800321#if (CONFIG_SYS_NUM_DDR_CTLRS >= 2)
York Sun7b083df2014-03-28 15:07:27 -0700322 u32 __iomem *plldgdcr2 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c40);
323 u32 __iomem *plldadcr2 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c48);
York Sunfe845072016-12-28 08:43:45 -0800324#if (CONFIG_SYS_NUM_DDR_CTLRS >= 3)
York Sun7b083df2014-03-28 15:07:27 -0700325 u32 __iomem *plldgdcr3 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c60);
326 u32 __iomem *plldadcr3 = (void *)(CONFIG_SYS_DCSRBAR + 0x21c68);
327#endif
328#endif
329 /*
330 * Even this workaround applies to selected version of SoCs, it is
331 * safe to apply to all versions, with the limitation of odd ratios.
332 * If RCW has disabled DDR PLL, we have to apply this workaround,
333 * otherwise DDR will not work.
334 */
335 ddr_pll_ratio = (in_be32(&gur->rcwsr[0]) >>
336 FSL_CORENET_RCWSR0_MEM_PLL_RAT_SHIFT) &
337 FSL_CORENET_RCWSR0_MEM_PLL_RAT_MASK;
338 /* check if RCW sets ratio to 0, required by this workaround */
339 if (ddr_pll_ratio != 0)
340 return;
341 ddr_pll_ratio = (in_be32(&gur->rcwsr[0]) >>
342 FSL_CORENET_RCWSR0_MEM_PLL_RAT_RESV_SHIFT) &
343 FSL_CORENET_RCWSR0_MEM_PLL_RAT_MASK;
344 /* check if reserved bits have the desired ratio */
345 if (ddr_pll_ratio == 0) {
346 printf("Error: Unknown DDR PLL ratio!\n");
347 return;
348 }
349 ddr_pll_ratio >>= 1;
350
351 setbits_be32(plldadcr1, 0x02000001);
York Sunfe845072016-12-28 08:43:45 -0800352#if (CONFIG_SYS_NUM_DDR_CTLRS >= 2)
York Sun7b083df2014-03-28 15:07:27 -0700353 setbits_be32(plldadcr2, 0x02000001);
York Sunfe845072016-12-28 08:43:45 -0800354#if (CONFIG_SYS_NUM_DDR_CTLRS >= 3)
York Sun7b083df2014-03-28 15:07:27 -0700355 setbits_be32(plldadcr3, 0x02000001);
356#endif
357#endif
358 setbits_be32(dpdovrcr4, 0xe0000000);
359 out_be32(plldgdcr1, 0x08000001 | (ddr_pll_ratio << 1));
York Sunfe845072016-12-28 08:43:45 -0800360#if (CONFIG_SYS_NUM_DDR_CTLRS >= 2)
York Sun7b083df2014-03-28 15:07:27 -0700361 out_be32(plldgdcr2, 0x08000001 | (ddr_pll_ratio << 1));
York Sunfe845072016-12-28 08:43:45 -0800362#if (CONFIG_SYS_NUM_DDR_CTLRS >= 3)
York Sun7b083df2014-03-28 15:07:27 -0700363 out_be32(plldgdcr3, 0x08000001 | (ddr_pll_ratio << 1));
364#endif
365#endif
366 udelay(100);
367 clrbits_be32(plldadcr1, 0x02000001);
York Sunfe845072016-12-28 08:43:45 -0800368#if (CONFIG_SYS_NUM_DDR_CTLRS >= 2)
York Sun7b083df2014-03-28 15:07:27 -0700369 clrbits_be32(plldadcr2, 0x02000001);
York Sunfe845072016-12-28 08:43:45 -0800370#if (CONFIG_SYS_NUM_DDR_CTLRS >= 3)
York Sun7b083df2014-03-28 15:07:27 -0700371 clrbits_be32(plldadcr3, 0x02000001);
372#endif
373#endif
374 clrbits_be32(dpdovrcr4, 0xe0000000);
375}
376#endif
377
York Sun695c0c32014-04-30 14:43:47 -0700378ulong cpu_init_f(void)
wdenk9c53f402003-10-15 23:53:47 +0000379{
wdenk9c53f402003-10-15 23:53:47 +0000380 extern void m8560_cpm_reset (void);
Aneesh Bansal4b636c32016-01-22 17:05:59 +0530381#ifdef CONFIG_SYS_DCSRBAR_PHYS
Stephen George5bbf29c2011-07-20 09:47:26 -0500382 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
383#endif
Udit Agarwald2dd2f72019-11-07 16:11:39 +0000384#if defined(CONFIG_NXP_ESBC) && !defined(CONFIG_SYS_RAMBOOT)
Ruchika Gupta8ca8d822010-12-15 17:02:08 +0000385 struct law_entry law;
386#endif
York Sunefc49e02016-11-15 13:52:34 -0800387#ifdef CONFIG_ARCH_MPC8548
Peter Tyser30103c62008-11-11 10:17:10 -0600388 ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
389 uint svr = get_svr();
390
391 /*
392 * CPU2 errata workaround: A core hang possible while executing
393 * a msync instruction and a snoopable transaction from an I/O
394 * master tagged to make quick forward progress is present.
395 * Fixed in silicon rev 2.1.
396 */
397 if ((SVR_MAJ(svr) == 1) || ((SVR_MAJ(svr) == 2 && SVR_MIN(svr) == 0x0)))
398 out_be32(&ecm->eebpcr, in_be32(&ecm->eebpcr) | (1 << 16));
399#endif
wdenk9c53f402003-10-15 23:53:47 +0000400
Kumar Gala9772ee72008-01-16 22:38:34 -0600401 disable_tlb(14);
402 disable_tlb(15);
403
Udit Agarwald2dd2f72019-11-07 16:11:39 +0000404#if defined(CONFIG_NXP_ESBC) && !defined(CONFIG_SYS_RAMBOOT)
Ruchika Gupta8ca8d822010-12-15 17:02:08 +0000405 /* Disable the LAW created for NOR flash by the PBI commands */
406 law = find_law(CONFIG_SYS_PBI_FLASH_BASE);
407 if (law.index != -1)
408 disable_law(law.index);
Aneesh Bansal8bcbc272014-03-18 23:40:26 +0530409
410#if defined(CONFIG_SYS_CPC_REINIT_F)
411 disable_cpc_sram();
412#endif
Ruchika Gupta8ca8d822010-12-15 17:02:08 +0000413#endif
414
Becky Bruce0d4cee12010-06-17 11:37:20 -0500415 init_early_memctl_regs();
wdenk9c53f402003-10-15 23:53:47 +0000416
Zhao Qiangb818ba22014-03-21 16:21:45 +0800417#if defined(CONFIG_QE) && !defined(CONFIG_U_QE)
Andy Flemingee0e9172007-08-14 00:14:25 -0500418 /* Config QE ioports */
419 config_qe_ioports();
420#endif
Zhao Qiangb818ba22014-03-21 16:21:45 +0800421
Peter Tysera9af1dc2009-06-30 17:15:47 -0500422#if defined(CONFIG_FSL_DMA)
423 dma_init();
424#endif
Kumar Gala24f86a82009-09-17 01:52:37 -0500425#ifdef CONFIG_FSL_CORENET
426 corenet_tb_init();
427#endif
Kumar Gala42f99182009-11-12 10:26:16 -0600428 init_used_tlb_cams();
Kumar Gala76eef3e2009-03-19 03:40:08 -0500429
430 /* Invalidate the CPC before DDR gets enabled */
431 invalidate_cpc();
Stephen George5bbf29c2011-07-20 09:47:26 -0500432
433 #ifdef CONFIG_SYS_DCSRBAR_PHYS
434 /* set DCSRCR so that DCSR space is 1G */
435 setbits_be32(&gur->dcsrcr, FSL_CORENET_DCSR_SZ_1G);
436 in_be32(&gur->dcsrcr);
437#endif
438
York Sun7b083df2014-03-28 15:07:27 -0700439#ifdef CONFIG_SYS_FSL_ERRATUM_A007212
440 fsl_erratum_a007212_workaround();
441#endif
442
tang yuantiana4341912014-12-18 10:26:34 +0800443 return 0;
wdenk9c53f402003-10-15 23:53:47 +0000444}
445
Kumar Galaa38a9ce2010-12-15 03:50:47 -0600446/* Implement a dummy function for those platforms w/o SERDES */
447static void __fsl_serdes__init(void)
448{
449 return ;
450}
451__attribute__((weak, alias("__fsl_serdes__init"))) void fsl_serdes_init(void);
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500452
Prabhakar Kushwahacc3c5b62013-08-29 13:10:38 +0530453#if defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500)
York Sunc3d87b12012-10-08 07:44:08 +0000454int enable_cluster_l2(void)
455{
456 int i = 0;
Shengzhou Liu26ed2d02014-04-25 16:31:22 +0800457 u32 cluster, svr = get_svr();
York Sunc3d87b12012-10-08 07:44:08 +0000458 ccsr_gur_t *gur = (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
459 struct ccsr_cluster_l2 __iomem *l2cache;
460
Shengzhou Liu26ed2d02014-04-25 16:31:22 +0800461 /* only the L2 of first cluster should be enabled as expected on T4080,
462 * but there is no EOC in the first cluster as HW sake, so return here
463 * to skip enabling L2 cache of the 2nd cluster.
464 */
465 if (SVR_SOC_VER(svr) == SVR_T4080)
466 return 0;
467
York Sunc3d87b12012-10-08 07:44:08 +0000468 cluster = in_be32(&gur->tp_cluster[i].lower);
469 if (cluster & TP_CLUSTER_EOC)
470 return 0;
471
472 /* The first cache has already been set up, so skip it */
473 i++;
474
475 /* Look through the remaining clusters, and set up their caches */
476 do {
Prabhakar Kushwahaccf0e682012-12-23 19:25:18 +0000477 int j, cluster_valid = 0;
478
York Sunc3d87b12012-10-08 07:44:08 +0000479 l2cache = (void __iomem *)(CONFIG_SYS_FSL_CLUSTER_1_L2 + i * 0x40000);
Prabhakar Kushwahaccf0e682012-12-23 19:25:18 +0000480
York Sunc3d87b12012-10-08 07:44:08 +0000481 cluster = in_be32(&gur->tp_cluster[i].lower);
482
Prabhakar Kushwahaccf0e682012-12-23 19:25:18 +0000483 /* check that at least one core/accel is enabled in cluster */
484 for (j = 0; j < 4; j++) {
485 u32 idx = (cluster >> (j*8)) & TP_CLUSTER_INIT_MASK;
486 u32 type = in_be32(&gur->tp_ityp[idx]);
York Sunc3d87b12012-10-08 07:44:08 +0000487
Shaveta Leekha6e125a22014-07-02 11:44:54 +0530488 if ((type & TP_ITYP_AV) &&
489 TP_ITYP_TYPE(type) == TP_ITYP_TYPE_PPC)
Prabhakar Kushwahaccf0e682012-12-23 19:25:18 +0000490 cluster_valid = 1;
491 }
492
493 if (cluster_valid) {
494 /* set stash ID to (cluster) * 2 + 32 + 1 */
495 clrsetbits_be32(&l2cache->l2csr1, 0xff, 32 + i * 2 + 1);
496
497 printf("enable l2 for cluster %d %p\n", i, l2cache);
York Sunc3d87b12012-10-08 07:44:08 +0000498
Prabhakar Kushwahaccf0e682012-12-23 19:25:18 +0000499 out_be32(&l2cache->l2csr0, L2CSR0_L2FI|L2CSR0_L2LFC);
500 while ((in_be32(&l2cache->l2csr0)
501 & (L2CSR0_L2FI|L2CSR0_L2LFC)) != 0)
502 ;
James Yang284ce502013-03-25 07:40:03 +0000503 out_be32(&l2cache->l2csr0, L2CSR0_L2E|L2CSR0_L2PE|L2CSR0_L2REP_MODE);
Prabhakar Kushwahaccf0e682012-12-23 19:25:18 +0000504 }
York Sunc3d87b12012-10-08 07:44:08 +0000505 i++;
506 } while (!(cluster & TP_CLUSTER_EOC));
507
508 return 0;
509}
510#endif
511
wdenk9c53f402003-10-15 23:53:47 +0000512/*
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500513 * Initialize L2 as cache.
wdenk9c53f402003-10-15 23:53:47 +0000514 */
Tang Yuantianefd6da62014-07-04 17:39:26 +0800515int l2cache_init(void)
wdenk9c53f402003-10-15 23:53:47 +0000516{
Timur Tabid7acf5c2011-11-21 17:10:23 -0600517 __maybe_unused u32 svr = get_svr();
York Sunc3d87b12012-10-08 07:44:08 +0000518#ifdef CONFIG_L2_CACHE
519 ccsr_l2cache_t *l2cache = (void __iomem *)CONFIG_SYS_MPC85xx_L2_ADDR;
Prabhakar Kushwahacc3c5b62013-08-29 13:10:38 +0530520#elif defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500)
York Sunc3d87b12012-10-08 07:44:08 +0000521 struct ccsr_cluster_l2 * l2cache = (void __iomem *)CONFIG_SYS_FSL_CLUSTER_1_L2;
Lan Chunhee0ef7322010-04-21 07:40:50 -0500522#endif
York Sunf066a042012-10-28 08:12:54 +0000523
Wolfgang Grandegger09cb1202008-06-05 13:11:59 +0200524 puts ("L2: ");
525
wdenk9c53f402003-10-15 23:53:47 +0000526#if defined(CONFIG_L2_CACHE)
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500527 volatile uint cache_ctl;
Timur Tabid7acf5c2011-11-21 17:10:23 -0600528 uint ver;
Kumar Gala20119972008-07-14 14:07:00 -0500529 u32 l2siz_field;
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500530
Kumar Gala1f109fd2008-04-08 10:45:50 -0500531 ver = SVR_SOC_VER(svr);
wdenk9c53f402003-10-15 23:53:47 +0000532
533 asm("msync;isync");
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500534 cache_ctl = l2cache->l2ctl;
Mingkai Hu0255cd72009-09-11 14:19:10 +0800535
536#if defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SYS_INIT_L2_ADDR)
537 if (cache_ctl & MPC85xx_L2CTL_L2E) {
538 /* Clear L2 SRAM memory-mapped base address */
539 out_be32(&l2cache->l2srbar0, 0x0);
540 out_be32(&l2cache->l2srbar1, 0x0);
541
542 /* set MBECCDIS=0, SBECCDIS=0 */
543 clrbits_be32(&l2cache->l2errdis,
544 (MPC85xx_L2ERRDIS_MBECC |
545 MPC85xx_L2ERRDIS_SBECC));
546
547 /* set L2E=0, L2SRAM=0 */
548 clrbits_be32(&l2cache->l2ctl,
549 (MPC85xx_L2CTL_L2E |
550 MPC85xx_L2CTL_L2SRAM_ENTIRE));
551 }
552#endif
553
Kumar Gala20119972008-07-14 14:07:00 -0500554 l2siz_field = (cache_ctl >> 28) & 0x3;
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500555
Kumar Gala20119972008-07-14 14:07:00 -0500556 switch (l2siz_field) {
557 case 0x0:
558 printf(" unknown size (0x%08x)\n", cache_ctl);
559 return -1;
560 break;
561 case 0x1:
562 if (ver == SVR_8540 || ver == SVR_8560 ||
York Sun8cb65482012-07-06 17:10:33 -0500563 ver == SVR_8541 || ver == SVR_8555) {
Shruti Kanetkar81159362013-08-15 11:25:38 -0500564 puts("128 KiB ");
565 /* set L2E=1, L2I=1, & L2BLKSZ=1 (128 KiBibyte) */
Kumar Gala20119972008-07-14 14:07:00 -0500566 cache_ctl = 0xc4000000;
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500567 } else {
Shruti Kanetkar81159362013-08-15 11:25:38 -0500568 puts("256 KiB ");
Kumar Gala20119972008-07-14 14:07:00 -0500569 cache_ctl = 0xc0000000; /* set L2E=1, L2I=1, & L2SRAM=0 */
570 }
571 break;
572 case 0x2:
573 if (ver == SVR_8540 || ver == SVR_8560 ||
York Sun8cb65482012-07-06 17:10:33 -0500574 ver == SVR_8541 || ver == SVR_8555) {
Shruti Kanetkar81159362013-08-15 11:25:38 -0500575 puts("256 KiB ");
576 /* set L2E=1, L2I=1, & L2BLKSZ=2 (256 KiBibyte) */
Ed Swarthoutdd93d8f2007-07-27 01:50:47 -0500577 cache_ctl = 0xc8000000;
Kumar Gala20119972008-07-14 14:07:00 -0500578 } else {
Shruti Kanetkar81159362013-08-15 11:25:38 -0500579 puts("512 KiB ");
Kumar Gala20119972008-07-14 14:07:00 -0500580 /* set L2E=1, L2I=1, & L2SRAM=0 */
581 cache_ctl = 0xc0000000;
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500582 }
Jon Loeliger4fc25e42005-07-25 10:58:39 -0500583 break;
Kumar Gala20119972008-07-14 14:07:00 -0500584 case 0x3:
Shruti Kanetkar81159362013-08-15 11:25:38 -0500585 puts("1024 KiB ");
Kumar Gala20119972008-07-14 14:07:00 -0500586 /* set L2E=1, L2I=1, & L2SRAM=0 */
587 cache_ctl = 0xc0000000;
Ed Swarthoutdd93d8f2007-07-27 01:50:47 -0500588 break;
Jon Loeliger4fc25e42005-07-25 10:58:39 -0500589 }
590
Mingkai Hud2088e02009-08-18 15:37:15 +0800591 if (l2cache->l2ctl & MPC85xx_L2CTL_L2E) {
Wolfgang Grandegger09cb1202008-06-05 13:11:59 +0200592 puts("already enabled");
Haiying Wang05beab72010-12-01 10:35:30 -0500593#if defined(CONFIG_SYS_INIT_L2_ADDR) && defined(CONFIG_SYS_FLASH_BASE)
Kumar Gala1882fab2011-11-09 09:56:41 -0600594 u32 l2srbar = l2cache->l2srbar0;
Mingkai Hud2088e02009-08-18 15:37:15 +0800595 if (l2cache->l2ctl & MPC85xx_L2CTL_L2SRAM_ENTIRE
596 && l2srbar >= CONFIG_SYS_FLASH_BASE) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200597 l2srbar = CONFIG_SYS_INIT_L2_ADDR;
Ed Swarthoutdd93d8f2007-07-27 01:50:47 -0500598 l2cache->l2srbar0 = l2srbar;
Scott Wood55f9f3a2012-10-29 19:00:41 -0500599 printf(", moving to 0x%08x", CONFIG_SYS_INIT_L2_ADDR);
Ed Swarthoutdd93d8f2007-07-27 01:50:47 -0500600 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200601#endif /* CONFIG_SYS_INIT_L2_ADDR */
Ed Swarthoutdd93d8f2007-07-27 01:50:47 -0500602 puts("\n");
603 } else {
604 asm("msync;isync");
605 l2cache->l2ctl = cache_ctl; /* invalidate & enable */
606 asm("msync;isync");
Wolfgang Grandegger09cb1202008-06-05 13:11:59 +0200607 puts("enabled\n");
Ed Swarthoutdd93d8f2007-07-27 01:50:47 -0500608 }
Kumar Galae56f2c52009-03-19 09:16:10 -0500609#elif defined(CONFIG_BACKSIDE_L2_CACHE)
York Sun8cb65482012-07-06 17:10:33 -0500610 if (SVR_SOC_VER(svr) == SVR_P2040) {
Kumar Galae08c6d82011-07-21 00:20:21 -0500611 puts("N/A\n");
612 goto skip_l2;
613 }
614
Kumar Galae56f2c52009-03-19 09:16:10 -0500615 u32 l2cfg0 = mfspr(SPRN_L2CFG0);
616
617 /* invalidate the L2 cache */
Kumar Galab6a40902009-09-22 15:45:44 -0500618 mtspr(SPRN_L2CSR0, (L2CSR0_L2FI|L2CSR0_L2LFC));
619 while (mfspr(SPRN_L2CSR0) & (L2CSR0_L2FI|L2CSR0_L2LFC))
Kumar Galae56f2c52009-03-19 09:16:10 -0500620 ;
621
Kumar Gala8d2817c2009-03-19 02:53:01 -0500622#ifdef CONFIG_SYS_CACHE_STASHING
623 /* set stash id to (coreID) * 2 + 32 + L2 (1) */
624 mtspr(SPRN_L2CSR1, (32 + 1));
625#endif
626
Kumar Galae56f2c52009-03-19 09:16:10 -0500627 /* enable the cache */
628 mtspr(SPRN_L2CSR0, CONFIG_SYS_INIT_L2CSR0);
629
Dave Liu17218192009-10-22 00:10:23 -0500630 if (CONFIG_SYS_INIT_L2CSR0 & L2CSR0_L2E) {
631 while (!(mfspr(SPRN_L2CSR0) & L2CSR0_L2E))
632 ;
Shruti Kanetkar3adfb912013-08-15 11:25:37 -0500633 print_size((l2cfg0 & 0x3fff) * 64 * 1024, " enabled\n");
Dave Liu17218192009-10-22 00:10:23 -0500634 }
Kumar Galae08c6d82011-07-21 00:20:21 -0500635
636skip_l2:
Prabhakar Kushwahacc3c5b62013-08-29 13:10:38 +0530637#elif defined(CONFIG_SYS_FSL_QORIQ_CHASSIS2) && defined(CONFIG_E6500)
York Sunc3d87b12012-10-08 07:44:08 +0000638 if (l2cache->l2csr0 & L2CSR0_L2E)
Shruti Kanetkar3adfb912013-08-15 11:25:37 -0500639 print_size((l2cache->l2cfg0 & 0x3fff) * 64 * 1024,
640 " enabled\n");
York Sunc3d87b12012-10-08 07:44:08 +0000641
642 enable_cluster_l2();
wdenk9c53f402003-10-15 23:53:47 +0000643#else
Wolfgang Grandegger09cb1202008-06-05 13:11:59 +0200644 puts("disabled\n");
wdenk9c53f402003-10-15 23:53:47 +0000645#endif
Kumar Gala76eef3e2009-03-19 03:40:08 -0500646
Tang Yuantianefd6da62014-07-04 17:39:26 +0800647 return 0;
648}
649
650/*
651 *
652 * The newer 8548, etc, parts have twice as much cache, but
653 * use the same bit-encoding as the older 8555, etc, parts.
654 *
655 */
656int cpu_init_r(void)
657{
658 __maybe_unused u32 svr = get_svr();
659#ifdef CONFIG_SYS_LBC_LCRR
660 fsl_lbc_t *lbc = (void __iomem *)LBC_BASE_ADDR;
661#endif
662#if defined(CONFIG_PPC_SPINTABLE_COMPATIBLE) && defined(CONFIG_MP)
663 extern int spin_table_compat;
664 const char *spin;
665#endif
666#ifdef CONFIG_SYS_FSL_ERRATUM_SEC_A003571
667 ccsr_sec_t __iomem *sec = (void *)CONFIG_SYS_FSL_SEC_ADDR;
668#endif
669#if defined(CONFIG_SYS_P4080_ERRATUM_CPU22) || \
670 defined(CONFIG_SYS_FSL_ERRATUM_NMG_CPU_A011)
671 /*
672 * CPU22 and NMG_CPU_A011 share the same workaround.
673 * CPU22 applies to P4080 rev 1.0, 2.0, fixed in 3.0
674 * NMG_CPU_A011 applies to P4080 rev 1.0, 2.0, fixed in 3.0
675 * also applies to P3041 rev 1.0, 1.1, P2041 rev 1.0, 1.1, both
676 * fixed in 2.0. NMG_CPU_A011 is activated by default and can
677 * be disabled by hwconfig with syntax:
678 *
679 * fsl_cpu_a011:disable
680 */
681 extern int enable_cpu_a011_workaround;
682#ifdef CONFIG_SYS_P4080_ERRATUM_CPU22
683 enable_cpu_a011_workaround = (SVR_MAJ(svr) < 3);
684#else
685 char buffer[HWCONFIG_BUFFER_SIZE];
686 char *buf = NULL;
687 int n, res;
688
Simon Glass64b723f2017-08-03 12:22:12 -0600689 n = env_get_f("hwconfig", buffer, sizeof(buffer));
Tang Yuantianefd6da62014-07-04 17:39:26 +0800690 if (n > 0)
691 buf = buffer;
692
693 res = hwconfig_arg_cmp_f("fsl_cpu_a011", "disable", buf);
694 if (res > 0) {
695 enable_cpu_a011_workaround = 0;
696 } else {
697 if (n >= HWCONFIG_BUFFER_SIZE) {
698 printf("fsl_cpu_a011 was not found. hwconfig variable "
699 "may be too long\n");
700 }
701 enable_cpu_a011_workaround =
702 (SVR_SOC_VER(svr) == SVR_P4080 && SVR_MAJ(svr) < 3) ||
703 (SVR_SOC_VER(svr) != SVR_P4080 && SVR_MAJ(svr) < 2);
704 }
705#endif
706 if (enable_cpu_a011_workaround) {
707 flush_dcache();
708 mtspr(L1CSR2, (mfspr(L1CSR2) | L1CSR2_DCWS));
709 sync();
710 }
711#endif
Darwin Dingela56d6c02016-10-25 09:48:01 +1300712
713#ifdef CONFIG_SYS_FSL_ERRATUM_A007907
714 flush_dcache();
715 mtspr(L1CSR2, (mfspr(L1CSR2) & ~L1CSR2_DCSTASHID));
716 sync();
717#endif
718
Tang Yuantianefd6da62014-07-04 17:39:26 +0800719#ifdef CONFIG_SYS_FSL_ERRATUM_A005812
720 /*
721 * A-005812 workaround sets bit 32 of SPR 976 for SoCs running
722 * in write shadow mode. Checking DCWS before setting SPR 976.
723 */
724 if (mfspr(L1CSR2) & L1CSR2_DCWS)
725 mtspr(SPRN_HDBCR0, (mfspr(SPRN_HDBCR0) | 0x80000000));
726#endif
727
728#if defined(CONFIG_PPC_SPINTABLE_COMPATIBLE) && defined(CONFIG_MP)
Simon Glass64b723f2017-08-03 12:22:12 -0600729 spin = env_get("spin_table_compat");
Tang Yuantianefd6da62014-07-04 17:39:26 +0800730 if (spin && (*spin == 'n'))
731 spin_table_compat = 0;
732 else
733 spin_table_compat = 1;
734#endif
735
Prabhakar Kushwaha1de43cf2016-01-22 14:34:44 +0530736#ifdef CONFIG_FSL_CORENET
737 set_liodns();
738#ifdef CONFIG_SYS_DPAA_QBMAN
Ahmed Mansouraa270b42017-12-15 16:01:00 -0500739 setup_qbman_portals();
Prabhakar Kushwaha1de43cf2016-01-22 14:34:44 +0530740#endif
741#endif
742
Tang Yuantianefd6da62014-07-04 17:39:26 +0800743 l2cache_init();
Aneesh Bansal8bcbc272014-03-18 23:40:26 +0530744#if defined(CONFIG_RAMBOOT_PBL)
745 disable_cpc_sram();
746#endif
Kumar Gala76eef3e2009-03-19 03:40:08 -0500747 enable_cpc();
Sandeep Singh4fb16a12014-06-05 18:49:57 +0530748#if defined(T1040_TDM_QUIRK_CCSR_BASE)
749 enable_tdm_law();
750#endif
Kumar Gala76eef3e2009-03-19 03:40:08 -0500751
York Sun972cc402013-06-25 11:37:41 -0700752#ifndef CONFIG_SYS_FSL_NO_SERDES
Kumar Gala86853d42010-05-22 13:21:39 -0500753 /* needs to be in ram since code uses global static vars */
754 fsl_serdes_init();
York Sun972cc402013-06-25 11:37:41 -0700755#endif
Kumar Gala86853d42010-05-22 13:21:39 -0500756
Shengzhou Liu097be702013-08-15 09:31:47 +0800757#ifdef CONFIG_SYS_FSL_ERRATUM_SEC_A003571
758#define MCFGR_AXIPIPE 0x000000f0
759 if (IS_SVR_REV(svr, 1, 0))
Ruchika Guptabb7143b2014-09-09 11:50:31 +0530760 sec_clrbits32(&sec->mcfgr, MCFGR_AXIPIPE);
Shengzhou Liu097be702013-08-15 09:31:47 +0800761#endif
762
Shengzhou Liu95bd8e52013-01-23 19:56:23 +0000763#ifdef CONFIG_SYS_FSL_ERRATUM_A005871
764 if (IS_SVR_REV(svr, 1, 0)) {
765 int i;
766 __be32 *p = (void __iomem *)CONFIG_SYS_DCSRBAR + 0xb004c;
767
768 for (i = 0; i < 12; i++) {
769 p += i + (i > 5 ? 11 : 0);
770 out_be32(p, 0x2);
771 }
772 p = (void __iomem *)CONFIG_SYS_DCSRBAR + 0xb0108;
773 out_be32(p, 0x34);
774 }
775#endif
776
Kumar Gala8975d7a2010-12-30 12:09:53 -0600777#ifdef CONFIG_SYS_SRIO
778 srio_init();
Liu Gang27afb9c2013-05-07 16:30:46 +0800779#ifdef CONFIG_SRIO_PCIE_BOOT_MASTER
Simon Glass64b723f2017-08-03 12:22:12 -0600780 char *s = env_get("bootmaster");
Liu Gangd7b17a92012-08-09 05:09:59 +0000781 if (s) {
782 if (!strcmp(s, "SRIO1")) {
783 srio_boot_master(1);
784 srio_boot_master_release_slave(1);
785 }
786 if (!strcmp(s, "SRIO2")) {
787 srio_boot_master(2);
788 srio_boot_master_release_slave(2);
789 }
790 }
Liu Gang4cc85322012-03-08 00:33:17 +0000791#endif
Kumar Gala8975d7a2010-12-30 12:09:53 -0600792#endif
793
Kumar Gala36d6b3f2008-01-17 16:48:33 -0600794#if defined(CONFIG_MP)
795 setup_mp();
796#endif
Lan Chunhee0ef7322010-04-21 07:40:50 -0500797
Zang Roy-R6191183659922012-09-18 09:50:08 +0000798#ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC13
Roy Zangc65dc4d2011-01-07 00:24:27 -0600799 {
Zang Roy-R6191183659922012-09-18 09:50:08 +0000800 if (SVR_MAJ(svr) < 3) {
801 void *p;
802 p = (void *)CONFIG_SYS_DCSRBAR + 0x20520;
803 setbits_be32(p, 1 << (31 - 14));
804 }
Roy Zangc65dc4d2011-01-07 00:24:27 -0600805 }
806#endif
807
Lan Chunhee0ef7322010-04-21 07:40:50 -0500808#ifdef CONFIG_SYS_LBC_LCRR
809 /*
810 * Modify the CLKDIV field of LCRR register to improve the writing
811 * speed for NOR flash.
812 */
813 clrsetbits_be32(&lbc->lcrr, LCRR_CLKDIV, CONFIG_SYS_LBC_LCRR);
814 __raw_readl(&lbc->lcrr);
815 isync();
Kumar Galaf3339d62011-10-03 08:37:57 -0500816#ifdef CONFIG_SYS_FSL_ERRATUM_NMG_LBC103
817 udelay(100);
818#endif
Lan Chunhee0ef7322010-04-21 07:40:50 -0500819#endif
820
Roy Zang6d6a0e12011-04-13 00:08:51 -0500821#ifdef CONFIG_SYS_FSL_USB1_PHY_ENABLE
822 {
ramneek mehreshc65e8822013-08-05 16:00:16 +0530823 struct ccsr_usb_phy __iomem *usb_phy1 =
Roy Zang6d6a0e12011-04-13 00:08:51 -0500824 (void *)CONFIG_SYS_MPC85xx_USB1_PHY_ADDR;
Suresh Gupta086f0a72014-02-26 14:29:12 +0530825#ifdef CONFIG_SYS_FSL_ERRATUM_A006261
826 if (has_erratum_a006261())
827 fsl_erratum_a006261_workaround(usb_phy1);
828#endif
Roy Zang6d6a0e12011-04-13 00:08:51 -0500829 out_be32(&usb_phy1->usb_enable_override,
830 CONFIG_SYS_FSL_USB_ENABLE_OVERRIDE);
831 }
832#endif
833#ifdef CONFIG_SYS_FSL_USB2_PHY_ENABLE
834 {
ramneek mehreshc65e8822013-08-05 16:00:16 +0530835 struct ccsr_usb_phy __iomem *usb_phy2 =
Roy Zang6d6a0e12011-04-13 00:08:51 -0500836 (void *)CONFIG_SYS_MPC85xx_USB2_PHY_ADDR;
Suresh Gupta086f0a72014-02-26 14:29:12 +0530837#ifdef CONFIG_SYS_FSL_ERRATUM_A006261
838 if (has_erratum_a006261())
839 fsl_erratum_a006261_workaround(usb_phy2);
840#endif
Roy Zang6d6a0e12011-04-13 00:08:51 -0500841 out_be32(&usb_phy2->usb_enable_override,
842 CONFIG_SYS_FSL_USB_ENABLE_OVERRIDE);
843 }
844#endif
845
Xuleicf4f4932013-03-11 17:56:34 +0000846#ifdef CONFIG_SYS_FSL_ERRATUM_USB14
847 /* On P204x/P304x/P50x0 Rev1.0, USB transmit will result internal
848 * multi-bit ECC errors which has impact on performance, so software
849 * should disable all ECC reporting from USB1 and USB2.
850 */
851 if (IS_SVR_REV(get_svr(), 1, 0)) {
852 struct dcsr_dcfg_regs *dcfg = (struct dcsr_dcfg_regs *)
853 (CONFIG_SYS_DCSRBAR + CONFIG_SYS_DCSR_DCFG_OFFSET);
854 setbits_be32(&dcfg->ecccr1,
855 (DCSR_DCFG_ECC_DISABLE_USB1 |
856 DCSR_DCFG_ECC_DISABLE_USB2));
857 }
858#endif
859
Roy Zang59a539a2013-03-25 07:39:33 +0000860#if defined(CONFIG_SYS_FSL_USB_DUAL_PHY_ENABLE)
ramneek mehreshc65e8822013-08-05 16:00:16 +0530861 struct ccsr_usb_phy __iomem *usb_phy =
Roy Zang59a539a2013-03-25 07:39:33 +0000862 (void *)CONFIG_SYS_MPC85xx_USB1_PHY_ADDR;
863 setbits_be32(&usb_phy->pllprg[1],
864 CONFIG_SYS_FSL_USB_PLLPRG2_PHY2_CLK_EN |
865 CONFIG_SYS_FSL_USB_PLLPRG2_PHY1_CLK_EN |
866 CONFIG_SYS_FSL_USB_PLLPRG2_MFI |
867 CONFIG_SYS_FSL_USB_PLLPRG2_PLL_EN);
Nikhil Badola006e83a2014-04-15 14:44:52 +0530868#ifdef CONFIG_SYS_FSL_SINGLE_SOURCE_CLK
869 usb_single_source_clk_configure(usb_phy);
870#endif
Roy Zang59a539a2013-03-25 07:39:33 +0000871 setbits_be32(&usb_phy->port1.ctrl,
872 CONFIG_SYS_FSL_USB_CTRL_PHY_EN);
873 setbits_be32(&usb_phy->port1.drvvbuscfg,
874 CONFIG_SYS_FSL_USB_DRVVBUS_CR_EN);
875 setbits_be32(&usb_phy->port1.pwrfltcfg,
876 CONFIG_SYS_FSL_USB_PWRFLT_CR_EN);
877 setbits_be32(&usb_phy->port2.ctrl,
878 CONFIG_SYS_FSL_USB_CTRL_PHY_EN);
879 setbits_be32(&usb_phy->port2.drvvbuscfg,
880 CONFIG_SYS_FSL_USB_DRVVBUS_CR_EN);
881 setbits_be32(&usb_phy->port2.pwrfltcfg,
882 CONFIG_SYS_FSL_USB_PWRFLT_CR_EN);
Suresh Gupta086f0a72014-02-26 14:29:12 +0530883
884#ifdef CONFIG_SYS_FSL_ERRATUM_A006261
885 if (has_erratum_a006261())
886 fsl_erratum_a006261_workaround(usb_phy);
Roy Zang59a539a2013-03-25 07:39:33 +0000887#endif
888
Suresh Gupta086f0a72014-02-26 14:29:12 +0530889#endif /* CONFIG_SYS_FSL_USB_DUAL_PHY_ENABLE */
890
Shengzhou Liu15875a52016-11-21 11:36:48 +0800891#ifdef CONFIG_SYS_FSL_ERRATUM_A009942
892 erratum_a009942_check_cpo();
893#endif
894
Kumar Gala2683c532011-04-13 08:37:44 -0500895#ifdef CONFIG_FMAN_ENET
Madalin Bucur70848512020-04-30 15:59:58 +0300896#ifndef CONFIG_DM_ETH
Kumar Gala2683c532011-04-13 08:37:44 -0500897 fman_enet_init();
898#endif
Madalin Bucur70848512020-04-30 15:59:58 +0300899#endif
Kumar Gala2683c532011-04-13 08:37:44 -0500900
Udit Agarwald2dd2f72019-11-07 16:11:39 +0000901#if defined(CONFIG_NXP_ESBC) && defined(CONFIG_FSL_CORENET)
Aneesh Bansal4b636c32016-01-22 17:05:59 +0530902 if (pamu_init() < 0)
903 fsl_secboot_handle_error(ERROR_ESBC_PAMU_INIT);
904#endif
905
Ruchika Guptaac1b2692014-10-15 11:35:30 +0530906#ifdef CONFIG_FSL_CAAM
York Sun4119aee2016-11-15 18:44:22 -0800907#if defined(CONFIG_ARCH_C29X)
Alex Porosanu7703d1e2016-04-29 15:18:00 +0300908 if ((SVR_SOC_VER(svr) == SVR_C292) ||
909 (SVR_SOC_VER(svr) == SVR_C293))
910 sec_init_idx(1);
911
912 if (SVR_SOC_VER(svr) == SVR_C293)
913 sec_init_idx(2);
914#endif
Ruchika Guptaac1b2692014-10-15 11:35:30 +0530915#endif
916
York Sunbe735532016-12-28 08:43:43 -0800917#if defined(CONFIG_FSL_SATA_V2) && defined(CONFIG_SYS_FSL_ERRATUM_SATA_A001)
Timur Tabid7acf5c2011-11-21 17:10:23 -0600918 /*
919 * For P1022/1013 Rev1.0 silicon, after power on SATA host
920 * controller is configured in legacy mode instead of the
921 * expected enterprise mode. Software needs to clear bit[28]
922 * of HControl register to change to enterprise mode from
923 * legacy mode. We assume that the controller is offline.
924 */
925 if (IS_SVR_REV(svr, 1, 0) &&
926 ((SVR_SOC_VER(svr) == SVR_P1022) ||
York Sun8cb65482012-07-06 17:10:33 -0500927 (SVR_SOC_VER(svr) == SVR_P1013))) {
Timur Tabid7acf5c2011-11-21 17:10:23 -0600928 fsl_sata_reg_t *reg;
929
930 /* first SATA controller */
931 reg = (void *)CONFIG_SYS_MPC85xx_SATA1_ADDR;
932 clrbits_le32(&reg->hcontrol, HCONTROL_ENTERPRISE_EN);
933
934 /* second SATA controller */
935 reg = (void *)CONFIG_SYS_MPC85xx_SATA2_ADDR;
936 clrbits_le32(&reg->hcontrol, HCONTROL_ENTERPRISE_EN);
937 }
938#endif
939
Alexander Grafcfb90e32014-04-30 19:21:12 +0200940 init_used_tlb_cams();
Timur Tabid7acf5c2011-11-21 17:10:23 -0600941
wdenk9c53f402003-10-15 23:53:47 +0000942 return 0;
943}
Kumar Galac24a9052009-08-14 13:37:54 -0500944
Gaurav Jain7f19c3b2022-03-24 11:50:37 +0530945#ifdef CONFIG_ARCH_MISC_INIT
946int arch_misc_init(void)
947{
948 if (IS_ENABLED(CONFIG_FSL_CAAM)) {
949 struct udevice *dev;
950 int ret;
951
952 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev);
953 if (ret)
Ye Liec346892022-05-11 13:56:20 +0530954 printf("Failed to initialize caam_jr: %d\n", ret);
Gaurav Jain7f19c3b2022-03-24 11:50:37 +0530955 }
956
957 return 0;
958}
959#endif
960
Kumar Galac24a9052009-08-14 13:37:54 -0500961void arch_preboot_os(void)
962{
Kumar Gala9faa23a2009-09-11 15:28:41 -0500963 u32 msr;
964
965 /*
966 * We are changing interrupt offsets and are about to boot the OS so
967 * we need to make sure we disable all async interrupts. EE is already
968 * disabled by the time we get called.
969 */
970 msr = mfmsr();
Prabhakar Kushwaha8f3e8922012-04-29 23:56:30 +0000971 msr &= ~(MSR_ME|MSR_CE);
Kumar Gala9faa23a2009-09-11 15:28:41 -0500972 mtmsr(msr);
Kumar Galac24a9052009-08-14 13:37:54 -0500973}
Kumar Galaeb453df2010-04-20 10:21:25 -0500974
Ovidiu Panaitc14c0f92020-11-28 10:43:09 +0200975int cpu_secondary_init_r(void)
Kumar Gala2ef216b2011-02-02 11:23:50 -0600976{
Madalin Bucur9be4dea2020-04-29 12:16:38 +0300977#ifdef CONFIG_QE
Zhao Qiangb818ba22014-03-21 16:21:45 +0800978#ifdef CONFIG_U_QE
979 uint qe_base = CONFIG_SYS_IMMR + 0x00140000; /* QE immr base */
Madalin Bucur9be4dea2020-04-29 12:16:38 +0300980#else
Kumar Gala2ef216b2011-02-02 11:23:50 -0600981 uint qe_base = CONFIG_SYS_IMMR + 0x00080000; /* QE immr base */
Zhao Qiangb818ba22014-03-21 16:21:45 +0800982#endif
983
Kumar Gala2ef216b2011-02-02 11:23:50 -0600984 qe_init(qe_base);
985 qe_reset();
986#endif
Ovidiu Panaitc14c0f92020-11-28 10:43:09 +0200987
988 return 0;
Aneesh Bansalc6249092016-01-22 16:37:27 +0530989}
990
991#ifdef CONFIG_BOARD_LATE_INIT
992int board_late_init(void)
993{
994#ifdef CONFIG_CHAIN_OF_TRUST
995 fsl_setenv_chain_of_trust();
996#endif
997
998 return 0;
Kumar Gala2ef216b2011-02-02 11:23:50 -0600999}
Aneesh Bansalc6249092016-01-22 16:37:27 +05301000#endif