blob: 002ff7988b90b7eb8695fe2ed9622024947171d5 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk11a72d92002-10-27 22:25:25 +00002/*
3 * (C) Copyright 2002
4 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
5 * Marius Groeger <mgroeger@sysgo.de>
6 *
7 * (C) Copyright 2002
8 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
9 * Alex Zuepke <azu@sysgo.de>
wdenk11a72d92002-10-27 22:25:25 +000010 */
11
Marcel Ziswiler67b855f2015-08-16 04:16:26 +020012#include <common.h>
Simon Glass9edefc22019-11-14 12:57:37 -070013#include <cpu_func.h>
Simon Glass36bf4462019-11-14 12:57:42 -070014#include <irq_func.h>
Marcel Ziswiler67b855f2015-08-16 04:16:26 +020015#include <asm/arch/pxa-regs.h>
Marek Vasut3ba8bf72010-09-09 09:50:39 +020016#include <asm/io.h>
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +020017#include <asm/system.h>
Marek Vasut3ba8bf72010-09-09 09:50:39 +020018#include <command.h>
wdenk11a72d92002-10-27 22:25:25 +000019
Marek Vasutd10237d2011-11-26 07:32:24 +010020/* Flush I/D-cache */
21static void cache_flush(void)
wdenk11a72d92002-10-27 22:25:25 +000022{
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020023 unsigned long i = 0;
wdenk11a72d92002-10-27 22:25:25 +000024
Marek Vasutd10237d2011-11-26 07:32:24 +010025 asm ("mcr p15, 0, %0, c7, c5, 0" : : "r" (i));
wdenk11a72d92002-10-27 22:25:25 +000026}
wdenk71f95112003-06-15 22:40:42 +000027
Marek Vasutd10237d2011-11-26 07:32:24 +010028int cleanup_before_linux(void)
wdenk71f95112003-06-15 22:40:42 +000029{
Marek Vasutd10237d2011-11-26 07:32:24 +010030 /*
31 * This function is called just before we call Linux. It prepares
32 * the processor for Linux by just disabling everything that can
33 * disturb booting Linux.
34 */
Marek Vasut3ba8bf72010-09-09 09:50:39 +020035
Marek Vasutd10237d2011-11-26 07:32:24 +010036 disable_interrupts();
37 icache_disable();
38 dcache_disable();
39 cache_flush();
wdenk71f95112003-06-15 22:40:42 +000040
Marek Vasutd10237d2011-11-26 07:32:24 +010041 return 0;
wdenk71f95112003-06-15 22:40:42 +000042}
Marek Vasut2cad92f2010-09-28 15:44:10 +020043
Marek Vasut2cad92f2010-09-28 15:44:10 +020044inline void writelrb(uint32_t val, uint32_t addr)
45{
46 writel(val, addr);
Marek Vasutd10237d2011-11-26 07:32:24 +010047 asm volatile("" : : : "memory");
Marek Vasut2cad92f2010-09-28 15:44:10 +020048 readl(addr);
Marek Vasutd10237d2011-11-26 07:32:24 +010049 asm volatile("" : : : "memory");
Marek Vasut2cad92f2010-09-28 15:44:10 +020050}
51
Marek Vasutf68d2a22011-11-26 11:18:57 +010052void pxa2xx_dram_init(void)
Marek Vasut2cad92f2010-09-28 15:44:10 +020053{
54 uint32_t tmp;
55 int i;
56 /*
57 * 1) Initialize Asynchronous static memory controller
58 */
59
60 writelrb(CONFIG_SYS_MSC0_VAL, MSC0);
61 writelrb(CONFIG_SYS_MSC1_VAL, MSC1);
62 writelrb(CONFIG_SYS_MSC2_VAL, MSC2);
63 /*
64 * 2) Initialize Card Interface
65 */
66
67 /* MECR: Memory Expansion Card Register */
68 writelrb(CONFIG_SYS_MECR_VAL, MECR);
69 /* MCMEM0: Card Interface slot 0 timing */
70 writelrb(CONFIG_SYS_MCMEM0_VAL, MCMEM0);
71 /* MCMEM1: Card Interface slot 1 timing */
72 writelrb(CONFIG_SYS_MCMEM1_VAL, MCMEM1);
73 /* MCATT0: Card Interface Attribute Space Timing, slot 0 */
74 writelrb(CONFIG_SYS_MCATT0_VAL, MCATT0);
75 /* MCATT1: Card Interface Attribute Space Timing, slot 1 */
76 writelrb(CONFIG_SYS_MCATT1_VAL, MCATT1);
77 /* MCIO0: Card Interface I/O Space Timing, slot 0 */
78 writelrb(CONFIG_SYS_MCIO0_VAL, MCIO0);
79 /* MCIO1: Card Interface I/O Space Timing, slot 1 */
80 writelrb(CONFIG_SYS_MCIO1_VAL, MCIO1);
81
82 /*
83 * 3) Configure Fly-By DMA register
84 */
85
86 writelrb(CONFIG_SYS_FLYCNFG_VAL, FLYCNFG);
87
88 /*
89 * 4) Initialize Timing for Sync Memory (SDCLK0)
90 */
91
92 /*
93 * Before accessing MDREFR we need a valid DRI field, so we set
94 * this to power on defaults + DRI field.
95 */
96
97 /* Read current MDREFR config and zero out DRI */
98 tmp = readl(MDREFR) & ~0xfff;
99 /* Add user-specified DRI */
100 tmp |= CONFIG_SYS_MDREFR_VAL & 0xfff;
101 /* Configure important bits */
102 tmp |= MDREFR_K0RUN | MDREFR_SLFRSH;
103 tmp &= ~(MDREFR_APD | MDREFR_E1PIN);
104
105 /* Write MDREFR back */
106 writelrb(tmp, MDREFR);
107
108 /*
109 * 5) Initialize Synchronous Static Memory (Flash/Peripherals)
110 */
111
112 /* Initialize SXCNFG register. Assert the enable bits.
113 *
114 * Write SXMRS to cause an MRS command to all enabled banks of
115 * synchronous static memory. Note that SXLCR need not be written
116 * at this time.
117 */
118 writelrb(CONFIG_SYS_SXCNFG_VAL, SXCNFG);
119
120 /*
121 * 6) Initialize SDRAM
122 */
123
124 writelrb(CONFIG_SYS_MDREFR_VAL & ~MDREFR_SLFRSH, MDREFR);
125 writelrb(CONFIG_SYS_MDREFR_VAL | MDREFR_E1PIN, MDREFR);
126
127 /*
128 * 7) Write MDCNFG with MDCNFG:DEx deasserted (set to 0), to configure
129 * but not enable each SDRAM partition pair.
130 */
131
132 writelrb(CONFIG_SYS_MDCNFG_VAL &
133 ~(MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3), MDCNFG);
Simon Glasse3107d12019-11-14 12:57:28 -0700134
Marek Vasut2cad92f2010-09-28 15:44:10 +0200135 /* Wait for the clock to the SDRAMs to stabilize, 100..200 usec. */
Simon Glasse3107d12019-11-14 12:57:28 -0700136 writel(0, OSCR);
137 while (readl(OSCR) < 0x300)
138 asm volatile("" : : : "memory");
Marek Vasut2cad92f2010-09-28 15:44:10 +0200139
140 /*
141 * 8) Trigger a number (usually 8) refresh cycles by attempting
142 * non-burst read or write accesses to disabled SDRAM, as commonly
143 * specified in the power up sequence documented in SDRAM data
144 * sheets. The address(es) used for this purpose must not be
145 * cacheable.
146 */
147 for (i = 9; i >= 0; i--) {
148 writel(i, 0xa0000000);
Marek Vasutd10237d2011-11-26 07:32:24 +0100149 asm volatile("" : : : "memory");
Marek Vasut2cad92f2010-09-28 15:44:10 +0200150 }
151 /*
152 * 9) Write MDCNFG with enable bits asserted (MDCNFG:DEx set to 1).
153 */
154
155 tmp = CONFIG_SYS_MDCNFG_VAL &
156 (MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3);
157 tmp |= readl(MDCNFG);
158 writelrb(tmp, MDCNFG);
159
160 /*
161 * 10) Write MDMRS.
162 */
163
164 writelrb(CONFIG_SYS_MDMRS_VAL, MDMRS);
165
166 /*
167 * 11) Enable APD
168 */
169
170 if (CONFIG_SYS_MDREFR_VAL & MDREFR_APD) {
171 tmp = readl(MDREFR);
172 tmp |= MDREFR_APD;
173 writelrb(tmp, MDREFR);
174 }
175}
176
177void pxa_gpio_setup(void)
178{
179 writel(CONFIG_SYS_GPSR0_VAL, GPSR0);
180 writel(CONFIG_SYS_GPSR1_VAL, GPSR1);
181 writel(CONFIG_SYS_GPSR2_VAL, GPSR2);
Marek Vasutd10237d2011-11-26 07:32:24 +0100182#if defined(CONFIG_CPU_PXA27X)
Marek Vasut2cad92f2010-09-28 15:44:10 +0200183 writel(CONFIG_SYS_GPSR3_VAL, GPSR3);
184#endif
185
186 writel(CONFIG_SYS_GPCR0_VAL, GPCR0);
187 writel(CONFIG_SYS_GPCR1_VAL, GPCR1);
188 writel(CONFIG_SYS_GPCR2_VAL, GPCR2);
Marek Vasutd10237d2011-11-26 07:32:24 +0100189#if defined(CONFIG_CPU_PXA27X)
Marek Vasut2cad92f2010-09-28 15:44:10 +0200190 writel(CONFIG_SYS_GPCR3_VAL, GPCR3);
191#endif
192
193 writel(CONFIG_SYS_GPDR0_VAL, GPDR0);
194 writel(CONFIG_SYS_GPDR1_VAL, GPDR1);
195 writel(CONFIG_SYS_GPDR2_VAL, GPDR2);
Marek Vasutd10237d2011-11-26 07:32:24 +0100196#if defined(CONFIG_CPU_PXA27X)
Marek Vasut2cad92f2010-09-28 15:44:10 +0200197 writel(CONFIG_SYS_GPDR3_VAL, GPDR3);
198#endif
199
200 writel(CONFIG_SYS_GAFR0_L_VAL, GAFR0_L);
201 writel(CONFIG_SYS_GAFR0_U_VAL, GAFR0_U);
202 writel(CONFIG_SYS_GAFR1_L_VAL, GAFR1_L);
203 writel(CONFIG_SYS_GAFR1_U_VAL, GAFR1_U);
204 writel(CONFIG_SYS_GAFR2_L_VAL, GAFR2_L);
205 writel(CONFIG_SYS_GAFR2_U_VAL, GAFR2_U);
Marek Vasutd10237d2011-11-26 07:32:24 +0100206#if defined(CONFIG_CPU_PXA27X)
Marek Vasut2cad92f2010-09-28 15:44:10 +0200207 writel(CONFIG_SYS_GAFR3_L_VAL, GAFR3_L);
208 writel(CONFIG_SYS_GAFR3_U_VAL, GAFR3_U);
209#endif
210
211 writel(CONFIG_SYS_PSSR_VAL, PSSR);
212}
213
214void pxa_interrupt_setup(void)
215{
216 writel(0, ICLR);
217 writel(0, ICMR);
Marek Vasutd10237d2011-11-26 07:32:24 +0100218#if defined(CONFIG_CPU_PXA27X)
Marek Vasut2cad92f2010-09-28 15:44:10 +0200219 writel(0, ICLR2);
220 writel(0, ICMR2);
221#endif
222}
223
224void pxa_clock_setup(void)
225{
Marek Vasut2cad92f2010-09-28 15:44:10 +0200226 writel(CONFIG_SYS_CKEN, CKEN);
227 writel(CONFIG_SYS_CCCR, CCCR);
Sergey Yanovich847e6692013-05-21 23:49:41 +0400228 asm volatile("mcr p14, 0, %0, c6, c0, 0" : : "r"(0x0b));
Marek Vasut2cad92f2010-09-28 15:44:10 +0200229
230 /* enable the 32Khz oscillator for RTC and PowerManager */
231 writel(OSCC_OON, OSCC);
Marek Vasutd10237d2011-11-26 07:32:24 +0100232 while (!(readl(OSCC) & OSCC_OOK))
233 asm volatile("" : : : "memory");
Marek Vasut2cad92f2010-09-28 15:44:10 +0200234}
235
236void pxa_wakeup(void)
237{
238 uint32_t rcsr;
239
240 rcsr = readl(RCSR);
241 writel(rcsr & (RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR), RCSR);
242
243 /* Wakeup */
244 if (rcsr & RCSR_SMR) {
245 writel(PSSR_PH, PSSR);
Marek Vasutf68d2a22011-11-26 11:18:57 +0100246 pxa2xx_dram_init();
Marek Vasut2cad92f2010-09-28 15:44:10 +0200247 icache_disable();
248 dcache_disable();
Marek Vasutd10237d2011-11-26 07:32:24 +0100249 asm volatile("mov pc, %0" : : "r"(readl(PSPR)));
Marek Vasut2cad92f2010-09-28 15:44:10 +0200250 }
251}
252
253int arch_cpu_init(void)
254{
255 pxa_gpio_setup();
Marek Vasut2cad92f2010-09-28 15:44:10 +0200256 pxa_wakeup();
257 pxa_interrupt_setup();
258 pxa_clock_setup();
259 return 0;
260}
Lei Wen3df619e2011-04-13 23:48:31 +0530261
262void i2c_clk_enable(void)
263{
Marek Vasutd10237d2011-11-26 07:32:24 +0100264 /* Set the global I2C clock on */
Lei Wen3df619e2011-04-13 23:48:31 +0530265 writel(readl(CKEN) | CKEN14_I2C, CKEN);
Lei Wen3df619e2011-04-13 23:48:31 +0530266}
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100267
Łukasz Dałek2ac2bb72013-01-12 15:32:32 +0000268void __attribute__((weak)) reset_cpu(ulong ignored) __attribute__((noreturn));
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100269
270void reset_cpu(ulong ignored)
271{
272 uint32_t tmp;
273
274 setbits_le32(OWER, OWER_WME);
275
276 tmp = readl(OSCR);
277 tmp += 0x1000;
278 writel(tmp, OSMR3);
Sergei Ianovich23f00ca2013-12-17 05:03:40 +0400279 writel(MDREFR_SLFRSH, MDREFR);
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100280
281 for (;;)
282 ;
283}
Vasily Khoruzhick9cfc0592016-03-20 18:37:07 -0700284
285void enable_caches(void)
286{
Trevor Woerner10015022019-05-03 09:41:00 -0400287#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Vasily Khoruzhick9cfc0592016-03-20 18:37:07 -0700288 icache_enable();
289#endif
Trevor Woerner10015022019-05-03 09:41:00 -0400290#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Vasily Khoruzhick9cfc0592016-03-20 18:37:07 -0700291 dcache_enable();
292#endif
293}