1
2
3
4
5
6
7
8
9
10
11
12
13#include <asm/io.h>
14#include <asm/system.h>
15#include <command.h>
16#include <common.h>
17#include <asm/arch/pxa-regs.h>
18
19
20static void cache_flush(void)
21{
22 unsigned long i = 0;
23
24 asm ("mcr p15, 0, %0, c7, c5, 0" : : "r" (i));
25}
26
27int cleanup_before_linux(void)
28{
29
30
31
32
33
34
35 disable_interrupts();
36 icache_disable();
37 dcache_disable();
38 cache_flush();
39
40 return 0;
41}
42
43void pxa_wait_ticks(int ticks)
44{
45 writel(0, OSCR);
46 while (readl(OSCR) < ticks)
47 asm volatile("" : : : "memory");
48}
49
50inline void writelrb(uint32_t val, uint32_t addr)
51{
52 writel(val, addr);
53 asm volatile("" : : : "memory");
54 readl(addr);
55 asm volatile("" : : : "memory");
56}
57
58void pxa2xx_dram_init(void)
59{
60 uint32_t tmp;
61 int i;
62
63
64
65
66 writelrb(CONFIG_SYS_MSC0_VAL, MSC0);
67 writelrb(CONFIG_SYS_MSC1_VAL, MSC1);
68 writelrb(CONFIG_SYS_MSC2_VAL, MSC2);
69
70
71
72
73
74 writelrb(CONFIG_SYS_MECR_VAL, MECR);
75
76 writelrb(CONFIG_SYS_MCMEM0_VAL, MCMEM0);
77
78 writelrb(CONFIG_SYS_MCMEM1_VAL, MCMEM1);
79
80 writelrb(CONFIG_SYS_MCATT0_VAL, MCATT0);
81
82 writelrb(CONFIG_SYS_MCATT1_VAL, MCATT1);
83
84 writelrb(CONFIG_SYS_MCIO0_VAL, MCIO0);
85
86 writelrb(CONFIG_SYS_MCIO1_VAL, MCIO1);
87
88
89
90
91
92 writelrb(CONFIG_SYS_FLYCNFG_VAL, FLYCNFG);
93
94
95
96
97
98
99
100
101
102
103
104 tmp = readl(MDREFR) & ~0xfff;
105
106 tmp |= CONFIG_SYS_MDREFR_VAL & 0xfff;
107
108 tmp |= MDREFR_K0RUN | MDREFR_SLFRSH;
109 tmp &= ~(MDREFR_APD | MDREFR_E1PIN);
110
111
112 writelrb(tmp, MDREFR);
113
114
115
116
117
118
119
120
121
122
123
124 writelrb(CONFIG_SYS_SXCNFG_VAL, SXCNFG);
125
126
127
128
129
130 writelrb(CONFIG_SYS_MDREFR_VAL & ~MDREFR_SLFRSH, MDREFR);
131 writelrb(CONFIG_SYS_MDREFR_VAL | MDREFR_E1PIN, MDREFR);
132
133
134
135
136
137
138 writelrb(CONFIG_SYS_MDCNFG_VAL &
139 ~(MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3), MDCNFG);
140
141 pxa_wait_ticks(0x300);
142
143
144
145
146
147
148
149
150 for (i = 9; i >= 0; i--) {
151 writel(i, 0xa0000000);
152 asm volatile("" : : : "memory");
153 }
154
155
156
157
158 tmp = CONFIG_SYS_MDCNFG_VAL &
159 (MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3);
160 tmp |= readl(MDCNFG);
161 writelrb(tmp, MDCNFG);
162
163
164
165
166
167 writelrb(CONFIG_SYS_MDMRS_VAL, MDMRS);
168
169
170
171
172
173 if (CONFIG_SYS_MDREFR_VAL & MDREFR_APD) {
174 tmp = readl(MDREFR);
175 tmp |= MDREFR_APD;
176 writelrb(tmp, MDREFR);
177 }
178}
179
180void pxa_gpio_setup(void)
181{
182 writel(CONFIG_SYS_GPSR0_VAL, GPSR0);
183 writel(CONFIG_SYS_GPSR1_VAL, GPSR1);
184 writel(CONFIG_SYS_GPSR2_VAL, GPSR2);
185#if defined(CONFIG_CPU_PXA27X)
186 writel(CONFIG_SYS_GPSR3_VAL, GPSR3);
187#endif
188
189 writel(CONFIG_SYS_GPCR0_VAL, GPCR0);
190 writel(CONFIG_SYS_GPCR1_VAL, GPCR1);
191 writel(CONFIG_SYS_GPCR2_VAL, GPCR2);
192#if defined(CONFIG_CPU_PXA27X)
193 writel(CONFIG_SYS_GPCR3_VAL, GPCR3);
194#endif
195
196 writel(CONFIG_SYS_GPDR0_VAL, GPDR0);
197 writel(CONFIG_SYS_GPDR1_VAL, GPDR1);
198 writel(CONFIG_SYS_GPDR2_VAL, GPDR2);
199#if defined(CONFIG_CPU_PXA27X)
200 writel(CONFIG_SYS_GPDR3_VAL, GPDR3);
201#endif
202
203 writel(CONFIG_SYS_GAFR0_L_VAL, GAFR0_L);
204 writel(CONFIG_SYS_GAFR0_U_VAL, GAFR0_U);
205 writel(CONFIG_SYS_GAFR1_L_VAL, GAFR1_L);
206 writel(CONFIG_SYS_GAFR1_U_VAL, GAFR1_U);
207 writel(CONFIG_SYS_GAFR2_L_VAL, GAFR2_L);
208 writel(CONFIG_SYS_GAFR2_U_VAL, GAFR2_U);
209#if defined(CONFIG_CPU_PXA27X)
210 writel(CONFIG_SYS_GAFR3_L_VAL, GAFR3_L);
211 writel(CONFIG_SYS_GAFR3_U_VAL, GAFR3_U);
212#endif
213
214 writel(CONFIG_SYS_PSSR_VAL, PSSR);
215}
216
217void pxa_interrupt_setup(void)
218{
219 writel(0, ICLR);
220 writel(0, ICMR);
221#if defined(CONFIG_CPU_PXA27X)
222 writel(0, ICLR2);
223 writel(0, ICMR2);
224#endif
225}
226
227void pxa_clock_setup(void)
228{
229 writel(CONFIG_SYS_CKEN, CKEN);
230 writel(CONFIG_SYS_CCCR, CCCR);
231 asm volatile("mcr p14, 0, %0, c6, c0, 0" : : "r"(0x0b));
232
233
234 writel(OSCC_OON, OSCC);
235 while (!(readl(OSCC) & OSCC_OOK))
236 asm volatile("" : : : "memory");
237}
238
239void pxa_wakeup(void)
240{
241 uint32_t rcsr;
242
243 rcsr = readl(RCSR);
244 writel(rcsr & (RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR), RCSR);
245
246
247 if (rcsr & RCSR_SMR) {
248 writel(PSSR_PH, PSSR);
249 pxa2xx_dram_init();
250 icache_disable();
251 dcache_disable();
252 asm volatile("mov pc, %0" : : "r"(readl(PSPR)));
253 }
254}
255
256int arch_cpu_init(void)
257{
258 pxa_gpio_setup();
259 pxa_wakeup();
260 pxa_interrupt_setup();
261 pxa_clock_setup();
262 return 0;
263}
264
265void i2c_clk_enable(void)
266{
267
268 writel(readl(CKEN) | CKEN14_I2C, CKEN);
269}
270
271void __attribute__((weak)) reset_cpu(ulong ignored) __attribute__((noreturn));
272
273void reset_cpu(ulong ignored)
274{
275 uint32_t tmp;
276
277 setbits_le32(OWER, OWER_WME);
278
279 tmp = readl(OSCR);
280 tmp += 0x1000;
281 writel(tmp, OSMR3);
282 writel(MDREFR_SLFRSH, MDREFR);
283
284 for (;;)
285 ;
286}
287