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