blob: 0c186101eccfaeb21f515e127b5cc297aaa49145 [file] [log] [blame]
wdenk11a72d92002-10-27 22:25:25 +00001/*
2 * (C) Copyright 2002
3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4 * Marius Groeger <mgroeger@sysgo.de>
5 *
6 * (C) Copyright 2002
7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * Alex Zuepke <azu@sysgo.de>
9 *
10 * See file CREDITS for list of people who contributed to this
11 * project.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 * MA 02111-1307 USA
27 */
28
Marek Vasut3ba8bf72010-09-09 09:50:39 +020029#include <asm/io.h>
Jean-Christophe PLAGNIOL-VILLARD677e62f2009-04-05 13:02:43 +020030#include <asm/system.h>
Marek Vasut3ba8bf72010-09-09 09:50:39 +020031#include <command.h>
32#include <common.h>
Marek Vasut2cad92f2010-09-28 15:44:10 +020033#include <asm/arch/pxa-regs.h>
wdenk11a72d92002-10-27 22:25:25 +000034
Marek Vasutd10237d2011-11-26 07:32:24 +010035/* Flush I/D-cache */
36static void cache_flush(void)
wdenk11a72d92002-10-27 22:25:25 +000037{
Jean-Christophe PLAGNIOL-VILLARDb3acb6c2009-04-05 13:06:31 +020038 unsigned long i = 0;
wdenk11a72d92002-10-27 22:25:25 +000039
Marek Vasutd10237d2011-11-26 07:32:24 +010040 asm ("mcr p15, 0, %0, c7, c5, 0" : : "r" (i));
wdenk11a72d92002-10-27 22:25:25 +000041}
wdenk71f95112003-06-15 22:40:42 +000042
Marek Vasutd10237d2011-11-26 07:32:24 +010043int cleanup_before_linux(void)
wdenk71f95112003-06-15 22:40:42 +000044{
Marek Vasutd10237d2011-11-26 07:32:24 +010045 /*
46 * This function is called just before we call Linux. It prepares
47 * the processor for Linux by just disabling everything that can
48 * disturb booting Linux.
49 */
Marek Vasut3ba8bf72010-09-09 09:50:39 +020050
Marek Vasutd10237d2011-11-26 07:32:24 +010051 disable_interrupts();
52 icache_disable();
53 dcache_disable();
54 cache_flush();
wdenk71f95112003-06-15 22:40:42 +000055
Marek Vasutd10237d2011-11-26 07:32:24 +010056 return 0;
wdenk71f95112003-06-15 22:40:42 +000057}
Marek Vasut2cad92f2010-09-28 15:44:10 +020058
59void pxa_wait_ticks(int ticks)
60{
61 writel(0, OSCR);
62 while (readl(OSCR) < ticks)
Marek Vasutd10237d2011-11-26 07:32:24 +010063 asm volatile("" : : : "memory");
Marek Vasut2cad92f2010-09-28 15:44:10 +020064}
65
66inline void writelrb(uint32_t val, uint32_t addr)
67{
68 writel(val, addr);
Marek Vasutd10237d2011-11-26 07:32:24 +010069 asm volatile("" : : : "memory");
Marek Vasut2cad92f2010-09-28 15:44:10 +020070 readl(addr);
Marek Vasutd10237d2011-11-26 07:32:24 +010071 asm volatile("" : : : "memory");
Marek Vasut2cad92f2010-09-28 15:44:10 +020072}
73
Marek Vasutf68d2a22011-11-26 11:18:57 +010074void pxa2xx_dram_init(void)
Marek Vasut2cad92f2010-09-28 15:44:10 +020075{
76 uint32_t tmp;
77 int i;
78 /*
79 * 1) Initialize Asynchronous static memory controller
80 */
81
82 writelrb(CONFIG_SYS_MSC0_VAL, MSC0);
83 writelrb(CONFIG_SYS_MSC1_VAL, MSC1);
84 writelrb(CONFIG_SYS_MSC2_VAL, MSC2);
85 /*
86 * 2) Initialize Card Interface
87 */
88
89 /* MECR: Memory Expansion Card Register */
90 writelrb(CONFIG_SYS_MECR_VAL, MECR);
91 /* MCMEM0: Card Interface slot 0 timing */
92 writelrb(CONFIG_SYS_MCMEM0_VAL, MCMEM0);
93 /* MCMEM1: Card Interface slot 1 timing */
94 writelrb(CONFIG_SYS_MCMEM1_VAL, MCMEM1);
95 /* MCATT0: Card Interface Attribute Space Timing, slot 0 */
96 writelrb(CONFIG_SYS_MCATT0_VAL, MCATT0);
97 /* MCATT1: Card Interface Attribute Space Timing, slot 1 */
98 writelrb(CONFIG_SYS_MCATT1_VAL, MCATT1);
99 /* MCIO0: Card Interface I/O Space Timing, slot 0 */
100 writelrb(CONFIG_SYS_MCIO0_VAL, MCIO0);
101 /* MCIO1: Card Interface I/O Space Timing, slot 1 */
102 writelrb(CONFIG_SYS_MCIO1_VAL, MCIO1);
103
104 /*
105 * 3) Configure Fly-By DMA register
106 */
107
108 writelrb(CONFIG_SYS_FLYCNFG_VAL, FLYCNFG);
109
110 /*
111 * 4) Initialize Timing for Sync Memory (SDCLK0)
112 */
113
114 /*
115 * Before accessing MDREFR we need a valid DRI field, so we set
116 * this to power on defaults + DRI field.
117 */
118
119 /* Read current MDREFR config and zero out DRI */
120 tmp = readl(MDREFR) & ~0xfff;
121 /* Add user-specified DRI */
122 tmp |= CONFIG_SYS_MDREFR_VAL & 0xfff;
123 /* Configure important bits */
124 tmp |= MDREFR_K0RUN | MDREFR_SLFRSH;
125 tmp &= ~(MDREFR_APD | MDREFR_E1PIN);
126
127 /* Write MDREFR back */
128 writelrb(tmp, MDREFR);
129
130 /*
131 * 5) Initialize Synchronous Static Memory (Flash/Peripherals)
132 */
133
134 /* Initialize SXCNFG register. Assert the enable bits.
135 *
136 * Write SXMRS to cause an MRS command to all enabled banks of
137 * synchronous static memory. Note that SXLCR need not be written
138 * at this time.
139 */
140 writelrb(CONFIG_SYS_SXCNFG_VAL, SXCNFG);
141
142 /*
143 * 6) Initialize SDRAM
144 */
145
146 writelrb(CONFIG_SYS_MDREFR_VAL & ~MDREFR_SLFRSH, MDREFR);
147 writelrb(CONFIG_SYS_MDREFR_VAL | MDREFR_E1PIN, MDREFR);
148
149 /*
150 * 7) Write MDCNFG with MDCNFG:DEx deasserted (set to 0), to configure
151 * but not enable each SDRAM partition pair.
152 */
153
154 writelrb(CONFIG_SYS_MDCNFG_VAL &
155 ~(MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3), MDCNFG);
156 /* Wait for the clock to the SDRAMs to stabilize, 100..200 usec. */
157 pxa_wait_ticks(0x300);
158
159 /*
160 * 8) Trigger a number (usually 8) refresh cycles by attempting
161 * non-burst read or write accesses to disabled SDRAM, as commonly
162 * specified in the power up sequence documented in SDRAM data
163 * sheets. The address(es) used for this purpose must not be
164 * cacheable.
165 */
166 for (i = 9; i >= 0; i--) {
167 writel(i, 0xa0000000);
Marek Vasutd10237d2011-11-26 07:32:24 +0100168 asm volatile("" : : : "memory");
Marek Vasut2cad92f2010-09-28 15:44:10 +0200169 }
170 /*
171 * 9) Write MDCNFG with enable bits asserted (MDCNFG:DEx set to 1).
172 */
173
174 tmp = CONFIG_SYS_MDCNFG_VAL &
175 (MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3);
176 tmp |= readl(MDCNFG);
177 writelrb(tmp, MDCNFG);
178
179 /*
180 * 10) Write MDMRS.
181 */
182
183 writelrb(CONFIG_SYS_MDMRS_VAL, MDMRS);
184
185 /*
186 * 11) Enable APD
187 */
188
189 if (CONFIG_SYS_MDREFR_VAL & MDREFR_APD) {
190 tmp = readl(MDREFR);
191 tmp |= MDREFR_APD;
192 writelrb(tmp, MDREFR);
193 }
194}
195
196void pxa_gpio_setup(void)
197{
198 writel(CONFIG_SYS_GPSR0_VAL, GPSR0);
199 writel(CONFIG_SYS_GPSR1_VAL, GPSR1);
200 writel(CONFIG_SYS_GPSR2_VAL, GPSR2);
Marek Vasutd10237d2011-11-26 07:32:24 +0100201#if defined(CONFIG_CPU_PXA27X)
Marek Vasut2cad92f2010-09-28 15:44:10 +0200202 writel(CONFIG_SYS_GPSR3_VAL, GPSR3);
203#endif
204
205 writel(CONFIG_SYS_GPCR0_VAL, GPCR0);
206 writel(CONFIG_SYS_GPCR1_VAL, GPCR1);
207 writel(CONFIG_SYS_GPCR2_VAL, GPCR2);
Marek Vasutd10237d2011-11-26 07:32:24 +0100208#if defined(CONFIG_CPU_PXA27X)
Marek Vasut2cad92f2010-09-28 15:44:10 +0200209 writel(CONFIG_SYS_GPCR3_VAL, GPCR3);
210#endif
211
212 writel(CONFIG_SYS_GPDR0_VAL, GPDR0);
213 writel(CONFIG_SYS_GPDR1_VAL, GPDR1);
214 writel(CONFIG_SYS_GPDR2_VAL, GPDR2);
Marek Vasutd10237d2011-11-26 07:32:24 +0100215#if defined(CONFIG_CPU_PXA27X)
Marek Vasut2cad92f2010-09-28 15:44:10 +0200216 writel(CONFIG_SYS_GPDR3_VAL, GPDR3);
217#endif
218
219 writel(CONFIG_SYS_GAFR0_L_VAL, GAFR0_L);
220 writel(CONFIG_SYS_GAFR0_U_VAL, GAFR0_U);
221 writel(CONFIG_SYS_GAFR1_L_VAL, GAFR1_L);
222 writel(CONFIG_SYS_GAFR1_U_VAL, GAFR1_U);
223 writel(CONFIG_SYS_GAFR2_L_VAL, GAFR2_L);
224 writel(CONFIG_SYS_GAFR2_U_VAL, GAFR2_U);
Marek Vasutd10237d2011-11-26 07:32:24 +0100225#if defined(CONFIG_CPU_PXA27X)
Marek Vasut2cad92f2010-09-28 15:44:10 +0200226 writel(CONFIG_SYS_GAFR3_L_VAL, GAFR3_L);
227 writel(CONFIG_SYS_GAFR3_U_VAL, GAFR3_U);
228#endif
229
230 writel(CONFIG_SYS_PSSR_VAL, PSSR);
231}
232
233void pxa_interrupt_setup(void)
234{
235 writel(0, ICLR);
236 writel(0, ICMR);
Marek Vasutd10237d2011-11-26 07:32:24 +0100237#if defined(CONFIG_CPU_PXA27X)
Marek Vasut2cad92f2010-09-28 15:44:10 +0200238 writel(0, ICLR2);
239 writel(0, ICMR2);
240#endif
241}
242
243void pxa_clock_setup(void)
244{
Marek Vasut2cad92f2010-09-28 15:44:10 +0200245 writel(CONFIG_SYS_CKEN, CKEN);
246 writel(CONFIG_SYS_CCCR, CCCR);
Marek Vasutd10237d2011-11-26 07:32:24 +0100247 asm volatile("mcr p14, 0, %0, c6, c0, 0" : : "r"(2));
Marek Vasut2cad92f2010-09-28 15:44:10 +0200248
249 /* enable the 32Khz oscillator for RTC and PowerManager */
250 writel(OSCC_OON, OSCC);
Marek Vasutd10237d2011-11-26 07:32:24 +0100251 while (!(readl(OSCC) & OSCC_OOK))
252 asm volatile("" : : : "memory");
Marek Vasut2cad92f2010-09-28 15:44:10 +0200253}
254
255void pxa_wakeup(void)
256{
257 uint32_t rcsr;
258
259 rcsr = readl(RCSR);
260 writel(rcsr & (RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR), RCSR);
261
262 /* Wakeup */
263 if (rcsr & RCSR_SMR) {
264 writel(PSSR_PH, PSSR);
Marek Vasutf68d2a22011-11-26 11:18:57 +0100265 pxa2xx_dram_init();
Marek Vasut2cad92f2010-09-28 15:44:10 +0200266 icache_disable();
267 dcache_disable();
Marek Vasutd10237d2011-11-26 07:32:24 +0100268 asm volatile("mov pc, %0" : : "r"(readl(PSPR)));
Marek Vasut2cad92f2010-09-28 15:44:10 +0200269 }
270}
271
272int arch_cpu_init(void)
273{
274 pxa_gpio_setup();
Marek Vasut2cad92f2010-09-28 15:44:10 +0200275 pxa_wakeup();
276 pxa_interrupt_setup();
277 pxa_clock_setup();
278 return 0;
279}
Lei Wen3df619e2011-04-13 23:48:31 +0530280
281void i2c_clk_enable(void)
282{
Marek Vasutd10237d2011-11-26 07:32:24 +0100283 /* Set the global I2C clock on */
Lei Wen3df619e2011-04-13 23:48:31 +0530284 writel(readl(CKEN) | CKEN14_I2C, CKEN);
Lei Wen3df619e2011-04-13 23:48:31 +0530285}
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100286
Łukasz Dałek2ac2bb72013-01-12 15:32:32 +0000287void __attribute__((weak)) reset_cpu(ulong ignored) __attribute__((noreturn));
Marek Vasut20f7b1b2011-10-31 14:12:39 +0100288
289void reset_cpu(ulong ignored)
290{
291 uint32_t tmp;
292
293 setbits_le32(OWER, OWER_WME);
294
295 tmp = readl(OSCR);
296 tmp += 0x1000;
297 writel(tmp, OSMR3);
298
299 for (;;)
300 ;
301}