blob: ecf85d2f14b2cc654c0f63c1d463885a5a63d09c [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 Glass8f3f7612019-11-14 12:57:42 -070014#include <irq_func.h>
Marcel Ziswilerfe8ade02015-08-16 04:16:26 +020015#include <asm/arch/pxa-regs.h>
Simon Glass274e0b02020-05-10 11:39:56 -060016#include <asm/cache.h>
Marek Vasut2db1e962010-09-09 09:50:39 +020017#include <asm/io.h>
Jean-Christophe PLAGNIOL-VILLARD9053b5a2009-04-05 13:02:43 +020018#include <asm/system.h>
Marek Vasut2db1e962010-09-09 09:50:39 +020019#include <command.h>
wdenk11a72d92002-10-27 22:25:25 +000020
Marek Vasut9da6fe52011-11-26 07:32:24 +010021/* Flush I/D-cache */
22static void cache_flush(void)
23{
24 unsigned long i = 0;
25
26 asm ("mcr p15, 0, %0, c7, c5, 0" : : "r" (i));
27}
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020028
Marek Vasut9da6fe52011-11-26 07:32:24 +010029int cleanup_before_linux(void)
wdenk11a72d92002-10-27 22:25:25 +000030{
31 /*
Marek Vasut9da6fe52011-11-26 07:32:24 +010032 * This function is called just before we call Linux. It prepares
33 * the processor for Linux by just disabling everything that can
34 * disturb booting Linux.
wdenk11a72d92002-10-27 22:25:25 +000035 */
36
Marek Vasut9da6fe52011-11-26 07:32:24 +010037 disable_interrupts();
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020038 icache_disable();
39 dcache_disable();
Jean-Christophe PLAGNIOL-VILLARDe6b5f1b2009-04-05 13:06:31 +020040 cache_flush();
wdenk11a72d92002-10-27 22:25:25 +000041
Marek Vasut9da6fe52011-11-26 07:32:24 +010042 return 0;
wdenk7a428cc2003-06-15 22:40:42 +000043}
Marek Vasutb9b8ea32010-09-28 15:44:10 +020044
Marek Vasutb9b8ea32010-09-28 15:44:10 +020045inline void writelrb(uint32_t val, uint32_t addr)
46{
47 writel(val, addr);
Marek Vasut9da6fe52011-11-26 07:32:24 +010048 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +020049 readl(addr);
Marek Vasut9da6fe52011-11-26 07:32:24 +010050 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +020051}
52
Marek Vasut08341be2011-11-26 11:18:57 +010053void pxa2xx_dram_init(void)
Marek Vasutb9b8ea32010-09-28 15:44:10 +020054{
55 uint32_t tmp;
56 int i;
57 /*
58 * 1) Initialize Asynchronous static memory controller
59 */
60
61 writelrb(CONFIG_SYS_MSC0_VAL, MSC0);
62 writelrb(CONFIG_SYS_MSC1_VAL, MSC1);
63 writelrb(CONFIG_SYS_MSC2_VAL, MSC2);
64 /*
65 * 2) Initialize Card Interface
66 */
67
68 /* MECR: Memory Expansion Card Register */
69 writelrb(CONFIG_SYS_MECR_VAL, MECR);
70 /* MCMEM0: Card Interface slot 0 timing */
71 writelrb(CONFIG_SYS_MCMEM0_VAL, MCMEM0);
72 /* MCMEM1: Card Interface slot 1 timing */
73 writelrb(CONFIG_SYS_MCMEM1_VAL, MCMEM1);
74 /* MCATT0: Card Interface Attribute Space Timing, slot 0 */
75 writelrb(CONFIG_SYS_MCATT0_VAL, MCATT0);
76 /* MCATT1: Card Interface Attribute Space Timing, slot 1 */
77 writelrb(CONFIG_SYS_MCATT1_VAL, MCATT1);
78 /* MCIO0: Card Interface I/O Space Timing, slot 0 */
79 writelrb(CONFIG_SYS_MCIO0_VAL, MCIO0);
80 /* MCIO1: Card Interface I/O Space Timing, slot 1 */
81 writelrb(CONFIG_SYS_MCIO1_VAL, MCIO1);
82
83 /*
84 * 3) Configure Fly-By DMA register
85 */
86
87 writelrb(CONFIG_SYS_FLYCNFG_VAL, FLYCNFG);
88
89 /*
90 * 4) Initialize Timing for Sync Memory (SDCLK0)
91 */
92
93 /*
94 * Before accessing MDREFR we need a valid DRI field, so we set
95 * this to power on defaults + DRI field.
96 */
97
98 /* Read current MDREFR config and zero out DRI */
99 tmp = readl(MDREFR) & ~0xfff;
100 /* Add user-specified DRI */
101 tmp |= CONFIG_SYS_MDREFR_VAL & 0xfff;
102 /* Configure important bits */
103 tmp |= MDREFR_K0RUN | MDREFR_SLFRSH;
104 tmp &= ~(MDREFR_APD | MDREFR_E1PIN);
105
106 /* Write MDREFR back */
107 writelrb(tmp, MDREFR);
108
109 /*
110 * 5) Initialize Synchronous Static Memory (Flash/Peripherals)
111 */
112
113 /* Initialize SXCNFG register. Assert the enable bits.
114 *
115 * Write SXMRS to cause an MRS command to all enabled banks of
116 * synchronous static memory. Note that SXLCR need not be written
117 * at this time.
118 */
119 writelrb(CONFIG_SYS_SXCNFG_VAL, SXCNFG);
120
121 /*
122 * 6) Initialize SDRAM
123 */
124
125 writelrb(CONFIG_SYS_MDREFR_VAL & ~MDREFR_SLFRSH, MDREFR);
126 writelrb(CONFIG_SYS_MDREFR_VAL | MDREFR_E1PIN, MDREFR);
127
128 /*
129 * 7) Write MDCNFG with MDCNFG:DEx deasserted (set to 0), to configure
130 * but not enable each SDRAM partition pair.
131 */
132
133 writelrb(CONFIG_SYS_MDCNFG_VAL &
134 ~(MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3), MDCNFG);
Simon Glassa18a6692019-11-14 12:57:28 -0700135
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200136 /* Wait for the clock to the SDRAMs to stabilize, 100..200 usec. */
Simon Glassa18a6692019-11-14 12:57:28 -0700137 writel(0, OSCR);
138 while (readl(OSCR) < 0x300)
139 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200140
141 /*
142 * 8) Trigger a number (usually 8) refresh cycles by attempting
143 * non-burst read or write accesses to disabled SDRAM, as commonly
144 * specified in the power up sequence documented in SDRAM data
145 * sheets. The address(es) used for this purpose must not be
146 * cacheable.
147 */
148 for (i = 9; i >= 0; i--) {
149 writel(i, 0xa0000000);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100150 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200151 }
152 /*
153 * 9) Write MDCNFG with enable bits asserted (MDCNFG:DEx set to 1).
154 */
155
156 tmp = CONFIG_SYS_MDCNFG_VAL &
157 (MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3);
158 tmp |= readl(MDCNFG);
159 writelrb(tmp, MDCNFG);
160
161 /*
162 * 10) Write MDMRS.
163 */
164
165 writelrb(CONFIG_SYS_MDMRS_VAL, MDMRS);
166
167 /*
168 * 11) Enable APD
169 */
170
171 if (CONFIG_SYS_MDREFR_VAL & MDREFR_APD) {
172 tmp = readl(MDREFR);
173 tmp |= MDREFR_APD;
174 writelrb(tmp, MDREFR);
175 }
176}
177
178void pxa_gpio_setup(void)
179{
180 writel(CONFIG_SYS_GPSR0_VAL, GPSR0);
181 writel(CONFIG_SYS_GPSR1_VAL, GPSR1);
182 writel(CONFIG_SYS_GPSR2_VAL, GPSR2);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100183#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200184 writel(CONFIG_SYS_GPSR3_VAL, GPSR3);
185#endif
186
187 writel(CONFIG_SYS_GPCR0_VAL, GPCR0);
188 writel(CONFIG_SYS_GPCR1_VAL, GPCR1);
189 writel(CONFIG_SYS_GPCR2_VAL, GPCR2);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100190#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200191 writel(CONFIG_SYS_GPCR3_VAL, GPCR3);
192#endif
193
194 writel(CONFIG_SYS_GPDR0_VAL, GPDR0);
195 writel(CONFIG_SYS_GPDR1_VAL, GPDR1);
196 writel(CONFIG_SYS_GPDR2_VAL, GPDR2);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100197#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200198 writel(CONFIG_SYS_GPDR3_VAL, GPDR3);
199#endif
200
201 writel(CONFIG_SYS_GAFR0_L_VAL, GAFR0_L);
202 writel(CONFIG_SYS_GAFR0_U_VAL, GAFR0_U);
203 writel(CONFIG_SYS_GAFR1_L_VAL, GAFR1_L);
204 writel(CONFIG_SYS_GAFR1_U_VAL, GAFR1_U);
205 writel(CONFIG_SYS_GAFR2_L_VAL, GAFR2_L);
206 writel(CONFIG_SYS_GAFR2_U_VAL, GAFR2_U);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100207#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200208 writel(CONFIG_SYS_GAFR3_L_VAL, GAFR3_L);
209 writel(CONFIG_SYS_GAFR3_U_VAL, GAFR3_U);
210#endif
211
212 writel(CONFIG_SYS_PSSR_VAL, PSSR);
213}
214
215void pxa_interrupt_setup(void)
216{
217 writel(0, ICLR);
218 writel(0, ICMR);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100219#if defined(CONFIG_CPU_PXA27X)
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200220 writel(0, ICLR2);
221 writel(0, ICMR2);
222#endif
223}
224
225void pxa_clock_setup(void)
226{
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200227 writel(CONFIG_SYS_CKEN, CKEN);
228 writel(CONFIG_SYS_CCCR, CCCR);
Sergey Yanovichd81863d2013-05-21 23:49:41 +0400229 asm volatile("mcr p14, 0, %0, c6, c0, 0" : : "r"(0x0b));
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200230
231 /* enable the 32Khz oscillator for RTC and PowerManager */
232 writel(OSCC_OON, OSCC);
Marek Vasut9da6fe52011-11-26 07:32:24 +0100233 while (!(readl(OSCC) & OSCC_OOK))
234 asm volatile("" : : : "memory");
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200235}
236
237void pxa_wakeup(void)
238{
239 uint32_t rcsr;
240
241 rcsr = readl(RCSR);
242 writel(rcsr & (RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR), RCSR);
243
244 /* Wakeup */
245 if (rcsr & RCSR_SMR) {
246 writel(PSSR_PH, PSSR);
Marek Vasut08341be2011-11-26 11:18:57 +0100247 pxa2xx_dram_init();
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200248 icache_disable();
249 dcache_disable();
Marek Vasut9da6fe52011-11-26 07:32:24 +0100250 asm volatile("mov pc, %0" : : "r"(readl(PSPR)));
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200251 }
252}
253
254int arch_cpu_init(void)
255{
256 pxa_gpio_setup();
Marek Vasutb9b8ea32010-09-28 15:44:10 +0200257 pxa_wakeup();
258 pxa_interrupt_setup();
259 pxa_clock_setup();
260 return 0;
261}
Lei Wena41374b42011-04-13 23:48:31 +0530262
263void i2c_clk_enable(void)
264{
Marek Vasut9da6fe52011-11-26 07:32:24 +0100265 /* Set the global I2C clock on */
Lei Wena41374b42011-04-13 23:48:31 +0530266 writel(readl(CKEN) | CKEN14_I2C, CKEN);
Lei Wena41374b42011-04-13 23:48:31 +0530267}
Marek Vasutb9091622011-10-31 14:12:39 +0100268
Łukasz Dałek8d5a7282013-01-12 15:32:32 +0000269void __attribute__((weak)) reset_cpu(ulong ignored) __attribute__((noreturn));
Marek Vasutb9091622011-10-31 14:12:39 +0100270
271void reset_cpu(ulong ignored)
272{
273 uint32_t tmp;
274
275 setbits_le32(OWER, OWER_WME);
276
277 tmp = readl(OSCR);
278 tmp += 0x1000;
279 writel(tmp, OSMR3);
Sergei Ianovich093f09f2013-12-17 05:03:40 +0400280 writel(MDREFR_SLFRSH, MDREFR);
Marek Vasutb9091622011-10-31 14:12:39 +0100281
282 for (;;)
283 ;
284}
Vasily Khoruzhickb1670092016-03-20 18:37:07 -0700285
286void enable_caches(void)
287{
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400288#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Vasily Khoruzhickb1670092016-03-20 18:37:07 -0700289 icache_enable();
290#endif
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400291#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Vasily Khoruzhickb1670092016-03-20 18:37:07 -0700292 dcache_enable();
293#endif
294}