cpu_init.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. /*
  2. * (C) Copyright 2000-2006
  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 <ppc4xx.h>
  28. #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
  29. DECLARE_GLOBAL_DATA_PTR;
  30. #endif
  31. #ifdef CFG_INIT_DCACHE_CS
  32. # if (CFG_INIT_DCACHE_CS == 0)
  33. # define PBxAP pb0ap
  34. # define PBxCR pb0cr
  35. # if (defined(CFG_EBC_PB0AP) && defined(CFG_EBC_PB0CR))
  36. # define PBxAP_VAL CFG_EBC_PB0AP
  37. # define PBxCR_VAL CFG_EBC_PB0CR
  38. # endif
  39. # endif
  40. # if (CFG_INIT_DCACHE_CS == 1)
  41. # define PBxAP pb1ap
  42. # define PBxCR pb1cr
  43. # if (defined(CFG_EBC_PB1AP) && defined(CFG_EBC_PB1CR))
  44. # define PBxAP_VAL CFG_EBC_PB1AP
  45. # define PBxCR_VAL CFG_EBC_PB1CR
  46. # endif
  47. # endif
  48. # if (CFG_INIT_DCACHE_CS == 2)
  49. # define PBxAP pb2ap
  50. # define PBxCR pb2cr
  51. # if (defined(CFG_EBC_PB2AP) && defined(CFG_EBC_PB2CR))
  52. # define PBxAP_VAL CFG_EBC_PB2AP
  53. # define PBxCR_VAL CFG_EBC_PB2CR
  54. # endif
  55. # endif
  56. # if (CFG_INIT_DCACHE_CS == 3)
  57. # define PBxAP pb3ap
  58. # define PBxCR pb3cr
  59. # if (defined(CFG_EBC_PB3AP) && defined(CFG_EBC_PB3CR))
  60. # define PBxAP_VAL CFG_EBC_PB3AP
  61. # define PBxCR_VAL CFG_EBC_PB3CR
  62. # endif
  63. # endif
  64. # if (CFG_INIT_DCACHE_CS == 4)
  65. # define PBxAP pb4ap
  66. # define PBxCR pb4cr
  67. # if (defined(CFG_EBC_PB4AP) && defined(CFG_EBC_PB4CR))
  68. # define PBxAP_VAL CFG_EBC_PB4AP
  69. # define PBxCR_VAL CFG_EBC_PB4CR
  70. # endif
  71. # endif
  72. # if (CFG_INIT_DCACHE_CS == 5)
  73. # define PBxAP pb5ap
  74. # define PBxCR pb5cr
  75. # if (defined(CFG_EBC_PB5AP) && defined(CFG_EBC_PB5CR))
  76. # define PBxAP_VAL CFG_EBC_PB5AP
  77. # define PBxCR_VAL CFG_EBC_PB5CR
  78. # endif
  79. # endif
  80. # if (CFG_INIT_DCACHE_CS == 6)
  81. # define PBxAP pb6ap
  82. # define PBxCR pb6cr
  83. # if (defined(CFG_EBC_PB6AP) && defined(CFG_EBC_PB6CR))
  84. # define PBxAP_VAL CFG_EBC_PB6AP
  85. # define PBxCR_VAL CFG_EBC_PB6CR
  86. # endif
  87. # endif
  88. # if (CFG_INIT_DCACHE_CS == 7)
  89. # define PBxAP pb7ap
  90. # define PBxCR pb7cr
  91. # if (defined(CFG_EBC_PB7AP) && defined(CFG_EBC_PB7CR))
  92. # define PBxAP_VAL CFG_EBC_PB7AP
  93. # define PBxCR_VAL CFG_EBC_PB7CR
  94. # endif
  95. # endif
  96. #endif /* CFG_INIT_DCACHE_CS */
  97. #if defined(CFG_440_GPIO_TABLE)
  98. gpio_param_s gpio_tab[GPIO_GROUP_MAX][GPIO_MAX] = CFG_440_GPIO_TABLE;
  99. void set_chip_gpio_configuration(gpio_param_s (*gpio_tab)[GPIO_GROUP_MAX][GPIO_MAX])
  100. {
  101. unsigned char i=0, j=0, reg_offset = 0, gpio_core;
  102. unsigned long gpio_reg, gpio_core_add;
  103. for (gpio_core=0; gpio_core<GPIO_GROUP_MAX; gpio_core++) {
  104. j = 0;
  105. reg_offset = 0;
  106. /* GPIO config of the GPIOs 0 to 31 */
  107. for (i=0; i<GPIO_MAX; i++, j++) {
  108. if (i == GPIO_MAX/2) {
  109. reg_offset = 4;
  110. j = i-16;
  111. }
  112. gpio_core_add = (*gpio_tab)[gpio_core][i].add;
  113. if (((*gpio_tab)[gpio_core][i].in_out == GPIO_IN) ||
  114. ((*gpio_tab)[gpio_core][i].in_out == GPIO_BI)) {
  115. switch ((*gpio_tab)[gpio_core][i].alt_nb) {
  116. case GPIO_SEL:
  117. break;
  118. case GPIO_ALT1:
  119. gpio_reg = in32(GPIO_IS1(gpio_core_add+reg_offset))
  120. & ~(GPIO_MASK >> (j*2));
  121. gpio_reg = gpio_reg | (GPIO_IN_SEL >> (j*2));
  122. out32(GPIO_IS1(gpio_core_add+reg_offset), gpio_reg);
  123. break;
  124. case GPIO_ALT2:
  125. gpio_reg = in32(GPIO_IS2(gpio_core_add+reg_offset))
  126. & ~(GPIO_MASK >> (j*2));
  127. gpio_reg = gpio_reg | (GPIO_IN_SEL >> (j*2));
  128. out32(GPIO_IS2(gpio_core_add+reg_offset), gpio_reg);
  129. break;
  130. case GPIO_ALT3:
  131. gpio_reg = in32(GPIO_IS3(gpio_core_add+reg_offset))
  132. & ~(GPIO_MASK >> (j*2));
  133. gpio_reg = gpio_reg | (GPIO_IN_SEL >> (j*2));
  134. out32(GPIO_IS3(gpio_core_add+reg_offset), gpio_reg);
  135. break;
  136. }
  137. }
  138. if (((*gpio_tab)[gpio_core][i].in_out == GPIO_OUT) ||
  139. ((*gpio_tab)[gpio_core][i].in_out == GPIO_BI)) {
  140. switch ((*gpio_tab)[gpio_core][i].alt_nb) {
  141. case GPIO_SEL:
  142. if (gpio_core == GPIO0) {
  143. gpio_reg = in32(GPIO0_TCR) | (0x80000000 >> (j));
  144. out32(GPIO0_TCR, gpio_reg);
  145. }
  146. if (gpio_core == GPIO1) {
  147. gpio_reg = in32(GPIO1_TCR) | (0x80000000 >> (j));
  148. out32(GPIO1_TCR, gpio_reg);
  149. }
  150. gpio_reg = in32(GPIO_OS(gpio_core_add+reg_offset))
  151. & ~(GPIO_MASK >> (j*2));
  152. out32(GPIO_OS(gpio_core_add+reg_offset), gpio_reg);
  153. gpio_reg = in32(GPIO_TS(gpio_core_add+reg_offset))
  154. & ~(GPIO_MASK >> (j*2));
  155. out32(GPIO_TS(gpio_core_add+reg_offset), gpio_reg);
  156. break;
  157. case GPIO_ALT1:
  158. gpio_reg = in32(GPIO_OS(gpio_core_add+reg_offset))
  159. & ~(GPIO_MASK >> (j*2));
  160. gpio_reg = gpio_reg | (GPIO_ALT1_SEL >> (j*2));
  161. out32(GPIO_OS(gpio_core_add+reg_offset), gpio_reg);
  162. gpio_reg = in32(GPIO_TS(gpio_core_add+reg_offset))
  163. & ~(GPIO_MASK >> (j*2));
  164. gpio_reg = gpio_reg | (GPIO_ALT1_SEL >> (j*2));
  165. out32(GPIO_TS(gpio_core_add+reg_offset), gpio_reg);
  166. break;
  167. case GPIO_ALT2:
  168. gpio_reg = in32(GPIO_OS(gpio_core_add+reg_offset))
  169. & ~(GPIO_MASK >> (j*2));
  170. gpio_reg = gpio_reg | (GPIO_ALT2_SEL >> (j*2));
  171. out32(GPIO_OS(gpio_core_add+reg_offset), gpio_reg);
  172. gpio_reg = in32(GPIO_TS(gpio_core_add+reg_offset))
  173. & ~(GPIO_MASK >> (j*2));
  174. gpio_reg = gpio_reg | (GPIO_ALT2_SEL >> (j*2));
  175. out32(GPIO_TS(gpio_core_add+reg_offset), gpio_reg);
  176. break;
  177. case GPIO_ALT3:
  178. gpio_reg = in32(GPIO_OS(gpio_core_add+reg_offset))
  179. & ~(GPIO_MASK >> (j*2));
  180. gpio_reg = gpio_reg | (GPIO_ALT3_SEL >> (j*2));
  181. out32(GPIO_OS(gpio_core_add+reg_offset), gpio_reg);
  182. gpio_reg = in32(GPIO_TS(gpio_core_add+reg_offset))
  183. & ~(GPIO_MASK >> (j*2));
  184. gpio_reg = gpio_reg | (GPIO_ALT3_SEL >> (j*2));
  185. out32(GPIO_TS(gpio_core_add+reg_offset), gpio_reg);
  186. break;
  187. }
  188. }
  189. }
  190. }
  191. }
  192. #endif /* CFG_440_GPIO_TABLE */
  193. /*
  194. * Breath some life into the CPU...
  195. *
  196. * Set up the memory map,
  197. * initialize a bunch of registers
  198. */
  199. void
  200. cpu_init_f (void)
  201. {
  202. #if defined(CONFIG_WATCHDOG)
  203. unsigned long val;
  204. #endif
  205. #if defined(CONFIG_405EP)
  206. /*
  207. * GPIO0 setup (select GPIO or alternate function)
  208. */
  209. #if defined(CFG_GPIO0_OR)
  210. out32(GPIO0_OR, CFG_GPIO0_OR); /* set initial state of output pins */
  211. #endif
  212. #if defined(CFG_GPIO0_ODR)
  213. out32(GPIO0_ODR, CFG_GPIO0_ODR); /* open-drain select */
  214. #endif
  215. out32(GPIO0_OSRH, CFG_GPIO0_OSRH); /* output select */
  216. out32(GPIO0_OSRL, CFG_GPIO0_OSRL);
  217. out32(GPIO0_ISR1H, CFG_GPIO0_ISR1H); /* input select */
  218. out32(GPIO0_ISR1L, CFG_GPIO0_ISR1L);
  219. out32(GPIO0_TSRH, CFG_GPIO0_TSRH); /* three-state select */
  220. out32(GPIO0_TSRL, CFG_GPIO0_TSRL);
  221. out32(GPIO0_TCR, CFG_GPIO0_TCR); /* enable output driver for outputs */
  222. /*
  223. * Set EMAC noise filter bits
  224. */
  225. mtdcr(cpc0_epctl, CPC0_EPRCSR_E0NFE | CPC0_EPRCSR_E1NFE);
  226. #endif /* CONFIG_405EP */
  227. #if defined(CFG_440_GPIO_TABLE)
  228. set_chip_gpio_configuration(&gpio_tab);
  229. #endif /* CFG_440_GPIO_TABLE */
  230. /*
  231. * External Bus Controller (EBC) Setup
  232. */
  233. #if (defined(CFG_EBC_PB0AP) && defined(CFG_EBC_PB0CR))
  234. #if (defined(CONFIG_405GP) || defined(CONFIG_405CR) || \
  235. defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \
  236. defined(CONFIG_405))
  237. /*
  238. * Move the next instructions into icache, since these modify the flash
  239. * we are running from!
  240. */
  241. asm volatile(" bl 0f" ::: "lr");
  242. asm volatile("0: mflr 3" ::: "r3");
  243. asm volatile(" addi 4, 0, 14" ::: "r4");
  244. asm volatile(" mtctr 4" ::: "ctr");
  245. asm volatile("1: icbt 0, 3");
  246. asm volatile(" addi 3, 3, 32" ::: "r3");
  247. asm volatile(" bdnz 1b" ::: "ctr", "cr0");
  248. asm volatile(" addis 3, 0, 0x0" ::: "r3");
  249. asm volatile(" ori 3, 3, 0xA000" ::: "r3");
  250. asm volatile(" mtctr 3" ::: "ctr");
  251. asm volatile("2: bdnz 2b" ::: "ctr", "cr0");
  252. #endif
  253. mtebc(pb0ap, CFG_EBC_PB0AP);
  254. mtebc(pb0cr, CFG_EBC_PB0CR);
  255. #endif
  256. #if (defined(CFG_EBC_PB1AP) && defined(CFG_EBC_PB1CR) && !(CFG_INIT_DCACHE_CS == 1))
  257. mtebc(pb1ap, CFG_EBC_PB1AP);
  258. mtebc(pb1cr, CFG_EBC_PB1CR);
  259. #endif
  260. #if (defined(CFG_EBC_PB2AP) && defined(CFG_EBC_PB2CR) && !(CFG_INIT_DCACHE_CS == 2))
  261. mtebc(pb2ap, CFG_EBC_PB2AP);
  262. mtebc(pb2cr, CFG_EBC_PB2CR);
  263. #endif
  264. #if (defined(CFG_EBC_PB3AP) && defined(CFG_EBC_PB3CR) && !(CFG_INIT_DCACHE_CS == 3))
  265. mtebc(pb3ap, CFG_EBC_PB3AP);
  266. mtebc(pb3cr, CFG_EBC_PB3CR);
  267. #endif
  268. #if (defined(CFG_EBC_PB4AP) && defined(CFG_EBC_PB4CR) && !(CFG_INIT_DCACHE_CS == 4))
  269. mtebc(pb4ap, CFG_EBC_PB4AP);
  270. mtebc(pb4cr, CFG_EBC_PB4CR);
  271. #endif
  272. #if (defined(CFG_EBC_PB5AP) && defined(CFG_EBC_PB5CR) && !(CFG_INIT_DCACHE_CS == 5))
  273. mtebc(pb5ap, CFG_EBC_PB5AP);
  274. mtebc(pb5cr, CFG_EBC_PB5CR);
  275. #endif
  276. #if (defined(CFG_EBC_PB6AP) && defined(CFG_EBC_PB6CR) && !(CFG_INIT_DCACHE_CS == 6))
  277. mtebc(pb6ap, CFG_EBC_PB6AP);
  278. mtebc(pb6cr, CFG_EBC_PB6CR);
  279. #endif
  280. #if (defined(CFG_EBC_PB7AP) && defined(CFG_EBC_PB7CR) && !(CFG_INIT_DCACHE_CS == 7))
  281. mtebc(pb7ap, CFG_EBC_PB7AP);
  282. mtebc(pb7cr, CFG_EBC_PB7CR);
  283. #endif
  284. #if defined (CFG_EBC_CFG)
  285. mtebc(EBC0_CFG, CFG_EBC_CFG);
  286. #endif
  287. #if defined(CONFIG_WATCHDOG)
  288. val = mfspr(tcr);
  289. #if defined(CONFIG_440EP) || defined(CONFIG_440GR)
  290. val |= 0xb8000000; /* generate system reset after 1.34 seconds */
  291. #else
  292. val |= 0xf0000000; /* generate system reset after 2.684 seconds */
  293. #endif
  294. #if defined(CFG_4xx_RESET_TYPE)
  295. val &= ~0x30000000; /* clear WRC bits */
  296. val |= CFG_4xx_RESET_TYPE << 28; /* set board specific WRC type */
  297. #endif
  298. mtspr(tcr, val);
  299. val = mfspr(tsr);
  300. val |= 0x80000000; /* enable watchdog timer */
  301. mtspr(tsr, val);
  302. reset_4xx_watchdog();
  303. #endif /* CONFIG_WATCHDOG */
  304. }
  305. /*
  306. * initialize higher level parts of CPU like time base and timers
  307. */
  308. int cpu_init_r (void)
  309. {
  310. #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
  311. bd_t *bd = gd->bd;
  312. unsigned long reg;
  313. #if defined(CONFIG_405GP)
  314. uint pvr = get_pvr();
  315. #endif
  316. #ifdef CFG_INIT_DCACHE_CS
  317. /*
  318. * Flush and invalidate dcache, then disable CS for temporary stack.
  319. * Afterwards, this CS can be used for other purposes
  320. */
  321. dcache_disable(); /* flush and invalidate dcache */
  322. mtebc(PBxAP, 0);
  323. mtebc(PBxCR, 0); /* disable CS for temporary stack */
  324. #if (defined(PBxAP_VAL) && defined(PBxCR_VAL))
  325. /*
  326. * Write new value into CS register
  327. */
  328. mtebc(PBxAP, PBxAP_VAL);
  329. mtebc(PBxCR, PBxCR_VAL);
  330. #endif
  331. #endif /* CFG_INIT_DCACHE_CS */
  332. /*
  333. * Write Ethernetaddress into on-chip register
  334. */
  335. reg = 0x00000000;
  336. reg |= bd->bi_enetaddr[0]; /* set high address */
  337. reg = reg << 8;
  338. reg |= bd->bi_enetaddr[1];
  339. out32 (EMAC_IAH, reg);
  340. reg = 0x00000000;
  341. reg |= bd->bi_enetaddr[2]; /* set low address */
  342. reg = reg << 8;
  343. reg |= bd->bi_enetaddr[3];
  344. reg = reg << 8;
  345. reg |= bd->bi_enetaddr[4];
  346. reg = reg << 8;
  347. reg |= bd->bi_enetaddr[5];
  348. out32 (EMAC_IAL, reg);
  349. #if defined(CONFIG_405GP)
  350. /*
  351. * Set edge conditioning circuitry on PPC405GPr
  352. * for compatibility to existing PPC405GP designs.
  353. */
  354. if ((pvr & 0xfffffff0) == (PVR_405GPR_RB & 0xfffffff0)) {
  355. mtdcr(ecr, 0x60606000);
  356. }
  357. #endif /* defined(CONFIG_405GP) */
  358. #endif /* defined(CONFIG_405GP) || defined(CONFIG_405EP) */
  359. return (0);
  360. }