]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/include/asm/arch-pxa/macro.h
PXA: fix MDREFR[APD] bit setting
[karo-tx-uboot.git] / arch / arm / include / asm / arch-pxa / macro.h
1 /*
2  * arch/arm/include/asm/arch-pxa/macro.h
3  *
4  * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
5  *
6  * See file CREDITS for list of people who contributed to this
7  * project.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of
12  * the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22  * MA 02111-1307 USA
23  */
24
25 #ifndef __ASM_ARCH_PXA_MACRO_H__
26 #define __ASM_ARCH_PXA_MACRO_H__
27 #ifdef __ASSEMBLY__
28
29 #include <asm/macro.h>
30 #include <asm/arch/pxa-regs.h>
31
32 /*
33  * This macro performs a 32bit write to a memory location and makes sure the
34  * write operation really happened by performing a read back.
35  *
36  * Clobbered regs: r4, r5
37  */
38 .macro  write32rb addr, data
39         ldr     r4, =\addr
40         ldr     r5, =\data
41         str     r5, [r4]
42         ldr     r5, [r4]
43 .endm
44
45 /*
46  * This macro waits according to OSCR incrementation
47  *
48  * Clobbered regs: r4, r5, r6
49  */
50 .macro  pxa_wait_ticks ticks
51         ldr     r4, =OSCR
52         mov     r5, #0
53         str     r5, [r4]
54         ldr     r5, =\ticks
55 1:
56         ldr     r6, [r4]
57         cmp     r5, r6
58         bgt     1b
59 .endm
60
61 /*
62  * This macro sets up the GPIO pins of the PXA2xx/PXA3xx CPU
63  *
64  * Clobbered regs: r4, r5
65  */
66 .macro  pxa_gpio_setup
67         write32 GPSR0, CONFIG_SYS_GPSR0_VAL
68         write32 GPSR1, CONFIG_SYS_GPSR1_VAL
69         write32 GPSR2, CONFIG_SYS_GPSR2_VAL
70 #if defined(CONFIG_PXA27X) || defined(CONFIG_CPU_MONAHANS)
71         write32 GPSR3, CONFIG_SYS_GPSR3_VAL
72 #endif
73
74         write32 GPCR0, CONFIG_SYS_GPCR0_VAL
75         write32 GPCR1, CONFIG_SYS_GPCR1_VAL
76         write32 GPCR2, CONFIG_SYS_GPCR2_VAL
77 #if defined(CONFIG_PXA27X) || defined(CONFIG_CPU_MONAHANS)
78         write32 GPCR3, CONFIG_SYS_GPCR3_VAL
79 #endif
80
81         write32 GPDR0, CONFIG_SYS_GPDR0_VAL
82         write32 GPDR1, CONFIG_SYS_GPDR1_VAL
83         write32 GPDR2, CONFIG_SYS_GPDR2_VAL
84 #if defined(CONFIG_PXA27X) || defined(CONFIG_CPU_MONAHANS)
85         write32 GPDR3, CONFIG_SYS_GPDR3_VAL
86 #endif
87
88         write32 GAFR0_L, CONFIG_SYS_GAFR0_L_VAL
89         write32 GAFR0_U, CONFIG_SYS_GAFR0_U_VAL
90         write32 GAFR1_L, CONFIG_SYS_GAFR1_L_VAL
91         write32 GAFR1_U, CONFIG_SYS_GAFR1_U_VAL
92         write32 GAFR2_L, CONFIG_SYS_GAFR2_L_VAL
93         write32 GAFR2_U, CONFIG_SYS_GAFR2_U_VAL
94 #if defined(CONFIG_PXA27X) || defined(CONFIG_CPU_MONAHANS)
95         write32 GAFR3_L, CONFIG_SYS_GAFR3_L_VAL
96         write32 GAFR3_U, CONFIG_SYS_GAFR3_U_VAL
97 #endif
98
99         write32 PSSR, CONFIG_SYS_PSSR_VAL
100 .endm
101
102 /*
103  * This macro sets up the Memory controller of the PXA2xx CPU
104  *
105  * WARNING: This macro uses internally r3 and r7 regs for MEMC_BASE
106  *          and CONFIG_SYS_MDREFR_VAL correspondingly. Please do not
107  *          use this regs for other purpose inside this macro.
108  *
109  * Clobbered regs: r3, r4, r5, r6, r7
110  */
111 .macro  pxa_mem_setup
112         /* This comes handy when setting MDREFR */
113         ldr     r3, =MEMC_BASE
114
115         /*
116          * 1) Initialize Asynchronous static memory controller
117          */
118
119         /* MSC0: nCS(0,1) */
120         write32rb       (MEMC_BASE + MSC0_OFFSET), CONFIG_SYS_MSC0_VAL
121         /* MSC1: nCS(2,3) */
122         write32rb       (MEMC_BASE + MSC1_OFFSET), CONFIG_SYS_MSC1_VAL
123         /* MSC2: nCS(4,5) */
124         write32rb       (MEMC_BASE + MSC2_OFFSET), CONFIG_SYS_MSC2_VAL
125
126         /*
127          * 2) Initialize Card Interface
128          */
129
130         /* MECR: Memory Expansion Card Register */
131         write32rb       (MEMC_BASE + MECR_OFFSET), CONFIG_SYS_MECR_VAL
132         /* MCMEM0: Card Interface slot 0 timing */
133         write32rb       (MEMC_BASE + MCMEM0_OFFSET), CONFIG_SYS_MCMEM0_VAL
134         /* MCMEM1: Card Interface slot 1 timing */
135         write32rb       (MEMC_BASE + MCMEM1_OFFSET), CONFIG_SYS_MCMEM1_VAL
136         /* MCATT0: Card Interface Attribute Space Timing, slot 0 */
137         write32rb       (MEMC_BASE + MCATT0_OFFSET), CONFIG_SYS_MCATT0_VAL
138         /* MCATT1: Card Interface Attribute Space Timing, slot 1 */
139         write32rb       (MEMC_BASE + MCATT1_OFFSET), CONFIG_SYS_MCATT1_VAL
140         /* MCIO0: Card Interface I/O Space Timing, slot 0 */
141         write32rb       (MEMC_BASE + MCIO0_OFFSET), CONFIG_SYS_MCIO0_VAL
142         /* MCIO1: Card Interface I/O Space Timing, slot 1 */
143         write32rb       (MEMC_BASE + MCIO1_OFFSET), CONFIG_SYS_MCIO1_VAL
144
145         /*
146          * 3) Configure Fly-By DMA register
147          */
148
149         write32rb       (MEMC_BASE + FLYCNFG_OFFSET), CONFIG_SYS_FLYCNFG_VAL
150
151         /*
152          * 4) Initialize Timing for Sync Memory (SDCLK0)
153          */
154
155         /*
156          * Before accessing MDREFR we need a valid DRI field, so we set
157          * this to power on defaults + DRI field.
158          */
159         ldr     r5, [r3, #MDREFR_OFFSET]
160         bic     r5, r5, #0x0ff
161         bic     r5, r5, #0xf00  /* MDREFR user config with zeroed DRI */
162
163         ldr     r4, =CONFIG_SYS_MDREFR_VAL
164         mov     r7, r4
165         lsl     r4, #20
166         lsr     r4, #20         /* Get a valid DRI field */
167
168         orr     r5, r5, r4      /* MDREFR user config with correct DRI */
169
170         orr     r5, #MDREFR_K0RUN
171         orr     r5, #MDREFR_SLFRSH
172         bic     r5, #MDREFR_APD
173         bic     r5, #MDREFR_E1PIN
174
175         str     r5, [r3, #MDREFR_OFFSET]
176         ldr     r4, [r3, #MDREFR_OFFSET]
177
178         /*
179          * 5) Initialize Synchronous Static Memory (Flash/Peripherals)
180          */
181
182         /* Initialize SXCNFG register. Assert the enable bits.
183          *
184          * Write SXMRS to cause an MRS command to all enabled banks of
185          * synchronous static memory. Note that SXLCR need not be written
186          * at this time.
187          */
188         write32rb       (MEMC_BASE + SXCNFG_OFFSET), CONFIG_SYS_SXCNFG_VAL
189
190         /*
191          * 6) Initialize SDRAM
192          */
193
194         bic     r7, #MDREFR_SLFRSH
195         str     r7, [r3, #MDREFR_OFFSET]
196         ldr     r4, [r3, #MDREFR_OFFSET]
197
198         orr     r7, #MDREFR_E1PIN
199         str     r7, [r3, #MDREFR_OFFSET]
200         ldr     r4, [r3, #MDREFR_OFFSET]
201
202         /*
203          * 7) Write MDCNFG with MDCNFG:DEx deasserted (set to 0), to configure
204          *    but not enable each SDRAM partition pair.
205          */
206
207         /* Fetch platform value of MDCNFG */
208         ldr     r4, =CONFIG_SYS_MDCNFG_VAL
209         /* Disable all sdram banks */
210         bic     r4, r4, #(MDCNFG_DE0|MDCNFG_DE1)
211         bic     r4, r4, #(MDCNFG_DE2|MDCNFG_DE3)
212         /* Write initial value of MDCNFG, w/o enabling sdram banks */
213         str     r4, [r3, #MDCNFG_OFFSET]
214         ldr     r4, [r3, #MDCNFG_OFFSET]
215
216         /* Wait for the clock to the SDRAMs to stabilize, 100..200 usec. */
217         pxa_wait_ticks  0x300
218
219         /*
220          * 8) Trigger a number (usually 8) refresh cycles by attempting
221          *    non-burst read or write accesses to disabled SDRAM, as commonly
222          *    specified in the power up sequence documented in SDRAM data
223          *    sheets. The address(es) used for this purpose must not be
224          *    cacheable.
225          */
226
227         ldr     r4, =CONFIG_SYS_DRAM_BASE
228 .rept 9
229         str     r5, [r4]
230 .endr
231
232         /*
233          * 9) Write MDCNFG with enable bits asserted (MDCNFG:DEx set to 1).
234          */
235
236         ldr     r5, =CONFIG_SYS_MDCNFG_VAL
237         ldr     r4, =(MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3)
238         and     r5, r5, r4
239         ldr     r4, [r3, #MDCNFG_OFFSET]
240         orr     r4, r4, r5
241         str     r4, [r3, #MDCNFG_OFFSET]
242         ldr     r4, [r3, #MDCNFG_OFFSET]
243
244         /*
245          * 10) Write MDMRS.
246          */
247
248         ldr     r4, =CONFIG_SYS_MDMRS_VAL
249         str     r4, [r3, #MDMRS_OFFSET]
250         ldr     r4, [r3, #MDMRS_OFFSET]
251
252         /*
253          * 11) Enable APD
254          */
255
256         ldr     r4, [r3, #MDREFR_OFFSET]
257         and     r7, r7, #MDREFR_APD
258         orr     r4, r4, r7
259         str     r4, [r3, #MDREFR_OFFSET]
260         ldr     r4, [r3, #MDREFR_OFFSET]
261 .endm
262
263 /*
264  * This macro tests if the CPU woke up from sleep and eventually resumes
265  *
266  * Clobbered regs: r4, r5
267  */
268 .macro  pxa_wakeup
269         ldr     r4, =RCSR
270         ldr     r5, [r4]
271         and     r5, r5, #(RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR)
272         str     r5, [r4]
273         teq     r5, #RCSR_SMR
274
275         bne     pxa_wakeup_exit
276
277         ldr     r4, =PSSR
278         mov     r5, #PSSR_PH
279         str     r5, [r4]
280
281         ldr     r4, =PSPR
282         ldr     pc, [r4]
283 pxa_wakeup_exit:
284 .endm
285
286 /*
287  * This macro disables all interupts on PXA2xx/PXA3xx CPU
288  *
289  * Clobbered regs: r4, r5
290  */
291 .macro  pxa_intr_setup
292         write32 ICLR, 0
293         write32 ICMR, 0
294 #if defined(CONFIG_PXA27X) || defined(CONFIG_CPU_MONAHANS)
295         write32 ICLR2, 0
296         write32 ICMR2, 0
297 #endif
298 .endm
299
300 /*
301  * This macro configures clock on PXA2xx/PXA3xx CPU
302  *
303  * Clobbered regs: r4, r5
304  */
305 .macro  pxa_clock_setup
306         /* Disable the peripheral clocks, and set the core clock frequency */
307
308         /* Turn Off ALL on-chip peripheral clocks for re-configuration */
309         write32 CKEN, CONFIG_SYS_CKEN
310
311         /* Write CCCR */
312         write32 CCCR, CONFIG_SYS_CCCR
313
314 #ifdef CONFIG_RTC
315         /* enable the 32Khz oscillator for RTC and PowerManager */
316         write32 OSCC, #OSCC_OON
317         ldr     r4, =OSCC
318
319         /* Spin here until OSCC.OOK get set, meaning the PLL has settled. */
320 2:
321         ldr     r5, [r4]
322         ands    r5, r5, #1
323         beq     2b
324 #endif
325 .endm
326
327 #endif /* __ASSEMBLY__ */
328 #endif /* __ASM_ARCH_PXA_MACRO_H__ */