macro.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. #ifndef __ASM_ARCH_PXA_MACRO_H__
  25. #define __ASM_ARCH_PXA_MACRO_H__
  26. #ifdef __ASSEMBLY__
  27. #include <asm/macro.h>
  28. #include <asm/arch/pxa-regs.h>
  29. /*
  30. * This macro performs a 32bit write to a memory location and makes sure the
  31. * write operation really happened by performing a read back.
  32. *
  33. * Clobbered regs: r4, r5
  34. */
  35. .macro write32rb addr, data
  36. ldr r4, =\addr
  37. ldr r5, =\data
  38. str r5, [r4]
  39. ldr r5, [r4]
  40. .endm
  41. /*
  42. * This macro waits according to OSCR incrementation
  43. *
  44. * Clobbered regs: r4, r5, r6
  45. */
  46. .macro pxa_wait_ticks ticks
  47. ldr r4, =OSCR
  48. mov r5, #0
  49. str r5, [r4]
  50. ldr r5, =\ticks
  51. 1:
  52. ldr r6, [r4]
  53. cmp r5, r6
  54. bgt 1b
  55. .endm
  56. /*
  57. * This macro sets up the GPIO pins of the PXA2xx/PXA3xx CPU
  58. *
  59. * Clobbered regs: r4, r5
  60. */
  61. .macro pxa_gpio_setup
  62. write32 GPSR0, CONFIG_SYS_GPSR0_VAL
  63. write32 GPSR1, CONFIG_SYS_GPSR1_VAL
  64. write32 GPSR2, CONFIG_SYS_GPSR2_VAL
  65. #if defined(CONFIG_PXA27X) || defined(CONFIG_CPU_MONAHANS)
  66. write32 GPSR3, CONFIG_SYS_GPSR3_VAL
  67. #endif
  68. write32 GPCR0, CONFIG_SYS_GPCR0_VAL
  69. write32 GPCR1, CONFIG_SYS_GPCR1_VAL
  70. write32 GPCR2, CONFIG_SYS_GPCR2_VAL
  71. #if defined(CONFIG_PXA27X) || defined(CONFIG_CPU_MONAHANS)
  72. write32 GPCR3, CONFIG_SYS_GPCR3_VAL
  73. #endif
  74. write32 GPDR0, CONFIG_SYS_GPDR0_VAL
  75. write32 GPDR1, CONFIG_SYS_GPDR1_VAL
  76. write32 GPDR2, CONFIG_SYS_GPDR2_VAL
  77. #if defined(CONFIG_PXA27X) || defined(CONFIG_CPU_MONAHANS)
  78. write32 GPDR3, CONFIG_SYS_GPDR3_VAL
  79. #endif
  80. write32 GAFR0_L, CONFIG_SYS_GAFR0_L_VAL
  81. write32 GAFR0_U, CONFIG_SYS_GAFR0_U_VAL
  82. write32 GAFR1_L, CONFIG_SYS_GAFR1_L_VAL
  83. write32 GAFR1_U, CONFIG_SYS_GAFR1_U_VAL
  84. write32 GAFR2_L, CONFIG_SYS_GAFR2_L_VAL
  85. write32 GAFR2_U, CONFIG_SYS_GAFR2_U_VAL
  86. #if defined(CONFIG_PXA27X) || defined(CONFIG_CPU_MONAHANS)
  87. write32 GAFR3_L, CONFIG_SYS_GAFR3_L_VAL
  88. write32 GAFR3_U, CONFIG_SYS_GAFR3_U_VAL
  89. #endif
  90. write32 PSSR, CONFIG_SYS_PSSR_VAL
  91. .endm
  92. /*
  93. * This macro sets up the Memory controller of the PXA2xx CPU
  94. *
  95. * Clobbered regs: r3, r4, r5
  96. */
  97. .macro pxa_mem_setup
  98. /* This comes handy when setting MDREFR */
  99. ldr r3, =MEMC_BASE
  100. /*
  101. * 1) Initialize Asynchronous static memory controller
  102. */
  103. /* MSC0: nCS(0,1) */
  104. write32rb (MEMC_BASE + MSC0_OFFSET), CONFIG_SYS_MSC0_VAL
  105. /* MSC1: nCS(2,3) */
  106. write32rb (MEMC_BASE + MSC1_OFFSET), CONFIG_SYS_MSC1_VAL
  107. /* MSC2: nCS(4,5) */
  108. write32rb (MEMC_BASE + MSC2_OFFSET), CONFIG_SYS_MSC2_VAL
  109. /*
  110. * 2) Initialize Card Interface
  111. */
  112. /* MECR: Memory Expansion Card Register */
  113. write32rb (MEMC_BASE + MECR_OFFSET), CONFIG_SYS_MECR_VAL
  114. /* MCMEM0: Card Interface slot 0 timing */
  115. write32rb (MEMC_BASE + MCMEM0_OFFSET), CONFIG_SYS_MCMEM0_VAL
  116. /* MCMEM1: Card Interface slot 1 timing */
  117. write32rb (MEMC_BASE + MCMEM1_OFFSET), CONFIG_SYS_MCMEM1_VAL
  118. /* MCATT0: Card Interface Attribute Space Timing, slot 0 */
  119. write32rb (MEMC_BASE + MCATT0_OFFSET), CONFIG_SYS_MCATT0_VAL
  120. /* MCATT1: Card Interface Attribute Space Timing, slot 1 */
  121. write32rb (MEMC_BASE + MCATT1_OFFSET), CONFIG_SYS_MCATT1_VAL
  122. /* MCIO0: Card Interface I/O Space Timing, slot 0 */
  123. write32rb (MEMC_BASE + MCIO0_OFFSET), CONFIG_SYS_MCIO0_VAL
  124. /* MCIO1: Card Interface I/O Space Timing, slot 1 */
  125. write32rb (MEMC_BASE + MCIO1_OFFSET), CONFIG_SYS_MCIO1_VAL
  126. /*
  127. * 3) Configure Fly-By DMA register
  128. */
  129. write32rb (MEMC_BASE + FLYCNFG_OFFSET), CONFIG_SYS_FLYCNFG_VAL
  130. /*
  131. * 4) Initialize Timing for Sync Memory (SDCLK0)
  132. */
  133. /*
  134. * Before accessing MDREFR we need a valid DRI field, so we set
  135. * this to power on defaults + DRI field.
  136. */
  137. ldr r5, [r3, #MDREFR_OFFSET]
  138. bic r5, r5, #0x0ff
  139. bic r5, r5, #0xf00 /* MDREFR user config with zeroed DRI */
  140. ldr r4, =CONFIG_SYS_MDREFR_VAL
  141. mov r6, r4
  142. lsl r4, #20
  143. lsr r4, #20 /* Get a valid DRI field */
  144. orr r5, r5, r4 /* MDREFR user config with correct DRI */
  145. orr r5, #MDREFR_K0RUN
  146. orr r5, #MDREFR_SLFRSH
  147. bic r5, #MDREFR_APD
  148. bic r5, #MDREFR_E1PIN
  149. str r5, [r3, #MDREFR_OFFSET]
  150. ldr r4, [r3, #MDREFR_OFFSET]
  151. /*
  152. * 5) Initialize Synchronous Static Memory (Flash/Peripherals)
  153. */
  154. /* Initialize SXCNFG register. Assert the enable bits.
  155. *
  156. * Write SXMRS to cause an MRS command to all enabled banks of
  157. * synchronous static memory. Note that SXLCR need not be written
  158. * at this time.
  159. */
  160. write32rb (MEMC_BASE + SXCNFG_OFFSET), CONFIG_SYS_SXCNFG_VAL
  161. /*
  162. * 6) Initialize SDRAM
  163. */
  164. bic r6, #MDREFR_SLFRSH
  165. str r6, [r3, #MDREFR_OFFSET]
  166. ldr r4, [r3, #MDREFR_OFFSET]
  167. orr r6, #MDREFR_E1PIN
  168. str r6, [r3, #MDREFR_OFFSET]
  169. ldr r4, [r3, #MDREFR_OFFSET]
  170. /*
  171. * 7) Write MDCNFG with MDCNFG:DEx deasserted (set to 0), to configure
  172. * but not enable each SDRAM partition pair.
  173. */
  174. /* Fetch platform value of MDCNFG */
  175. ldr r4, =CONFIG_SYS_MDCNFG_VAL
  176. /* Disable all sdram banks */
  177. bic r4, r4, #(MDCNFG_DE0|MDCNFG_DE1)
  178. bic r4, r4, #(MDCNFG_DE2|MDCNFG_DE3)
  179. /* Write initial value of MDCNFG, w/o enabling sdram banks */
  180. str r4, [r3, #MDCNFG_OFFSET]
  181. ldr r4, [r3, #MDCNFG_OFFSET]
  182. /* Wait for the clock to the SDRAMs to stabilize, 100..200 usec. */
  183. pxa_wait_ticks 0x300
  184. /*
  185. * 8) Trigger a number (usually 8) refresh cycles by attempting
  186. * non-burst read or write accesses to disabled SDRAM, as commonly
  187. * specified in the power up sequence documented in SDRAM data
  188. * sheets. The address(es) used for this purpose must not be
  189. * cacheable.
  190. */
  191. ldr r4, =CONFIG_SYS_DRAM_BASE
  192. .rept 9
  193. str r5, [r4]
  194. .endr
  195. /*
  196. * 9) Write MDCNFG with enable bits asserted (MDCNFG:DEx set to 1).
  197. */
  198. ldr r5, =CONFIG_SYS_MDCNFG_VAL
  199. ldr r4, =(MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3)
  200. and r5, r5, r4
  201. ldr r4, [r3, #MDCNFG_OFFSET]
  202. orr r4, r4, r5
  203. str r4, [r3, #MDCNFG_OFFSET]
  204. ldr r4, [r3, #MDCNFG_OFFSET]
  205. /*
  206. * 10) Write MDMRS.
  207. */
  208. ldr r4, =CONFIG_SYS_MDMRS_VAL
  209. str r4, [r3, #MDMRS_OFFSET]
  210. ldr r4, [r3, #MDMRS_OFFSET]
  211. /*
  212. * 11) Enable APD
  213. */
  214. ldr r4, [r3, #MDREFR_OFFSET]
  215. and r6, r6, #MDREFR_APD
  216. orr r4, r4, r6
  217. str r4, [r3, #MDREFR_OFFSET]
  218. ldr r4, [r3, #MDREFR_OFFSET]
  219. .endm
  220. /*
  221. * This macro tests if the CPU woke up from sleep and eventually resumes
  222. *
  223. * Clobbered regs: r4, r5
  224. */
  225. .macro pxa_wakeup
  226. ldr r4, =RCSR
  227. ldr r5, [r4]
  228. and r5, r5, #(RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR)
  229. str r5, [r4]
  230. teq r5, #RCSR_SMR
  231. bne pxa_wakeup_exit
  232. ldr r4, =PSSR
  233. mov r5, #PSSR_PH
  234. str r5, [r4]
  235. ldr r4, =PSPR
  236. ldr pc, [r4]
  237. pxa_wakeup_exit:
  238. .endm
  239. /*
  240. * This macro disables all interupts on PXA2xx/PXA3xx CPU
  241. *
  242. * Clobbered regs: r4, r5
  243. */
  244. .macro pxa_intr_setup
  245. write32 ICLR, 0
  246. write32 ICMR, 0
  247. #if defined(CONFIG_PXA27X) || defined(CONFIG_CPU_MONAHANS)
  248. write32 ICLR2, 0
  249. write32 ICMR2, 0
  250. #endif
  251. .endm
  252. /*
  253. * This macro configures clock on PXA2xx/PXA3xx CPU
  254. *
  255. * Clobbered regs: r4, r5
  256. */
  257. .macro pxa_clock_setup
  258. /* Disable the peripheral clocks, and set the core clock frequency */
  259. /* Turn Off ALL on-chip peripheral clocks for re-configuration */
  260. write32 CKEN, CONFIG_SYS_CKEN
  261. /* Write CCCR */
  262. write32 CCCR, CONFIG_SYS_CCCR
  263. #ifdef CONFIG_RTC
  264. /* enable the 32Khz oscillator for RTC and PowerManager */
  265. write32 OSCC, #OSCC_OON
  266. ldr r4, =OSCC
  267. /* Spin here until OSCC.OOK get set, meaning the PLL has settled. */
  268. 2:
  269. ldr r5, [r4]
  270. ands r5, r5, #1
  271. beq 2b
  272. #endif
  273. .endm
  274. #endif /* __ASSEMBLY__ */
  275. #endif /* __ASM_ARCH_PXA_MACRO_H__ */