blob: 14fe307c1a0163cc824039c4f568332bb3e01b92 [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>
13#include <asm/arch/pxa-regs.h>
Marek Vasut2db1e962010-09-09 09:50:39 +020014#include <asm/io.h>
Jean-Christophe PLAGNIOL-VILLARD9053b5a2009-04-05 13:02:43 +020015#include <asm/system.h>
Marek Vasut2db1e962010-09-09 09:50:39 +020016#include <command.h>
wdenk11a72d92002-10-27 22:25:25 +000017
Marek Vasut9da6fe52011-11-26 07:32:24 +010018/* Flush I/D-cache */
19static void cache_flush(void)
20{
21 unsigned long i = 0;
22
23 asm ("mcr p15, 0, %0, c7, c5, 0" : : "r" (i));
24}
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020025
Marek Vasut9da6fe52011-11-26 07:32:24 +010026int cleanup_before_linux(void)
wdenk11a72d92002-10-27 22:25:25 +000027{
28 /*
Marek Vasut9da6fe52011-11-26 07:32:24 +010029 * This function is called just before we call Linux. It prepares
30 * the processor for Linux by just disabling everything that can
31 * disturb booting Linux.
wdenk11a72d92002-10-27 22:25:25 +000032 */
33
Marek Vasut9da6fe52011-11-26 07:32:24 +010034 disable_interrupts();
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020035 icache_disable();
36 dcache_disable();
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020037 cache_flush();
wdenk11a72d92002-10-27 22:25:25 +000038
Marek Vasut9da6fe52011-11-26 07:32:24 +010039 return 0;
wdenk7a428cc2003-06-15 22:40:42 +000040}
Marek Vasutb9b8ea32010-09-28 15:44:10 +020041
Marek Vasutb9b8ea32010-09-28 15:44:10 +020042inline void writelrb(uint32_t val, uint32_t addr)
43{
44 writel(val, addr);
Marek Vasut9da6fe52011-11-26 07:32:24 +010045 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +020046 readl(addr);
Marek Vasut9da6fe52011-11-26 07:32:24 +010047 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +020048}
49
Marek Vasut08341be2011-11-26 11:18:57 +010050void pxa2xx_dram_init(void)
Marek Vasutb9b8ea32010-09-28 15:44:10 +020051{
52 uint32_t tmp;
53 int i;
54 /*
55 * 1) Initialize Asynchronous static memory controller
56 */
57
58 writelrb(CONFIG_SYS_MSC0_VAL, MSC0);
59 writelrb(CONFIG_SYS_MSC1_VAL, MSC1);
60 writelrb(CONFIG_SYS_MSC2_VAL, MSC2);
61 /*
62 * 2) Initialize Card Interface
63 */
64
65 /* MECR: Memory Expansion Card Register */
66 writelrb(CONFIG_SYS_MECR_VAL, MECR);
67 /* MCMEM0: Card Interface slot 0 timing */
68 writelrb(CONFIG_SYS_MCMEM0_VAL, MCMEM0);
69 /* MCMEM1: Card Interface slot 1 timing */
70 writelrb(CONFIG_SYS_MCMEM1_VAL, MCMEM1);
71 /* MCATT0: Card Interface Attribute Space Timing, slot 0 */
72 writelrb(CONFIG_SYS_MCATT0_VAL, MCATT0);
73 /* MCATT1: Card Interface Attribute Space Timing, slot 1 */
74 writelrb(CONFIG_SYS_MCATT1_VAL, MCATT1);
75 /* MCIO0: Card Interface I/O Space Timing, slot 0 */
76 writelrb(CONFIG_SYS_MCIO0_VAL, MCIO0);
77 /* MCIO1: Card Interface I/O Space Timing, slot 1 */
78 writelrb(CONFIG_SYS_MCIO1_VAL, MCIO1);
79
80 /*
81 * 3) Configure Fly-By DMA register
82 */
83
84 writelrb(CONFIG_SYS_FLYCNFG_VAL, FLYCNFG);
85
86 /*
87 * 4) Initialize Timing for Sync Memory (SDCLK0)
88 */
89
90 /*
91 * Before accessing MDREFR we need a valid DRI field, so we set
92 * this to power on defaults + DRI field.
93 */
94
95 /* Read current MDREFR config and zero out DRI */
96 tmp = readl(MDREFR) & ~0xfff;
97 /* Add user-specified DRI */
98 tmp |= CONFIG_SYS_MDREFR_VAL & 0xfff;
99 /* Configure important bits */
100 tmp |= MDREFR_K0RUN | MDREFR_SLFRSH;
101 tmp &= ~(MDREFR_APD | MDREFR_E1PIN);
102
103 /* Write MDREFR back */
104 writelrb(tmp, MDREFR);
105
106 /*
107 * 5) Initialize Synchronous Static Memory (Flash/Peripherals)
108 */
109
110 /* Initialize SXCNFG register. Assert the enable bits.
111 *
112 * Write SXMRS to cause an MRS command to all enabled banks of
113 * synchronous static memory. Note that SXLCR need not be written
114 * at this time.
115 */
116 writelrb(CONFIG_SYS_SXCNFG_VAL, SXCNFG);
117
118 /*
119 * 6) Initialize SDRAM
120 */
121
122 writelrb(CONFIG_SYS_MDREFR_VAL & ~MDREFR_SLFRSH, MDREFR);
123 writelrb(CONFIG_SYS_MDREFR_VAL | MDREFR_E1PIN, MDREFR);
124
125 /*
126 * 7) Write MDCNFG with MDCNFG:DEx deasserted (set to 0), to configure
127 * but not enable each SDRAM partition pair.
128 */
129
130 writelrb(CONFIG_SYS_MDCNFG_VAL &
131 ~(MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3), MDCNFG);
Simon Glassa18a6692019-11-14 12:57:28 -0700132
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200133 /* Wait for the clock to the SDRAMs to stabilize, 100..200 usec. */
Simon Glassa18a6692019-11-14 12:57:28 -0700134 writel(0, OSCR);
135 while (readl(OSCR) < 0x300)
136 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200137
138 /*
139 * 8) Trigger a number (usually 8) refresh cycles by attempting
140 * non-burst read or write accesses to disabled SDRAM, as commonly
141 * specified in the power up sequence documented in SDRAM data
142 * sheets. The address(es) used for this purpose must not be
143 * cacheable.
144 */
145 for (i = 9; i >= 0; i--) {
146 writel(i, 0xa0000000);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100147 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200148 }
149 /*
150 * 9) Write MDCNFG with enable bits asserted (MDCNFG:DEx set to 1).
151 */
152
153 tmp = CONFIG_SYS_MDCNFG_VAL &
154 (MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3);
155 tmp |= readl(MDCNFG);
156 writelrb(tmp, MDCNFG);
157
158 /*
159 * 10) Write MDMRS.
160 */
161
162 writelrb(CONFIG_SYS_MDMRS_VAL, MDMRS);
163
164 /*
165 * 11) Enable APD
166 */
167
168 if (CONFIG_SYS_MDREFR_VAL & MDREFR_APD) {
169 tmp = readl(MDREFR);
170 tmp |= MDREFR_APD;
171 writelrb(tmp, MDREFR);
172 }
173}
174
175void pxa_gpio_setup(void)
176{
177 writel(CONFIG_SYS_GPSR0_VAL, GPSR0);
178 writel(CONFIG_SYS_GPSR1_VAL, GPSR1);
179 writel(CONFIG_SYS_GPSR2_VAL, GPSR2);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100180#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200181 writel(CONFIG_SYS_GPSR3_VAL, GPSR3);
182#endif
183
184 writel(CONFIG_SYS_GPCR0_VAL, GPCR0);
185 writel(CONFIG_SYS_GPCR1_VAL, GPCR1);
186 writel(CONFIG_SYS_GPCR2_VAL, GPCR2);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100187#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200188 writel(CONFIG_SYS_GPCR3_VAL, GPCR3);
189#endif
190
191 writel(CONFIG_SYS_GPDR0_VAL, GPDR0);
192 writel(CONFIG_SYS_GPDR1_VAL, GPDR1);
193 writel(CONFIG_SYS_GPDR2_VAL, GPDR2);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100194#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200195 writel(CONFIG_SYS_GPDR3_VAL, GPDR3);
196#endif
197
198 writel(CONFIG_SYS_GAFR0_L_VAL, GAFR0_L);
199 writel(CONFIG_SYS_GAFR0_U_VAL, GAFR0_U);
200 writel(CONFIG_SYS_GAFR1_L_VAL, GAFR1_L);
201 writel(CONFIG_SYS_GAFR1_U_VAL, GAFR1_U);
202 writel(CONFIG_SYS_GAFR2_L_VAL, GAFR2_L);
203 writel(CONFIG_SYS_GAFR2_U_VAL, GAFR2_U);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100204#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200205 writel(CONFIG_SYS_GAFR3_L_VAL, GAFR3_L);
206 writel(CONFIG_SYS_GAFR3_U_VAL, GAFR3_U);
207#endif
208
209 writel(CONFIG_SYS_PSSR_VAL, PSSR);
210}
211
212void pxa_interrupt_setup(void)
213{
214 writel(0, ICLR);
215 writel(0, ICMR);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100216#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200217 writel(0, ICLR2);
218 writel(0, ICMR2);
219#endif
220}
221
222void pxa_clock_setup(void)
223{
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200224 writel(CONFIG_SYS_CKEN, CKEN);
225 writel(CONFIG_SYS_CCCR, CCCR);
Sergey Yanovichd81863d2013-05-21 23:49:41 +0400226 asm volatile("mcr p14, 0, %0, c6, c0, 0" : : "r"(0x0b));
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200227
228 /* enable the 32Khz oscillator for RTC and PowerManager */
229 writel(OSCC_OON, OSCC);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100230 while (!(readl(OSCC) & OSCC_OOK))
231 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200232}
233
234void pxa_wakeup(void)
235{
236 uint32_t rcsr;
237
238 rcsr = readl(RCSR);
239 writel(rcsr & (RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR), RCSR);
240
241 /* Wakeup */
242 if (rcsr & RCSR_SMR) {
243 writel(PSSR_PH, PSSR);
Marek Vasut08341be2011-11-26 11:18:57 +0100244 pxa2xx_dram_init();
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200245 icache_disable();
246 dcache_disable();
Marek Vasut9da6fe52011-11-26 07:32:24 +0100247 asm volatile("mov pc, %0" : : "r"(readl(PSPR)));
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200248 }
249}
250
251int arch_cpu_init(void)
252{
253 pxa_gpio_setup();
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200254 pxa_wakeup();
255 pxa_interrupt_setup();
256 pxa_clock_setup();
257 return 0;
258}
Lei Wena41374b42011-04-13 23:48:31 +0530259
260void i2c_clk_enable(void)
261{
Marek Vasut9da6fe52011-11-26 07:32:24 +0100262 /* Set the global I2C clock on */
Lei Wena41374b42011-04-13 23:48:31 +0530263 writel(readl(CKEN) | CKEN14_I2C, CKEN);
Lei Wena41374b42011-04-13 23:48:31 +0530264}
Marek Vasutb9091622011-10-31 14:12:39 +0100265
Łukasz Dałek8d5a7282013-01-12 15:32:32 +0000266void __attribute__((weak)) reset_cpu(ulong ignored) __attribute__((noreturn));
Marek Vasutb9091622011-10-31 14:12:39 +0100267
268void reset_cpu(ulong ignored)
269{
270 uint32_t tmp;
271
272 setbits_le32(OWER, OWER_WME);
273
274 tmp = readl(OSCR);
275 tmp += 0x1000;
276 writel(tmp, OSMR3);
Sergei Ianovich093f09f2013-12-17 05:03:40 +0400277 writel(MDREFR_SLFRSH, MDREFR);
Marek Vasutb9091622011-10-31 14:12:39 +0100278
279 for (;;)
280 ;
281}
Vasily Khoruzhickb1670092016-03-20 18:37:07 -0700282
283void enable_caches(void)
284{
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400285#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Vasily Khoruzhickb1670092016-03-20 18:37:07 -0700286 icache_enable();
287#endif
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400288#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Vasily Khoruzhickb1670092016-03-20 18:37:07 -0700289 dcache_enable();
290#endif
291}