cpu_init.c 11 KB

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