pxa2xx.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. * (C) Copyright 2002
  3. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  4. * Marius Groeger <mgroeger@sysgo.de>
  5. *
  6. * (C) Copyright 2002
  7. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  8. * Alex Zuepke <azu@sysgo.de>
  9. *
  10. * See file CREDITS for list of people who contributed to this
  11. * project.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #include <asm/io.h>
  29. #include <asm/system.h>
  30. #include <command.h>
  31. #include <common.h>
  32. #include <asm/arch/pxa-regs.h>
  33. /* Flush I/D-cache */
  34. static void cache_flush(void)
  35. {
  36. unsigned long i = 0;
  37. asm ("mcr p15, 0, %0, c7, c5, 0" : : "r" (i));
  38. }
  39. int cleanup_before_linux(void)
  40. {
  41. /*
  42. * This function is called just before we call Linux. It prepares
  43. * the processor for Linux by just disabling everything that can
  44. * disturb booting Linux.
  45. */
  46. disable_interrupts();
  47. icache_disable();
  48. dcache_disable();
  49. cache_flush();
  50. return 0;
  51. }
  52. void pxa_wait_ticks(int ticks)
  53. {
  54. writel(0, OSCR);
  55. while (readl(OSCR) < ticks)
  56. asm volatile("" : : : "memory");
  57. }
  58. inline void writelrb(uint32_t val, uint32_t addr)
  59. {
  60. writel(val, addr);
  61. asm volatile("" : : : "memory");
  62. readl(addr);
  63. asm volatile("" : : : "memory");
  64. }
  65. void pxa2xx_dram_init(void)
  66. {
  67. uint32_t tmp;
  68. int i;
  69. /*
  70. * 1) Initialize Asynchronous static memory controller
  71. */
  72. writelrb(CONFIG_SYS_MSC0_VAL, MSC0);
  73. writelrb(CONFIG_SYS_MSC1_VAL, MSC1);
  74. writelrb(CONFIG_SYS_MSC2_VAL, MSC2);
  75. /*
  76. * 2) Initialize Card Interface
  77. */
  78. /* MECR: Memory Expansion Card Register */
  79. writelrb(CONFIG_SYS_MECR_VAL, MECR);
  80. /* MCMEM0: Card Interface slot 0 timing */
  81. writelrb(CONFIG_SYS_MCMEM0_VAL, MCMEM0);
  82. /* MCMEM1: Card Interface slot 1 timing */
  83. writelrb(CONFIG_SYS_MCMEM1_VAL, MCMEM1);
  84. /* MCATT0: Card Interface Attribute Space Timing, slot 0 */
  85. writelrb(CONFIG_SYS_MCATT0_VAL, MCATT0);
  86. /* MCATT1: Card Interface Attribute Space Timing, slot 1 */
  87. writelrb(CONFIG_SYS_MCATT1_VAL, MCATT1);
  88. /* MCIO0: Card Interface I/O Space Timing, slot 0 */
  89. writelrb(CONFIG_SYS_MCIO0_VAL, MCIO0);
  90. /* MCIO1: Card Interface I/O Space Timing, slot 1 */
  91. writelrb(CONFIG_SYS_MCIO1_VAL, MCIO1);
  92. /*
  93. * 3) Configure Fly-By DMA register
  94. */
  95. writelrb(CONFIG_SYS_FLYCNFG_VAL, FLYCNFG);
  96. /*
  97. * 4) Initialize Timing for Sync Memory (SDCLK0)
  98. */
  99. /*
  100. * Before accessing MDREFR we need a valid DRI field, so we set
  101. * this to power on defaults + DRI field.
  102. */
  103. /* Read current MDREFR config and zero out DRI */
  104. tmp = readl(MDREFR) & ~0xfff;
  105. /* Add user-specified DRI */
  106. tmp |= CONFIG_SYS_MDREFR_VAL & 0xfff;
  107. /* Configure important bits */
  108. tmp |= MDREFR_K0RUN | MDREFR_SLFRSH;
  109. tmp &= ~(MDREFR_APD | MDREFR_E1PIN);
  110. /* Write MDREFR back */
  111. writelrb(tmp, MDREFR);
  112. /*
  113. * 5) Initialize Synchronous Static Memory (Flash/Peripherals)
  114. */
  115. /* Initialize SXCNFG register. Assert the enable bits.
  116. *
  117. * Write SXMRS to cause an MRS command to all enabled banks of
  118. * synchronous static memory. Note that SXLCR need not be written
  119. * at this time.
  120. */
  121. writelrb(CONFIG_SYS_SXCNFG_VAL, SXCNFG);
  122. /*
  123. * 6) Initialize SDRAM
  124. */
  125. writelrb(CONFIG_SYS_MDREFR_VAL & ~MDREFR_SLFRSH, MDREFR);
  126. writelrb(CONFIG_SYS_MDREFR_VAL | MDREFR_E1PIN, MDREFR);
  127. /*
  128. * 7) Write MDCNFG with MDCNFG:DEx deasserted (set to 0), to configure
  129. * but not enable each SDRAM partition pair.
  130. */
  131. writelrb(CONFIG_SYS_MDCNFG_VAL &
  132. ~(MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3), MDCNFG);
  133. /* Wait for the clock to the SDRAMs to stabilize, 100..200 usec. */
  134. pxa_wait_ticks(0x300);
  135. /*
  136. * 8) Trigger a number (usually 8) refresh cycles by attempting
  137. * non-burst read or write accesses to disabled SDRAM, as commonly
  138. * specified in the power up sequence documented in SDRAM data
  139. * sheets. The address(es) used for this purpose must not be
  140. * cacheable.
  141. */
  142. for (i = 9; i >= 0; i--) {
  143. writel(i, 0xa0000000);
  144. asm volatile("" : : : "memory");
  145. }
  146. /*
  147. * 9) Write MDCNFG with enable bits asserted (MDCNFG:DEx set to 1).
  148. */
  149. tmp = CONFIG_SYS_MDCNFG_VAL &
  150. (MDCNFG_DE0 | MDCNFG_DE1 | MDCNFG_DE2 | MDCNFG_DE3);
  151. tmp |= readl(MDCNFG);
  152. writelrb(tmp, MDCNFG);
  153. /*
  154. * 10) Write MDMRS.
  155. */
  156. writelrb(CONFIG_SYS_MDMRS_VAL, MDMRS);
  157. /*
  158. * 11) Enable APD
  159. */
  160. if (CONFIG_SYS_MDREFR_VAL & MDREFR_APD) {
  161. tmp = readl(MDREFR);
  162. tmp |= MDREFR_APD;
  163. writelrb(tmp, MDREFR);
  164. }
  165. }
  166. void pxa_gpio_setup(void)
  167. {
  168. writel(CONFIG_SYS_GPSR0_VAL, GPSR0);
  169. writel(CONFIG_SYS_GPSR1_VAL, GPSR1);
  170. writel(CONFIG_SYS_GPSR2_VAL, GPSR2);
  171. #if defined(CONFIG_CPU_PXA27X)
  172. writel(CONFIG_SYS_GPSR3_VAL, GPSR3);
  173. #endif
  174. writel(CONFIG_SYS_GPCR0_VAL, GPCR0);
  175. writel(CONFIG_SYS_GPCR1_VAL, GPCR1);
  176. writel(CONFIG_SYS_GPCR2_VAL, GPCR2);
  177. #if defined(CONFIG_CPU_PXA27X)
  178. writel(CONFIG_SYS_GPCR3_VAL, GPCR3);
  179. #endif
  180. writel(CONFIG_SYS_GPDR0_VAL, GPDR0);
  181. writel(CONFIG_SYS_GPDR1_VAL, GPDR1);
  182. writel(CONFIG_SYS_GPDR2_VAL, GPDR2);
  183. #if defined(CONFIG_CPU_PXA27X)
  184. writel(CONFIG_SYS_GPDR3_VAL, GPDR3);
  185. #endif
  186. writel(CONFIG_SYS_GAFR0_L_VAL, GAFR0_L);
  187. writel(CONFIG_SYS_GAFR0_U_VAL, GAFR0_U);
  188. writel(CONFIG_SYS_GAFR1_L_VAL, GAFR1_L);
  189. writel(CONFIG_SYS_GAFR1_U_VAL, GAFR1_U);
  190. writel(CONFIG_SYS_GAFR2_L_VAL, GAFR2_L);
  191. writel(CONFIG_SYS_GAFR2_U_VAL, GAFR2_U);
  192. #if defined(CONFIG_CPU_PXA27X)
  193. writel(CONFIG_SYS_GAFR3_L_VAL, GAFR3_L);
  194. writel(CONFIG_SYS_GAFR3_U_VAL, GAFR3_U);
  195. #endif
  196. writel(CONFIG_SYS_PSSR_VAL, PSSR);
  197. }
  198. void pxa_interrupt_setup(void)
  199. {
  200. writel(0, ICLR);
  201. writel(0, ICMR);
  202. #if defined(CONFIG_CPU_PXA27X)
  203. writel(0, ICLR2);
  204. writel(0, ICMR2);
  205. #endif
  206. }
  207. void pxa_clock_setup(void)
  208. {
  209. writel(CONFIG_SYS_CKEN, CKEN);
  210. writel(CONFIG_SYS_CCCR, CCCR);
  211. asm volatile("mcr p14, 0, %0, c6, c0, 0" : : "r"(2));
  212. /* enable the 32Khz oscillator for RTC and PowerManager */
  213. writel(OSCC_OON, OSCC);
  214. while (!(readl(OSCC) & OSCC_OOK))
  215. asm volatile("" : : : "memory");
  216. }
  217. void pxa_wakeup(void)
  218. {
  219. uint32_t rcsr;
  220. rcsr = readl(RCSR);
  221. writel(rcsr & (RCSR_GPR | RCSR_SMR | RCSR_WDR | RCSR_HWR), RCSR);
  222. /* Wakeup */
  223. if (rcsr & RCSR_SMR) {
  224. writel(PSSR_PH, PSSR);
  225. pxa2xx_dram_init();
  226. icache_disable();
  227. dcache_disable();
  228. asm volatile("mov pc, %0" : : "r"(readl(PSPR)));
  229. }
  230. }
  231. int arch_cpu_init(void)
  232. {
  233. pxa_gpio_setup();
  234. pxa_wakeup();
  235. pxa_interrupt_setup();
  236. pxa_clock_setup();
  237. return 0;
  238. }
  239. void i2c_clk_enable(void)
  240. {
  241. /* Set the global I2C clock on */
  242. writel(readl(CKEN) | CKEN14_I2C, CKEN);
  243. }
  244. void reset_cpu(ulong ignored) __attribute__((noreturn));
  245. void reset_cpu(ulong ignored)
  246. {
  247. uint32_t tmp;
  248. setbits_le32(OWER, OWER_WME);
  249. tmp = readl(OSCR);
  250. tmp += 0x1000;
  251. writel(tmp, OSMR3);
  252. for (;;)
  253. ;
  254. }