blob: ea91d8aaec2bbf90e4c13281271f23a96057285a [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>
Simon Glass97589732020-05-10 11:40:02 -060014#include <init.h>
Simon Glass8f3f7612019-11-14 12:57:42 -070015#include <irq_func.h>
Marcel Ziswilerfe8ade02015-08-16 04:16:26 +020016#include <asm/arch/pxa-regs.h>
Simon Glass274e0b02020-05-10 11:39:56 -060017#include <asm/cache.h>
Marek Vasut2db1e962010-09-09 09:50:39 +020018#include <asm/io.h>
Jean-Christophe PLAGNIOL-VILLARD9053b5a2009-04-05 13:02:43 +020019#include <asm/system.h>
Marek Vasut2db1e962010-09-09 09:50:39 +020020#include <command.h>
wdenk11a72d92002-10-27 22:25:25 +000021
Marek Vasut9da6fe52011-11-26 07:32:24 +010022/* Flush I/D-cache */
23static void cache_flush(void)
24{
25 unsigned long i = 0;
26
27 asm ("mcr p15, 0, %0, c7, c5, 0" : : "r" (i));
28}
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020029
Marek Vasut9da6fe52011-11-26 07:32:24 +010030int cleanup_before_linux(void)
wdenk11a72d92002-10-27 22:25:25 +000031{
32 /*
Marek Vasut9da6fe52011-11-26 07:32:24 +010033 * This function is called just before we call Linux. It prepares
34 * the processor for Linux by just disabling everything that can
35 * disturb booting Linux.
wdenk11a72d92002-10-27 22:25:25 +000036 */
37
Marek Vasut9da6fe52011-11-26 07:32:24 +010038 disable_interrupts();
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020039 icache_disable();
40 dcache_disable();
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020041 cache_flush();
wdenk11a72d92002-10-27 22:25:25 +000042
Marek Vasut9da6fe52011-11-26 07:32:24 +010043 return 0;
wdenk7a428cc2003-06-15 22:40:42 +000044}
Marek Vasutb9b8ea32010-09-28 15:44:10 +020045
Marek Vasutb9b8ea32010-09-28 15:44:10 +020046inline void writelrb(uint32_t val, uint32_t addr)
47{
48 writel(val, addr);
Marek Vasut9da6fe52011-11-26 07:32:24 +010049 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +020050 readl(addr);
Marek Vasut9da6fe52011-11-26 07:32:24 +010051 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +020052}
53
Marek Vasut08341be2011-11-26 11:18:57 +010054void pxa2xx_dram_init(void)
Marek Vasutb9b8ea32010-09-28 15:44:10 +020055{
56 uint32_t tmp;
57 int i;
58 /*
59 * 1) Initialize Asynchronous static memory controller
60 */
61
62 writelrb(CONFIG_SYS_MSC0_VAL, MSC0);
63 writelrb(CONFIG_SYS_MSC1_VAL, MSC1);
64 writelrb(CONFIG_SYS_MSC2_VAL, MSC2);
65 /*
66 * 2) Initialize Card Interface
67 */
68
69 /* MECR: Memory Expansion Card Register */
70 writelrb(CONFIG_SYS_MECR_VAL, MECR);
71 /* MCMEM0: Card Interface slot 0 timing */
72 writelrb(CONFIG_SYS_MCMEM0_VAL, MCMEM0);
73 /* MCMEM1: Card Interface slot 1 timing */
74 writelrb(CONFIG_SYS_MCMEM1_VAL, MCMEM1);
75 /* MCATT0: Card Interface Attribute Space Timing, slot 0 */
76 writelrb(CONFIG_SYS_MCATT0_VAL, MCATT0);
77 /* MCATT1: Card Interface Attribute Space Timing, slot 1 */
78 writelrb(CONFIG_SYS_MCATT1_VAL, MCATT1);
79 /* MCIO0: Card Interface I/O Space Timing, slot 0 */
80 writelrb(CONFIG_SYS_MCIO0_VAL, MCIO0);
81 /* MCIO1: Card Interface I/O Space Timing, slot 1 */
82 writelrb(CONFIG_SYS_MCIO1_VAL, MCIO1);
83
84 /*
85 * 3) Configure Fly-By DMA register
86 */
87
88 writelrb(CONFIG_SYS_FLYCNFG_VAL, FLYCNFG);
89
90 /*
91 * 4) Initialize Timing for Sync Memory (SDCLK0)
92 */
93
94 /*
95 * Before accessing MDREFR we need a valid DRI field, so we set
96 * this to power on defaults + DRI field.
97 */
98
99 /* Read current MDREFR config and zero out DRI */
100 tmp = readl(MDREFR) & ~0xfff;
101 /* Add user-specified DRI */
102 tmp |= CONFIG_SYS_MDREFR_VAL & 0xfff;
103 /* Configure important bits */
104 tmp |= MDREFR_K0RUN | MDREFR_SLFRSH;
105 tmp &= ~(MDREFR_APD | MDREFR_E1PIN);
106
107 /* Write MDREFR back */
108 writelrb(tmp, MDREFR);
109
110 /*
111 * 5) Initialize Synchronous Static Memory (Flash/Peripherals)
112 */
113
114 /* Initialize SXCNFG register. Assert the enable bits.
115 *
116 * Write SXMRS to cause an MRS command to all enabled banks of
117 * synchronous static memory. Note that SXLCR need not be written
118 * at this time.
119 */
120 writelrb(CONFIG_SYS_SXCNFG_VAL, SXCNFG);
121
122 /*
123 * 6) Initialize SDRAM
124 */
125
126 writelrb(CONFIG_SYS_MDREFR_VAL & ~MDREFR_SLFRSH, MDREFR);
127 writelrb(CONFIG_SYS_MDREFR_VAL | MDREFR_E1PIN, MDREFR);
128
129 /*
130 * 7) Write MDCNFG with MDCNFG:DEx deasserted (set to 0), to configure
131 * but not enable each SDRAM partition pair.
132 */
133
134 writelrb(CONFIG_SYS_MDCNFG_VAL &
135 ~(MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3), MDCNFG);
Simon Glassa18a6692019-11-14 12:57:28 -0700136
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200137 /* Wait for the clock to the SDRAMs to stabilize, 100..200 usec. */
Simon Glassa18a6692019-11-14 12:57:28 -0700138 writel(0, OSCR);
139 while (readl(OSCR) < 0x300)
140 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200141
142 /*
143 * 8) Trigger a number (usually 8) refresh cycles by attempting
144 * non-burst read or write accesses to disabled SDRAM, as commonly
145 * specified in the power up sequence documented in SDRAM data
146 * sheets. The address(es) used for this purpose must not be
147 * cacheable.
148 */
149 for (i = 9; i >= 0; i--) {
150 writel(i, 0xa0000000);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100151 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200152 }
153 /*
154 * 9) Write MDCNFG with enable bits asserted (MDCNFG:DEx set to 1).
155 */
156
157 tmp = CONFIG_SYS_MDCNFG_VAL &
158 (MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3);
159 tmp |= readl(MDCNFG);
160 writelrb(tmp, MDCNFG);
161
162 /*
163 * 10) Write MDMRS.
164 */
165
166 writelrb(CONFIG_SYS_MDMRS_VAL, MDMRS);
167
168 /*
169 * 11) Enable APD
170 */
171
172 if (CONFIG_SYS_MDREFR_VAL & MDREFR_APD) {
173 tmp = readl(MDREFR);
174 tmp |= MDREFR_APD;
175 writelrb(tmp, MDREFR);
176 }
177}
178
179void pxa_gpio_setup(void)
180{
181 writel(CONFIG_SYS_GPSR0_VAL, GPSR0);
182 writel(CONFIG_SYS_GPSR1_VAL, GPSR1);
183 writel(CONFIG_SYS_GPSR2_VAL, GPSR2);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100184#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200185 writel(CONFIG_SYS_GPSR3_VAL, GPSR3);
186#endif
187
188 writel(CONFIG_SYS_GPCR0_VAL, GPCR0);
189 writel(CONFIG_SYS_GPCR1_VAL, GPCR1);
190 writel(CONFIG_SYS_GPCR2_VAL, GPCR2);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100191#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200192 writel(CONFIG_SYS_GPCR3_VAL, GPCR3);
193#endif
194
195 writel(CONFIG_SYS_GPDR0_VAL, GPDR0);
196 writel(CONFIG_SYS_GPDR1_VAL, GPDR1);
197 writel(CONFIG_SYS_GPDR2_VAL, GPDR2);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100198#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200199 writel(CONFIG_SYS_GPDR3_VAL, GPDR3);
200#endif
201
202 writel(CONFIG_SYS_GAFR0_L_VAL, GAFR0_L);
203 writel(CONFIG_SYS_GAFR0_U_VAL, GAFR0_U);
204 writel(CONFIG_SYS_GAFR1_L_VAL, GAFR1_L);
205 writel(CONFIG_SYS_GAFR1_U_VAL, GAFR1_U);
206 writel(CONFIG_SYS_GAFR2_L_VAL, GAFR2_L);
207 writel(CONFIG_SYS_GAFR2_U_VAL, GAFR2_U);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100208#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200209 writel(CONFIG_SYS_GAFR3_L_VAL, GAFR3_L);
210 writel(CONFIG_SYS_GAFR3_U_VAL, GAFR3_U);
211#endif
212
213 writel(CONFIG_SYS_PSSR_VAL, PSSR);
214}
215
216void pxa_interrupt_setup(void)
217{
218 writel(0, ICLR);
219 writel(0, ICMR);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100220#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200221 writel(0, ICLR2);
222 writel(0, ICMR2);
223#endif
224}
225
226void pxa_clock_setup(void)
227{
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200228 writel(CONFIG_SYS_CKEN, CKEN);
229 writel(CONFIG_SYS_CCCR, CCCR);
Sergey Yanovichd81863d2013-05-21 23:49:41 +0400230 asm volatile("mcr p14, 0, %0, c6, c0, 0" : : "r"(0x0b));
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200231
232 /* enable the 32Khz oscillator for RTC and PowerManager */
233 writel(OSCC_OON, OSCC);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100234 while (!(readl(OSCC) & OSCC_OOK))
235 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200236}
237
238void pxa_wakeup(void)
239{
240 uint32_t rcsr;
241
242 rcsr = readl(RCSR);
243 writel(rcsr & (RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR), RCSR);
244
245 /* Wakeup */
246 if (rcsr & RCSR_SMR) {
247 writel(PSSR_PH, PSSR);
Marek Vasut08341be2011-11-26 11:18:57 +0100248 pxa2xx_dram_init();
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200249 icache_disable();
250 dcache_disable();
Marek Vasut9da6fe52011-11-26 07:32:24 +0100251 asm volatile("mov pc, %0" : : "r"(readl(PSPR)));
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200252 }
253}
254
255int arch_cpu_init(void)
256{
257 pxa_gpio_setup();
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200258 pxa_wakeup();
259 pxa_interrupt_setup();
260 pxa_clock_setup();
261 return 0;
262}
Lei Wena41374b42011-04-13 23:48:31 +0530263
264void i2c_clk_enable(void)
265{
Marek Vasut9da6fe52011-11-26 07:32:24 +0100266 /* Set the global I2C clock on */
Lei Wena41374b42011-04-13 23:48:31 +0530267 writel(readl(CKEN) | CKEN14_I2C, CKEN);
Lei Wena41374b42011-04-13 23:48:31 +0530268}
Marek Vasutb9091622011-10-31 14:12:39 +0100269
Łukasz Dałek8d5a7282013-01-12 15:32:32 +0000270void __attribute__((weak)) reset_cpu(ulong ignored) __attribute__((noreturn));
Marek Vasutb9091622011-10-31 14:12:39 +0100271
272void reset_cpu(ulong ignored)
273{
274 uint32_t tmp;
275
276 setbits_le32(OWER, OWER_WME);
277
278 tmp = readl(OSCR);
279 tmp += 0x1000;
280 writel(tmp, OSMR3);
Sergei Ianovich093f09f2013-12-17 05:03:40 +0400281 writel(MDREFR_SLFRSH, MDREFR);
Marek Vasutb9091622011-10-31 14:12:39 +0100282
283 for (;;)
284 ;
285}
Vasily Khoruzhickb1670092016-03-20 18:37:07 -0700286
287void enable_caches(void)
288{
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400289#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Vasily Khoruzhickb1670092016-03-20 18:37:07 -0700290 icache_enable();
291#endif
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400292#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Vasily Khoruzhickb1670092016-03-20 18:37:07 -0700293 dcache_enable();
294#endif
295}