cpu_init.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * (C) Copyright 2000-2007
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <watchdog.h>
  25. #include <ppc4xx_enet.h>
  26. #include <asm/processor.h>
  27. #include <asm/gpio.h>
  28. #include <ppc4xx.h>
  29. #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
  30. DECLARE_GLOBAL_DATA_PTR;
  31. #endif
  32. #ifdef CFG_INIT_DCACHE_CS
  33. # if (CFG_INIT_DCACHE_CS == 0)
  34. # define PBxAP pb0ap
  35. # define PBxCR pb0cr
  36. # if (defined(CFG_EBC_PB0AP) && defined(CFG_EBC_PB0CR))
  37. # define PBxAP_VAL CFG_EBC_PB0AP
  38. # define PBxCR_VAL CFG_EBC_PB0CR
  39. # endif
  40. # endif
  41. # if (CFG_INIT_DCACHE_CS == 1)
  42. # define PBxAP pb1ap
  43. # define PBxCR pb1cr
  44. # if (defined(CFG_EBC_PB1AP) && defined(CFG_EBC_PB1CR))
  45. # define PBxAP_VAL CFG_EBC_PB1AP
  46. # define PBxCR_VAL CFG_EBC_PB1CR
  47. # endif
  48. # endif
  49. # if (CFG_INIT_DCACHE_CS == 2)
  50. # define PBxAP pb2ap
  51. # define PBxCR pb2cr
  52. # if (defined(CFG_EBC_PB2AP) && defined(CFG_EBC_PB2CR))
  53. # define PBxAP_VAL CFG_EBC_PB2AP
  54. # define PBxCR_VAL CFG_EBC_PB2CR
  55. # endif
  56. # endif
  57. # if (CFG_INIT_DCACHE_CS == 3)
  58. # define PBxAP pb3ap
  59. # define PBxCR pb3cr
  60. # if (defined(CFG_EBC_PB3AP) && defined(CFG_EBC_PB3CR))
  61. # define PBxAP_VAL CFG_EBC_PB3AP
  62. # define PBxCR_VAL CFG_EBC_PB3CR
  63. # endif
  64. # endif
  65. # if (CFG_INIT_DCACHE_CS == 4)
  66. # define PBxAP pb4ap
  67. # define PBxCR pb4cr
  68. # if (defined(CFG_EBC_PB4AP) && defined(CFG_EBC_PB4CR))
  69. # define PBxAP_VAL CFG_EBC_PB4AP
  70. # define PBxCR_VAL CFG_EBC_PB4CR
  71. # endif
  72. # endif
  73. # if (CFG_INIT_DCACHE_CS == 5)
  74. # define PBxAP pb5ap
  75. # define PBxCR pb5cr
  76. # if (defined(CFG_EBC_PB5AP) && defined(CFG_EBC_PB5CR))
  77. # define PBxAP_VAL CFG_EBC_PB5AP
  78. # define PBxCR_VAL CFG_EBC_PB5CR
  79. # endif
  80. # endif
  81. # if (CFG_INIT_DCACHE_CS == 6)
  82. # define PBxAP pb6ap
  83. # define PBxCR pb6cr
  84. # if (defined(CFG_EBC_PB6AP) && defined(CFG_EBC_PB6CR))
  85. # define PBxAP_VAL CFG_EBC_PB6AP
  86. # define PBxCR_VAL CFG_EBC_PB6CR
  87. # endif
  88. # endif
  89. # if (CFG_INIT_DCACHE_CS == 7)
  90. # define PBxAP pb7ap
  91. # define PBxCR pb7cr
  92. # if (defined(CFG_EBC_PB7AP) && defined(CFG_EBC_PB7CR))
  93. # define PBxAP_VAL CFG_EBC_PB7AP
  94. # define PBxCR_VAL CFG_EBC_PB7CR
  95. # endif
  96. # endif
  97. #endif /* CFG_INIT_DCACHE_CS */
  98. /*
  99. * Breath some life into the CPU...
  100. *
  101. * Set up the memory map,
  102. * initialize a bunch of registers
  103. */
  104. void
  105. cpu_init_f (void)
  106. {
  107. #if defined(CONFIG_WATCHDOG)
  108. unsigned long val;
  109. #endif
  110. #if (defined(CONFIG_405EP) || defined (CONFIG_405EX)) && !defined(CFG_4xx_GPIO_TABLE)
  111. /*
  112. * GPIO0 setup (select GPIO or alternate function)
  113. */
  114. #if defined(CFG_GPIO0_OR)
  115. out32(GPIO0_OR, CFG_GPIO0_OR); /* set initial state of output pins */
  116. #endif
  117. #if defined(CFG_GPIO0_ODR)
  118. out32(GPIO0_ODR, CFG_GPIO0_ODR); /* open-drain select */
  119. #endif
  120. out32(GPIO0_OSRH, CFG_GPIO0_OSRH); /* output select */
  121. out32(GPIO0_OSRL, CFG_GPIO0_OSRL);
  122. out32(GPIO0_ISR1H, CFG_GPIO0_ISR1H); /* input select */
  123. out32(GPIO0_ISR1L, CFG_GPIO0_ISR1L);
  124. out32(GPIO0_TSRH, CFG_GPIO0_TSRH); /* three-state select */
  125. out32(GPIO0_TSRL, CFG_GPIO0_TSRL);
  126. #if defined(CFG_GPIO0_ISR2H)
  127. out32(GPIO0_ISR2H, CFG_GPIO0_ISR2H);
  128. out32(GPIO0_ISR2L, CFG_GPIO0_ISR2L);
  129. #endif
  130. #if defined (CFG_GPIO0_TCR)
  131. out32(GPIO0_TCR, CFG_GPIO0_TCR); /* enable output driver for outputs */
  132. #endif
  133. #if defined (CONFIG_405EP)
  134. /*
  135. * Set EMAC noise filter bits
  136. */
  137. mtdcr(cpc0_epctl, CPC0_EPRCSR_E0NFE | CPC0_EPRCSR_E1NFE);
  138. /*
  139. * Enable the internal PCI arbiter
  140. */
  141. mtdcr(cpc0_pci, mfdcr(cpc0_pci) | CPC0_PCI_HOST_CFG_EN | CPC0_PCI_ARBIT_EN);
  142. #endif /* CONFIG_405EP */
  143. #endif /* CONFIG_405EP */
  144. #if defined(CFG_4xx_GPIO_TABLE)
  145. gpio_set_chip_configuration();
  146. #endif /* CFG_4xx_GPIO_TABLE */
  147. /*
  148. * External Bus Controller (EBC) Setup
  149. */
  150. #if (defined(CFG_EBC_PB0AP) && defined(CFG_EBC_PB0CR))
  151. #if (defined(CONFIG_405GP) || defined(CONFIG_405CR) || \
  152. defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \
  153. defined(CONFIG_405EX) || defined(CONFIG_405))
  154. /*
  155. * Move the next instructions into icache, since these modify the flash
  156. * we are running from!
  157. */
  158. asm volatile(" bl 0f" ::: "lr");
  159. asm volatile("0: mflr 3" ::: "r3");
  160. asm volatile(" addi 4, 0, 14" ::: "r4");
  161. asm volatile(" mtctr 4" ::: "ctr");
  162. asm volatile("1: icbt 0, 3");
  163. asm volatile(" addi 3, 3, 32" ::: "r3");
  164. asm volatile(" bdnz 1b" ::: "ctr", "cr0");
  165. asm volatile(" addis 3, 0, 0x0" ::: "r3");
  166. asm volatile(" ori 3, 3, 0xA000" ::: "r3");
  167. asm volatile(" mtctr 3" ::: "ctr");
  168. asm volatile("2: bdnz 2b" ::: "ctr", "cr0");
  169. #endif
  170. mtebc(pb0ap, CFG_EBC_PB0AP);
  171. mtebc(pb0cr, CFG_EBC_PB0CR);
  172. #endif
  173. #if (defined(CFG_EBC_PB1AP) && defined(CFG_EBC_PB1CR) && !(CFG_INIT_DCACHE_CS == 1))
  174. mtebc(pb1ap, CFG_EBC_PB1AP);
  175. mtebc(pb1cr, CFG_EBC_PB1CR);
  176. #endif
  177. #if (defined(CFG_EBC_PB2AP) && defined(CFG_EBC_PB2CR) && !(CFG_INIT_DCACHE_CS == 2))
  178. mtebc(pb2ap, CFG_EBC_PB2AP);
  179. mtebc(pb2cr, CFG_EBC_PB2CR);
  180. #endif
  181. #if (defined(CFG_EBC_PB3AP) && defined(CFG_EBC_PB3CR) && !(CFG_INIT_DCACHE_CS == 3))
  182. mtebc(pb3ap, CFG_EBC_PB3AP);
  183. mtebc(pb3cr, CFG_EBC_PB3CR);
  184. #endif
  185. #if (defined(CFG_EBC_PB4AP) && defined(CFG_EBC_PB4CR) && !(CFG_INIT_DCACHE_CS == 4))
  186. mtebc(pb4ap, CFG_EBC_PB4AP);
  187. mtebc(pb4cr, CFG_EBC_PB4CR);
  188. #endif
  189. #if (defined(CFG_EBC_PB5AP) && defined(CFG_EBC_PB5CR) && !(CFG_INIT_DCACHE_CS == 5))
  190. mtebc(pb5ap, CFG_EBC_PB5AP);
  191. mtebc(pb5cr, CFG_EBC_PB5CR);
  192. #endif
  193. #if (defined(CFG_EBC_PB6AP) && defined(CFG_EBC_PB6CR) && !(CFG_INIT_DCACHE_CS == 6))
  194. mtebc(pb6ap, CFG_EBC_PB6AP);
  195. mtebc(pb6cr, CFG_EBC_PB6CR);
  196. #endif
  197. #if (defined(CFG_EBC_PB7AP) && defined(CFG_EBC_PB7CR) && !(CFG_INIT_DCACHE_CS == 7))
  198. mtebc(pb7ap, CFG_EBC_PB7AP);
  199. mtebc(pb7cr, CFG_EBC_PB7CR);
  200. #endif
  201. #if defined (CFG_EBC_CFG)
  202. mtebc(EBC0_CFG, CFG_EBC_CFG);
  203. #endif
  204. #if defined(CONFIG_WATCHDOG)
  205. val = mfspr(tcr);
  206. #if defined(CONFIG_440EP) || defined(CONFIG_440GR)
  207. val |= 0xb8000000; /* generate system reset after 1.34 seconds */
  208. #elif defined(CONFIG_440EPX)
  209. val |= 0xb0000000; /* generate system reset after 1.34 seconds */
  210. #else
  211. val |= 0xf0000000; /* generate system reset after 2.684 seconds */
  212. #endif
  213. #if defined(CFG_4xx_RESET_TYPE)
  214. val &= ~0x30000000; /* clear WRC bits */
  215. val |= CFG_4xx_RESET_TYPE << 28; /* set board specific WRC type */
  216. #endif
  217. mtspr(tcr, val);
  218. val = mfspr(tsr);
  219. val |= 0x80000000; /* enable watchdog timer */
  220. mtspr(tsr, val);
  221. reset_4xx_watchdog();
  222. #endif /* CONFIG_WATCHDOG */
  223. }
  224. /*
  225. * initialize higher level parts of CPU like time base and timers
  226. */
  227. int cpu_init_r (void)
  228. {
  229. #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
  230. bd_t *bd = gd->bd;
  231. unsigned long reg;
  232. #if defined(CONFIG_405GP)
  233. uint pvr = get_pvr();
  234. #endif
  235. #ifdef CFG_INIT_DCACHE_CS
  236. /*
  237. * Flush and invalidate dcache, then disable CS for temporary stack.
  238. * Afterwards, this CS can be used for other purposes
  239. */
  240. dcache_disable(); /* flush and invalidate dcache */
  241. mtebc(PBxAP, 0);
  242. mtebc(PBxCR, 0); /* disable CS for temporary stack */
  243. #if (defined(PBxAP_VAL) && defined(PBxCR_VAL))
  244. /*
  245. * Write new value into CS register
  246. */
  247. mtebc(PBxAP, PBxAP_VAL);
  248. mtebc(PBxCR, PBxCR_VAL);
  249. #endif
  250. #endif /* CFG_INIT_DCACHE_CS */
  251. /*
  252. * Write Ethernetaddress into on-chip register
  253. */
  254. reg = 0x00000000;
  255. reg |= bd->bi_enetaddr[0]; /* set high address */
  256. reg = reg << 8;
  257. reg |= bd->bi_enetaddr[1];
  258. out32 (EMAC_IAH, reg);
  259. reg = 0x00000000;
  260. reg |= bd->bi_enetaddr[2]; /* set low address */
  261. reg = reg << 8;
  262. reg |= bd->bi_enetaddr[3];
  263. reg = reg << 8;
  264. reg |= bd->bi_enetaddr[4];
  265. reg = reg << 8;
  266. reg |= bd->bi_enetaddr[5];
  267. out32 (EMAC_IAL, reg);
  268. #if defined(CONFIG_405GP)
  269. /*
  270. * Set edge conditioning circuitry on PPC405GPr
  271. * for compatibility to existing PPC405GP designs.
  272. */
  273. if ((pvr & 0xfffffff0) == (PVR_405GPR_RB & 0xfffffff0)) {
  274. mtdcr(ecr, 0x60606000);
  275. }
  276. #endif /* defined(CONFIG_405GP) */
  277. #endif /* defined(CONFIG_405GP) || defined(CONFIG_405EP) */
  278. return (0);
  279. }