blob: 7d6abf4dbca41b9d9d6b1f94d3b7bb0dc1c315a8 [file] [log] [blame]
Tom Rini10e47792018-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 Ziswilerfe8ade02015-08-16 04:16:26 +020012#include <common.h>
Simon Glass1d91ba72019-11-14 12:57:37 -070013#include <cpu_func.h>
Marcel Ziswilerfe8ade02015-08-16 04:16:26 +020014#include <asm/arch/pxa-regs.h>
Marek Vasut2db1e962010-09-09 09:50:39 +020015#include <asm/io.h>
Jean-Christophe PLAGNIOL-VILLARD9053b5a2009-04-05 13:02:43 +020016#include <asm/system.h>
Marek Vasut2db1e962010-09-09 09:50:39 +020017#include <command.h>
wdenk11a72d92002-10-27 22:25:25 +000018
Marek Vasut9da6fe52011-11-26 07:32:24 +010019/* Flush I/D-cache */
20static void cache_flush(void)
21{
22 unsigned long i = 0;
23
24 asm ("mcr p15, 0, %0, c7, c5, 0" : : "r" (i));
25}
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020026
Marek Vasut9da6fe52011-11-26 07:32:24 +010027int cleanup_before_linux(void)
wdenk11a72d92002-10-27 22:25:25 +000028{
29 /*
Marek Vasut9da6fe52011-11-26 07:32:24 +010030 * This function is called just before we call Linux. It prepares
31 * the processor for Linux by just disabling everything that can
32 * disturb booting Linux.
wdenk11a72d92002-10-27 22:25:25 +000033 */
34
Marek Vasut9da6fe52011-11-26 07:32:24 +010035 disable_interrupts();
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020036 icache_disable();
37 dcache_disable();
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020038 cache_flush();
wdenk11a72d92002-10-27 22:25:25 +000039
Marek Vasut9da6fe52011-11-26 07:32:24 +010040 return 0;
wdenk7a428cc2003-06-15 22:40:42 +000041}
Marek Vasutb9b8ea32010-09-28 15:44:10 +020042
Marek Vasutb9b8ea32010-09-28 15:44:10 +020043inline void writelrb(uint32_t val, uint32_t addr)
44{
45 writel(val, addr);
Marek Vasut9da6fe52011-11-26 07:32:24 +010046 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +020047 readl(addr);
Marek Vasut9da6fe52011-11-26 07:32:24 +010048 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +020049}
50
Marek Vasut08341be2011-11-26 11:18:57 +010051void pxa2xx_dram_init(void)
Marek Vasutb9b8ea32010-09-28 15:44:10 +020052{
53 uint32_t tmp;
54 int i;
55 /*
56 * 1) Initialize Asynchronous static memory controller
57 */
58
59 writelrb(CONFIG_SYS_MSC0_VAL, MSC0);
60 writelrb(CONFIG_SYS_MSC1_VAL, MSC1);
61 writelrb(CONFIG_SYS_MSC2_VAL, MSC2);
62 /*
63 * 2) Initialize Card Interface
64 */
65
66 /* MECR: Memory Expansion Card Register */
67 writelrb(CONFIG_SYS_MECR_VAL, MECR);
68 /* MCMEM0: Card Interface slot 0 timing */
69 writelrb(CONFIG_SYS_MCMEM0_VAL, MCMEM0);
70 /* MCMEM1: Card Interface slot 1 timing */
71 writelrb(CONFIG_SYS_MCMEM1_VAL, MCMEM1);
72 /* MCATT0: Card Interface Attribute Space Timing, slot 0 */
73 writelrb(CONFIG_SYS_MCATT0_VAL, MCATT0);
74 /* MCATT1: Card Interface Attribute Space Timing, slot 1 */
75 writelrb(CONFIG_SYS_MCATT1_VAL, MCATT1);
76 /* MCIO0: Card Interface I/O Space Timing, slot 0 */
77 writelrb(CONFIG_SYS_MCIO0_VAL, MCIO0);
78 /* MCIO1: Card Interface I/O Space Timing, slot 1 */
79 writelrb(CONFIG_SYS_MCIO1_VAL, MCIO1);
80
81 /*
82 * 3) Configure Fly-By DMA register
83 */
84
85 writelrb(CONFIG_SYS_FLYCNFG_VAL, FLYCNFG);
86
87 /*
88 * 4) Initialize Timing for Sync Memory (SDCLK0)
89 */
90
91 /*
92 * Before accessing MDREFR we need a valid DRI field, so we set
93 * this to power on defaults + DRI field.
94 */
95
96 /* Read current MDREFR config and zero out DRI */
97 tmp = readl(MDREFR) & ~0xfff;
98 /* Add user-specified DRI */
99 tmp |= CONFIG_SYS_MDREFR_VAL & 0xfff;
100 /* Configure important bits */
101 tmp |= MDREFR_K0RUN | MDREFR_SLFRSH;
102 tmp &= ~(MDREFR_APD | MDREFR_E1PIN);
103
104 /* Write MDREFR back */
105 writelrb(tmp, MDREFR);
106
107 /*
108 * 5) Initialize Synchronous Static Memory (Flash/Peripherals)
109 */
110
111 /* Initialize SXCNFG register. Assert the enable bits.
112 *
113 * Write SXMRS to cause an MRS command to all enabled banks of
114 * synchronous static memory. Note that SXLCR need not be written
115 * at this time.
116 */
117 writelrb(CONFIG_SYS_SXCNFG_VAL, SXCNFG);
118
119 /*
120 * 6) Initialize SDRAM
121 */
122
123 writelrb(CONFIG_SYS_MDREFR_VAL & ~MDREFR_SLFRSH, MDREFR);
124 writelrb(CONFIG_SYS_MDREFR_VAL | MDREFR_E1PIN, MDREFR);
125
126 /*
127 * 7) Write MDCNFG with MDCNFG:DEx deasserted (set to 0), to configure
128 * but not enable each SDRAM partition pair.
129 */
130
131 writelrb(CONFIG_SYS_MDCNFG_VAL &
132 ~(MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3), MDCNFG);
Simon Glassa18a6692019-11-14 12:57:28 -0700133
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200134 /* Wait for the clock to the SDRAMs to stabilize, 100..200 usec. */
Simon Glassa18a6692019-11-14 12:57:28 -0700135 writel(0, OSCR);
136 while (readl(OSCR) < 0x300)
137 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200138
139 /*
140 * 8) Trigger a number (usually 8) refresh cycles by attempting
141 * non-burst read or write accesses to disabled SDRAM, as commonly
142 * specified in the power up sequence documented in SDRAM data
143 * sheets. The address(es) used for this purpose must not be
144 * cacheable.
145 */
146 for (i = 9; i >= 0; i--) {
147 writel(i, 0xa0000000);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100148 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200149 }
150 /*
151 * 9) Write MDCNFG with enable bits asserted (MDCNFG:DEx set to 1).
152 */
153
154 tmp = CONFIG_SYS_MDCNFG_VAL &
155 (MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3);
156 tmp |= readl(MDCNFG);
157 writelrb(tmp, MDCNFG);
158
159 /*
160 * 10) Write MDMRS.
161 */
162
163 writelrb(CONFIG_SYS_MDMRS_VAL, MDMRS);
164
165 /*
166 * 11) Enable APD
167 */
168
169 if (CONFIG_SYS_MDREFR_VAL & MDREFR_APD) {
170 tmp = readl(MDREFR);
171 tmp |= MDREFR_APD;
172 writelrb(tmp, MDREFR);
173 }
174}
175
176void pxa_gpio_setup(void)
177{
178 writel(CONFIG_SYS_GPSR0_VAL, GPSR0);
179 writel(CONFIG_SYS_GPSR1_VAL, GPSR1);
180 writel(CONFIG_SYS_GPSR2_VAL, GPSR2);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100181#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200182 writel(CONFIG_SYS_GPSR3_VAL, GPSR3);
183#endif
184
185 writel(CONFIG_SYS_GPCR0_VAL, GPCR0);
186 writel(CONFIG_SYS_GPCR1_VAL, GPCR1);
187 writel(CONFIG_SYS_GPCR2_VAL, GPCR2);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100188#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200189 writel(CONFIG_SYS_GPCR3_VAL, GPCR3);
190#endif
191
192 writel(CONFIG_SYS_GPDR0_VAL, GPDR0);
193 writel(CONFIG_SYS_GPDR1_VAL, GPDR1);
194 writel(CONFIG_SYS_GPDR2_VAL, GPDR2);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100195#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200196 writel(CONFIG_SYS_GPDR3_VAL, GPDR3);
197#endif
198
199 writel(CONFIG_SYS_GAFR0_L_VAL, GAFR0_L);
200 writel(CONFIG_SYS_GAFR0_U_VAL, GAFR0_U);
201 writel(CONFIG_SYS_GAFR1_L_VAL, GAFR1_L);
202 writel(CONFIG_SYS_GAFR1_U_VAL, GAFR1_U);
203 writel(CONFIG_SYS_GAFR2_L_VAL, GAFR2_L);
204 writel(CONFIG_SYS_GAFR2_U_VAL, GAFR2_U);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100205#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200206 writel(CONFIG_SYS_GAFR3_L_VAL, GAFR3_L);
207 writel(CONFIG_SYS_GAFR3_U_VAL, GAFR3_U);
208#endif
209
210 writel(CONFIG_SYS_PSSR_VAL, PSSR);
211}
212
213void pxa_interrupt_setup(void)
214{
215 writel(0, ICLR);
216 writel(0, ICMR);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100217#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200218 writel(0, ICLR2);
219 writel(0, ICMR2);
220#endif
221}
222
223void pxa_clock_setup(void)
224{
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200225 writel(CONFIG_SYS_CKEN, CKEN);
226 writel(CONFIG_SYS_CCCR, CCCR);
Sergey Yanovichd81863d2013-05-21 23:49:41 +0400227 asm volatile("mcr p14, 0, %0, c6, c0, 0" : : "r"(0x0b));
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200228
229 /* enable the 32Khz oscillator for RTC and PowerManager */
230 writel(OSCC_OON, OSCC);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100231 while (!(readl(OSCC) & OSCC_OOK))
232 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200233}
234
235void pxa_wakeup(void)
236{
237 uint32_t rcsr;
238
239 rcsr = readl(RCSR);
240 writel(rcsr & (RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR), RCSR);
241
242 /* Wakeup */
243 if (rcsr & RCSR_SMR) {
244 writel(PSSR_PH, PSSR);
Marek Vasut08341be2011-11-26 11:18:57 +0100245 pxa2xx_dram_init();
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200246 icache_disable();
247 dcache_disable();
Marek Vasut9da6fe52011-11-26 07:32:24 +0100248 asm volatile("mov pc, %0" : : "r"(readl(PSPR)));
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200249 }
250}
251
252int arch_cpu_init(void)
253{
254 pxa_gpio_setup();
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200255 pxa_wakeup();
256 pxa_interrupt_setup();
257 pxa_clock_setup();
258 return 0;
259}
Lei Wena41374b42011-04-13 23:48:31 +0530260
261void i2c_clk_enable(void)
262{
Marek Vasut9da6fe52011-11-26 07:32:24 +0100263 /* Set the global I2C clock on */
Lei Wena41374b42011-04-13 23:48:31 +0530264 writel(readl(CKEN) | CKEN14_I2C, CKEN);
Lei Wena41374b42011-04-13 23:48:31 +0530265}
Marek Vasutb9091622011-10-31 14:12:39 +0100266
Łukasz Dałek8d5a7282013-01-12 15:32:32 +0000267void __attribute__((weak)) reset_cpu(ulong ignored) __attribute__((noreturn));
Marek Vasutb9091622011-10-31 14:12:39 +0100268
269void reset_cpu(ulong ignored)
270{
271 uint32_t tmp;
272
273 setbits_le32(OWER, OWER_WME);
274
275 tmp = readl(OSCR);
276 tmp += 0x1000;
277 writel(tmp, OSMR3);
Sergei Ianovich093f09f2013-12-17 05:03:40 +0400278 writel(MDREFR_SLFRSH, MDREFR);
Marek Vasutb9091622011-10-31 14:12:39 +0100279
280 for (;;)
281 ;
282}
Vasily Khoruzhickb1670092016-03-20 18:37:07 -0700283
284void enable_caches(void)
285{
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400286#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Vasily Khoruzhickb1670092016-03-20 18:37:07 -0700287 icache_enable();
288#endif
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400289#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Vasily Khoruzhickb1670092016-03-20 18:37:07 -0700290 dcache_enable();
291#endif
292}