macro.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. * WARNING: This macro uses internally r3 and r7 regs for MEMC_BASE
  96. * and CONFIG_SYS_MDREFR_VAL correspondingly. Please do not
  97. * use this regs for other purpose inside this macro.
  98. *
  99. * Clobbered regs: r3, r4, r5, r6, r7
  100. */
  101. .macro pxa_mem_setup
  102. /* This comes handy when setting MDREFR */
  103. ldr r3, =MEMC_BASE
  104. /*
  105. * 1) Initialize Asynchronous static memory controller
  106. */
  107. /* MSC0: nCS(0,1) */
  108. write32rb (MEMC_BASE + MSC0_OFFSET), CONFIG_SYS_MSC0_VAL
  109. /* MSC1: nCS(2,3) */
  110. write32rb (MEMC_BASE + MSC1_OFFSET), CONFIG_SYS_MSC1_VAL
  111. /* MSC2: nCS(4,5) */
  112. write32rb (MEMC_BASE + MSC2_OFFSET), CONFIG_SYS_MSC2_VAL
  113. /*
  114. * 2) Initialize Card Interface
  115. */
  116. /* MECR: Memory Expansion Card Register */
  117. write32rb (MEMC_BASE + MECR_OFFSET), CONFIG_SYS_MECR_VAL
  118. /* MCMEM0: Card Interface slot 0 timing */
  119. write32rb (MEMC_BASE + MCMEM0_OFFSET), CONFIG_SYS_MCMEM0_VAL
  120. /* MCMEM1: Card Interface slot 1 timing */
  121. write32rb (MEMC_BASE + MCMEM1_OFFSET), CONFIG_SYS_MCMEM1_VAL
  122. /* MCATT0: Card Interface Attribute Space Timing, slot 0 */
  123. write32rb (MEMC_BASE + MCATT0_OFFSET), CONFIG_SYS_MCATT0_VAL
  124. /* MCATT1: Card Interface Attribute Space Timing, slot 1 */
  125. write32rb (MEMC_BASE + MCATT1_OFFSET), CONFIG_SYS_MCATT1_VAL
  126. /* MCIO0: Card Interface I/O Space Timing, slot 0 */
  127. write32rb (MEMC_BASE + MCIO0_OFFSET), CONFIG_SYS_MCIO0_VAL
  128. /* MCIO1: Card Interface I/O Space Timing, slot 1 */
  129. write32rb (MEMC_BASE + MCIO1_OFFSET), CONFIG_SYS_MCIO1_VAL
  130. /*
  131. * 3) Configure Fly-By DMA register
  132. */
  133. write32rb (MEMC_BASE + FLYCNFG_OFFSET), CONFIG_SYS_FLYCNFG_VAL
  134. /*
  135. * 4) Initialize Timing for Sync Memory (SDCLK0)
  136. */
  137. /*
  138. * Before accessing MDREFR we need a valid DRI field, so we set
  139. * this to power on defaults + DRI field.
  140. */
  141. ldr r5, [r3, #MDREFR_OFFSET]
  142. bic r5, r5, #0x0ff
  143. bic r5, r5, #0xf00 /* MDREFR user config with zeroed DRI */
  144. ldr r4, =CONFIG_SYS_MDREFR_VAL
  145. mov r7, r4
  146. lsl r4, #20
  147. lsr r4, #20 /* Get a valid DRI field */
  148. orr r5, r5, r4 /* MDREFR user config with correct DRI */
  149. orr r5, #MDREFR_K0RUN
  150. orr r5, #MDREFR_SLFRSH
  151. bic r5, #MDREFR_APD
  152. bic r5, #MDREFR_E1PIN
  153. str r5, [r3, #MDREFR_OFFSET]
  154. ldr r4, [r3, #MDREFR_OFFSET]
  155. /*
  156. * 5) Initialize Synchronous Static Memory (Flash/Peripherals)
  157. */
  158. /* Initialize SXCNFG register. Assert the enable bits.
  159. *
  160. * Write SXMRS to cause an MRS command to all enabled banks of
  161. * synchronous static memory. Note that SXLCR need not be written
  162. * at this time.
  163. */
  164. write32rb (MEMC_BASE + SXCNFG_OFFSET), CONFIG_SYS_SXCNFG_VAL
  165. /*
  166. * 6) Initialize SDRAM
  167. */
  168. bic r7, #MDREFR_SLFRSH
  169. str r7, [r3, #MDREFR_OFFSET]
  170. ldr r4, [r3, #MDREFR_OFFSET]
  171. orr r7, #MDREFR_E1PIN
  172. str r7, [r3, #MDREFR_OFFSET]
  173. ldr r4, [r3, #MDREFR_OFFSET]
  174. /*
  175. * 7) Write MDCNFG with MDCNFG:DEx deasserted (set to 0), to configure
  176. * but not enable each SDRAM partition pair.
  177. */
  178. /* Fetch platform value of MDCNFG */
  179. ldr r4, =CONFIG_SYS_MDCNFG_VAL
  180. /* Disable all sdram banks */
  181. bic r4, r4, #(MDCNFG_DE0|MDCNFG_DE1)
  182. bic r4, r4, #(MDCNFG_DE2|MDCNFG_DE3)
  183. /* Write initial value of MDCNFG, w/o enabling sdram banks */
  184. str r4, [r3, #MDCNFG_OFFSET]
  185. ldr r4, [r3, #MDCNFG_OFFSET]
  186. /* Wait for the clock to the SDRAMs to stabilize, 100..200 usec. */
  187. pxa_wait_ticks 0x300
  188. /*
  189. * 8) Trigger a number (usually 8) refresh cycles by attempting
  190. * non-burst read or write accesses to disabled SDRAM, as commonly
  191. * specified in the power up sequence documented in SDRAM data
  192. * sheets. The address(es) used for this purpose must not be
  193. * cacheable.
  194. */
  195. ldr r4, =CONFIG_SYS_DRAM_BASE
  196. .rept 9
  197. str r5, [r4]
  198. .endr
  199. /*
  200. * 9) Write MDCNFG with enable bits asserted (MDCNFG:DEx set to 1).
  201. */
  202. ldr r5, =CONFIG_SYS_MDCNFG_VAL
  203. ldr r4, =(MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3)
  204. and r5, r5, r4
  205. ldr r4, [r3, #MDCNFG_OFFSET]
  206. orr r4, r4, r5
  207. str r4, [r3, #MDCNFG_OFFSET]
  208. ldr r4, [r3, #MDCNFG_OFFSET]
  209. /*
  210. * 10) Write MDMRS.
  211. */
  212. ldr r4, =CONFIG_SYS_MDMRS_VAL
  213. str r4, [r3, #MDMRS_OFFSET]
  214. ldr r4, [r3, #MDMRS_OFFSET]
  215. /*
  216. * 11) Enable APD
  217. */
  218. ldr r4, [r3, #MDREFR_OFFSET]
  219. and r7, r7, #MDREFR_APD
  220. orr r4, r4, r7
  221. str r4, [r3, #MDREFR_OFFSET]
  222. ldr r4, [r3, #MDREFR_OFFSET]
  223. .endm
  224. /*
  225. * This macro tests if the CPU woke up from sleep and eventually resumes
  226. *
  227. * Clobbered regs: r4, r5
  228. */
  229. .macro pxa_wakeup
  230. ldr r4, =RCSR
  231. ldr r5, [r4]
  232. and r5, r5, #(RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR)
  233. str r5, [r4]
  234. teq r5, #RCSR_SMR
  235. bne pxa_wakeup_exit
  236. ldr r4, =PSSR
  237. mov r5, #PSSR_PH
  238. str r5, [r4]
  239. ldr r4, =PSPR
  240. ldr pc, [r4]
  241. pxa_wakeup_exit:
  242. .endm
  243. /*
  244. * This macro disables all interupts on PXA2xx/PXA3xx CPU
  245. *
  246. * Clobbered regs: r4, r5
  247. */
  248. .macro pxa_intr_setup
  249. write32 ICLR, 0
  250. write32 ICMR, 0
  251. #if defined(CONFIG_PXA27X) || defined(CONFIG_CPU_MONAHANS)
  252. write32 ICLR2, 0
  253. write32 ICMR2, 0
  254. #endif
  255. .endm
  256. /*
  257. * This macro configures clock on PXA2xx/PXA3xx CPU
  258. *
  259. * Clobbered regs: r4, r5
  260. */
  261. .macro pxa_clock_setup
  262. /* Disable the peripheral clocks, and set the core clock frequency */
  263. /* Turn Off ALL on-chip peripheral clocks for re-configuration */
  264. write32 CKEN, CONFIG_SYS_CKEN
  265. /* Write CCCR */
  266. write32 CCCR, CONFIG_SYS_CCCR
  267. #ifdef CONFIG_RTC
  268. /* enable the 32Khz oscillator for RTC and PowerManager */
  269. write32 OSCC, #OSCC_OON
  270. ldr r4, =OSCC
  271. /* Spin here until OSCC.OOK get set, meaning the PLL has settled. */
  272. 2:
  273. ldr r5, [r4]
  274. ands r5, r5, #1
  275. beq 2b
  276. #endif
  277. .endm
  278. #endif /* __ASSEMBLY__ */
  279. #endif /* __ASM_ARCH_PXA_MACRO_H__ */