blob: 574510fa0883955019e64d90700cbb0e3fccf2c9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kumar Gala64dd1782009-09-11 13:52:45 -05002/*
Prabhakar Kushwahabc8d57c2012-04-29 23:56:43 +00003 * Copyright 2009-2012 Freescale Semiconductor, Inc
Kumar Gala64dd1782009-09-11 13:52:45 -05004 */
5
Tom Rinidec7ea02024-05-20 13:35:03 -06006#include <asm/ppc.h>
Tom Rini4ddbade2022-05-25 12:16:03 -04007#include <system-constants.h>
Tom Rinidec7ea02024-05-20 13:35:03 -06008#include <linux/types.h>
Simon Glass40d9b242020-05-10 11:40:07 -06009#include <asm-offsets.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <asm/global_data.h>
Kumar Gala64dd1782009-09-11 13:52:45 -050011#include <asm/processor.h>
12#include <asm/mmu.h>
13#include <asm/fsl_law.h>
Poonam Aggrwalee90b1c2011-06-29 16:32:50 +053014#include <asm/io.h>
Kumar Gala64dd1782009-09-11 13:52:45 -050015
16DECLARE_GLOBAL_DATA_PTR;
17
Prabhakar Kushwahad324f472013-04-16 13:27:44 +053018#ifdef CONFIG_A003399_NOR_WORKAROUND
Poonam Aggrwal46b86ca2011-07-07 20:36:47 +053019void setup_ifc(void)
20{
Tom Rini6a5dccc2022-11-16 13:10:41 -050021 struct fsl_ifc ifc_regs = {(void *)CFG_SYS_IFC_ADDR, (void *)NULL};
Poonam Aggrwal46b86ca2011-07-07 20:36:47 +053022 u32 _mas0, _mas1, _mas2, _mas3, _mas7;
Tom Rini6a5dccc2022-11-16 13:10:41 -050023 phys_addr_t flash_phys = CFG_SYS_FLASH_BASE_PHYS;
Poonam Aggrwal46b86ca2011-07-07 20:36:47 +053024
25 /*
26 * Adjust the TLB we were running out of to match the phys addr of the
27 * chip select we are adjusting and will return to.
28 */
Tom Rini6a5dccc2022-11-16 13:10:41 -050029 flash_phys += (~CFG_SYS_AMASK0) + 1 - 4*1024*1024;
Poonam Aggrwal46b86ca2011-07-07 20:36:47 +053030
31 _mas0 = MAS0_TLBSEL(1) | MAS0_ESEL(15);
32 _mas1 = MAS1_VALID | MAS1_TID(0) | MAS1_TS | MAS1_IPROT |
33 MAS1_TSIZE(BOOKE_PAGESZ_4M);
Simon Glass72cc5382022-10-20 18:22:39 -060034 _mas2 = FSL_BOOKE_MAS2(CONFIG_TEXT_BASE, MAS2_I | MAS2_G);
Poonam Aggrwal46b86ca2011-07-07 20:36:47 +053035 _mas3 = FSL_BOOKE_MAS3(flash_phys, 0, MAS3_SW|MAS3_SR|MAS3_SX);
36 _mas7 = FSL_BOOKE_MAS7(flash_phys);
37
38 mtspr(MAS0, _mas0);
39 mtspr(MAS1, _mas1);
40 mtspr(MAS2, _mas2);
41 mtspr(MAS3, _mas3);
42 mtspr(MAS7, _mas7);
43
44 asm volatile("isync;msync;tlbwe;isync");
45
Prabhakar Kushwahabc8d57c2012-04-29 23:56:43 +000046#if defined(CONFIG_SYS_PPC_E500_DEBUG_TLB)
47/*
48 * TLB entry for debuggging in AS1
49 * Create temporary TLB entry in AS0 to handle debug exception
50 * As on debug exception MSR is cleared i.e. Address space is changed
51 * to 0. A TLB entry (in AS0) is required to handle debug exception generated
52 * in AS1.
53 *
54 * TLB entry is created for IVPR + IVOR15 to map on valid OP code address
55 * bacause flash's physical address is going to change as
Tom Rini6a5dccc2022-11-16 13:10:41 -050056 * CFG_SYS_FLASH_BASE_PHYS.
Prabhakar Kushwahabc8d57c2012-04-29 23:56:43 +000057 */
58 _mas0 = MAS0_TLBSEL(1) |
59 MAS0_ESEL(CONFIG_SYS_PPC_E500_DEBUG_TLB);
60 _mas1 = MAS1_VALID | MAS1_TID(0) | MAS1_IPROT |
61 MAS1_TSIZE(BOOKE_PAGESZ_4M);
Simon Glass72cc5382022-10-20 18:22:39 -060062 _mas2 = FSL_BOOKE_MAS2(CONFIG_TEXT_BASE, MAS2_I | MAS2_G);
Prabhakar Kushwahabc8d57c2012-04-29 23:56:43 +000063 _mas3 = FSL_BOOKE_MAS3(flash_phys, 0, MAS3_SW|MAS3_SR|MAS3_SX);
64 _mas7 = FSL_BOOKE_MAS7(flash_phys);
65
66 mtspr(MAS0, _mas0);
67 mtspr(MAS1, _mas1);
68 mtspr(MAS2, _mas2);
69 mtspr(MAS3, _mas3);
70 mtspr(MAS7, _mas7);
71
72 asm volatile("isync;msync;tlbwe;isync");
73#endif
74
75 /* Change flash's physical address */
Tom Rini6a5dccc2022-11-16 13:10:41 -050076 ifc_out32(&(ifc_regs.gregs->cspr_cs[0].cspr), CFG_SYS_CSPR0);
77 ifc_out32(&(ifc_regs.gregs->csor_cs[0].csor), CFG_SYS_CSOR0);
78 ifc_out32(&(ifc_regs.gregs->amask_cs[0].amask), CFG_SYS_AMASK0);
Poonam Aggrwal46b86ca2011-07-07 20:36:47 +053079
Bin Meng75a6a372022-10-26 12:40:07 +080080 return;
Poonam Aggrwal46b86ca2011-07-07 20:36:47 +053081}
82#endif
83
Kumar Gala64dd1782009-09-11 13:52:45 -050084/* We run cpu_init_early_f in AS = 1 */
Alexander Grafc3468482014-04-11 17:09:45 +020085void cpu_init_early_f(void *fdt)
Kumar Gala64dd1782009-09-11 13:52:45 -050086{
87 u32 mas0, mas1, mas2, mas3, mas7;
Poonam Aggrwalaf54a5f2011-06-29 16:32:52 +053088#ifdef CONFIG_SYS_FSL_ERRATUM_P1010_A003549
Tom Rinid5c3bf22022-10-28 20:27:12 -040089 ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
Poonam Aggrwalaf54a5f2011-06-29 16:32:52 +053090#endif
Prabhakar Kushwahad324f472013-04-16 13:27:44 +053091#ifdef CONFIG_A003399_NOR_WORKAROUND
Tom Rinid5c3bf22022-10-28 20:27:12 -040092 ccsr_l2cache_t *l2cache = (void *)CFG_SYS_MPC85xx_L2_ADDR;
Poonam Aggrwal66a02212011-11-01 18:58:20 +053093 u32 *dst, *src;
Poonam Aggrwal46b86ca2011-07-07 20:36:47 +053094 void (*setup_ifc_sram)(void);
mario.six@gdsys.ccd5928cd2016-04-05 15:05:37 +020095 int i;
Poonam Aggrwal46b86ca2011-07-07 20:36:47 +053096#endif
Kumar Gala64dd1782009-09-11 13:52:45 -050097
98 /* Pointer is writable since we allocated a register for it */
Tom Rini4ddbade2022-05-25 12:16:03 -040099 gd = (gd_t *)SYS_INIT_SP_ADDR;
Kumar Gala64dd1782009-09-11 13:52:45 -0500100
mario.six@gdsys.ccd5928cd2016-04-05 15:05:37 +0200101 /* gd area was zeroed during startup */
Kumar Gala64dd1782009-09-11 13:52:45 -0500102
York Sun51e91e82016-11-18 12:29:51 -0800103#ifdef CONFIG_ARCH_QEMU_E500
Alexander Grafc3468482014-04-11 17:09:45 +0200104 /*
Tom Rini6a5dccc2022-11-16 13:10:41 -0500105 * CFG_SYS_CCSRBAR_PHYS below may use gd->fdt_blob on ePAPR systems,
Alexander Grafc3468482014-04-11 17:09:45 +0200106 * so we need to populate it before it accesses it.
107 */
108 gd->fdt_blob = fdt;
York Sun2038b772014-04-30 14:43:45 -0700109#endif
Alexander Grafc3468482014-04-11 17:09:45 +0200110
Poonam Aggrwalee90b1c2011-06-29 16:32:50 +0530111 mas0 = MAS0_TLBSEL(1) | MAS0_ESEL(13);
112 mas1 = MAS1_VALID | MAS1_TID(0) | MAS1_TS | MAS1_TSIZE(BOOKE_PAGESZ_1M);
Tom Rini6a5dccc2022-11-16 13:10:41 -0500113 mas2 = FSL_BOOKE_MAS2(CFG_SYS_CCSRBAR, MAS2_I|MAS2_G);
114 mas3 = FSL_BOOKE_MAS3(CFG_SYS_CCSRBAR_PHYS, 0, MAS3_SW|MAS3_SR);
115 mas7 = FSL_BOOKE_MAS7(CFG_SYS_CCSRBAR_PHYS);
Kumar Gala64dd1782009-09-11 13:52:45 -0500116
117 write_tlb(mas0, mas1, mas2, mas3, mas7);
118
Poonam Aggrwalaf54a5f2011-06-29 16:32:52 +0530119/*
120 * Work Around for IFC Erratum A-003549. This issue is P1010
121 * specific. LCLK(a free running clk signal) is muxed with IFC_CS3 on P1010 SOC
122 * Hence specifically selecting CS3.
123 */
124#ifdef CONFIG_SYS_FSL_ERRATUM_P1010_A003549
125 setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_LCLK_IFC_CS3);
126#endif
127
Bin Mengc39f3402021-02-25 17:22:27 +0800128#ifdef CONFIG_FSL_LAW
Kumar Gala64dd1782009-09-11 13:52:45 -0500129 init_laws();
Bin Mengc39f3402021-02-25 17:22:27 +0800130#endif
Poonam Aggrwal46b86ca2011-07-07 20:36:47 +0530131
132/*
133 * Work Around for IFC Erratum A003399, issue will hit only when execution
134 * from NOR Flash
135 */
Prabhakar Kushwahad324f472013-04-16 13:27:44 +0530136#ifdef CONFIG_A003399_NOR_WORKAROUND
Poonam Aggrwal46b86ca2011-07-07 20:36:47 +0530137#define SRAM_BASE_ADDR (0x00000000)
138 /* TLB for SRAM */
139 mas0 = MAS0_TLBSEL(1) | MAS0_ESEL(9);
140 mas1 = MAS1_VALID | MAS1_TID(0) | MAS1_TS |
141 MAS1_TSIZE(BOOKE_PAGESZ_1M);
142 mas2 = FSL_BOOKE_MAS2(SRAM_BASE_ADDR, MAS2_I);
143 mas3 = FSL_BOOKE_MAS3(SRAM_BASE_ADDR, 0, MAS3_SX|MAS3_SW|MAS3_SR);
144 mas7 = FSL_BOOKE_MAS7(0);
145
146 write_tlb(mas0, mas1, mas2, mas3, mas7);
147
148 out_be32(&l2cache->l2srbar0, SRAM_BASE_ADDR);
149
150 out_be32(&l2cache->l2errdis,
151 (MPC85xx_L2ERRDIS_MBECC | MPC85xx_L2ERRDIS_SBECC));
152
153 out_be32(&l2cache->l2ctl,
154 (MPC85xx_L2CTL_L2E | MPC85xx_L2CTL_L2SRAM_ENTIRE));
155
156 /*
157 * Copy the code in setup_ifc to L2SRAM. Do a word copy
158 * because NOR Flash on P1010 does not support byte
159 * access (Erratum IFC-A002769)
160 */
161 setup_ifc_sram = (void *)SRAM_BASE_ADDR;
162 dst = (u32 *) SRAM_BASE_ADDR;
163 src = (u32 *) setup_ifc;
Wolfgang Denk6ae80832014-11-06 14:02:57 +0100164 for (i = 0; i < 1024; i++) {
165 /* cppcheck-suppress nullPointer */
Poonam Aggrwal66a02212011-11-01 18:58:20 +0530166 *dst++ = *src++;
Wolfgang Denk6ae80832014-11-06 14:02:57 +0100167 }
Poonam Aggrwal46b86ca2011-07-07 20:36:47 +0530168
Wolfgang Denk6ae80832014-11-06 14:02:57 +0100169 /* cppcheck-suppress nullPointer */
Poonam Aggrwal46b86ca2011-07-07 20:36:47 +0530170 setup_ifc_sram();
171
172 /* CLEANUP */
173 clrbits_be32(&l2cache->l2ctl,
174 (MPC85xx_L2CTL_L2E |
175 MPC85xx_L2CTL_L2SRAM_ENTIRE));
176 out_be32(&l2cache->l2srbar0, 0x0);
177#endif
178
Poonam Aggrwalee90b1c2011-06-29 16:32:50 +0530179 invalidate_tlb(1);
Ruchika Gupta8ca8d822010-12-15 17:02:08 +0000180
Prabhakar Kushwaha11dee962013-07-05 11:59:26 +0530181#if defined(CONFIG_SYS_PPC_E500_DEBUG_TLB) && \
Tom Rini6b15c162022-05-13 12:26:35 -0400182 !(CONFIG_IS_ENABLED(INIT_MINIMAL) && defined(CONFIG_SPL_BUILD)) && \
Prabhakar Kushwaha11dee962013-07-05 11:59:26 +0530183 !defined(CONFIG_NAND_SPL)
Prabhakar Kushwahac2ea92b2013-06-13 10:14:00 +0530184 disable_tlb(CONFIG_SYS_PPC_E500_DEBUG_TLB);
185#endif
186
Kumar Gala64dd1782009-09-11 13:52:45 -0500187 init_tlbs();
188}