cpu_init.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * (C) Copyright 2000
  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 <405gp_enet.h>
  26. #include <asm/processor.h>
  27. #include <ppc4xx.h>
  28. #define mtebc(reg, data) mtdcr(ebccfga,reg);mtdcr(ebccfgd,data)
  29. /*
  30. * Breath some life into the CPU...
  31. *
  32. * Set up the memory map,
  33. * initialize a bunch of registers
  34. */
  35. void
  36. cpu_init_f (void)
  37. {
  38. #if defined(CONFIG_405EP)
  39. /*
  40. * GPIO0 setup (select GPIO or alternate function)
  41. */
  42. out32(GPIO0_OSRH, CFG_GPIO0_OSRH); /* output select */
  43. out32(GPIO0_OSRL, CFG_GPIO0_OSRL);
  44. out32(GPIO0_ISR1H, CFG_GPIO0_ISR1H); /* input select */
  45. out32(GPIO0_ISR1L, CFG_GPIO0_ISR1L);
  46. out32(GPIO0_TSRH, CFG_GPIO0_TSRH); /* three-state select */
  47. out32(GPIO0_TSRL, CFG_GPIO0_TSRL);
  48. out32(GPIO0_TCR, CFG_GPIO0_TCR); /* enable output driver for outputs */
  49. /*
  50. * Set EMAC noise filter bits
  51. */
  52. mtdcr(cpc0_epctl, CPC0_EPRCSR_E0NFE | CPC0_EPRCSR_E1NFE);
  53. #endif /* CONFIG_405EP */
  54. /*
  55. * External Bus Controller (EBC) Setup
  56. */
  57. #if (defined(CFG_EBC_PB0AP) && defined(CFG_EBC_PB0CR))
  58. /*
  59. * Move the next instructions into icache, since these modify the flash
  60. * we are running from!
  61. */
  62. asm volatile(" bl 0f" ::: "lr");
  63. asm volatile("0: mflr 3" ::: "r3");
  64. asm volatile(" addi 4, 0, 14" ::: "r4");
  65. asm volatile(" mtctr 4" ::: "ctr");
  66. asm volatile("1: icbt 0, 3");
  67. asm volatile(" addi 3, 3, 32" ::: "r3");
  68. asm volatile(" bdnz 1b" ::: "ctr", "cr0");
  69. asm volatile(" addis 3, 0, 0x0" ::: "r3");
  70. asm volatile(" ori 3, 3, 0xA000" ::: "r3");
  71. asm volatile(" mtctr 3" ::: "ctr");
  72. asm volatile("2: bdnz 2b" ::: "ctr", "cr0");
  73. mtebc(pb0ap, CFG_EBC_PB0AP);
  74. mtebc(pb0cr, CFG_EBC_PB0CR);
  75. #endif
  76. #if (defined(CFG_EBC_PB1AP) && defined(CFG_EBC_PB1CR))
  77. mtebc(pb1ap, CFG_EBC_PB1AP);
  78. mtebc(pb1cr, CFG_EBC_PB1CR);
  79. #endif
  80. #if (defined(CFG_EBC_PB2AP) && defined(CFG_EBC_PB2CR))
  81. mtebc(pb2ap, CFG_EBC_PB2AP);
  82. mtebc(pb2cr, CFG_EBC_PB2CR);
  83. #endif
  84. #if (defined(CFG_EBC_PB3AP) && defined(CFG_EBC_PB3CR))
  85. mtebc(pb3ap, CFG_EBC_PB3AP);
  86. mtebc(pb3cr, CFG_EBC_PB3CR);
  87. #endif
  88. #if (defined(CFG_EBC_PB4AP) && defined(CFG_EBC_PB4CR))
  89. mtebc(pb4ap, CFG_EBC_PB4AP);
  90. mtebc(pb4cr, CFG_EBC_PB4CR);
  91. #endif
  92. #if (defined(CFG_EBC_PB5AP) && defined(CFG_EBC_PB5CR))
  93. mtebc(pb5ap, CFG_EBC_PB5AP);
  94. mtebc(pb5cr, CFG_EBC_PB5CR);
  95. #endif
  96. #if (defined(CFG_EBC_PB6AP) && defined(CFG_EBC_PB6CR))
  97. mtebc(pb6ap, CFG_EBC_PB6AP);
  98. mtebc(pb6cr, CFG_EBC_PB6CR);
  99. #endif
  100. #if (defined(CFG_EBC_PB7AP) && defined(CFG_EBC_PB7CR))
  101. mtebc(pb7ap, CFG_EBC_PB7AP);
  102. mtebc(pb7cr, CFG_EBC_PB7CR);
  103. #endif
  104. #if defined(CONFIG_WATCHDOG)
  105. unsigned long val;
  106. val = mfspr(tcr);
  107. val |= 0xf0000000; /* generate system reset after 2.684 seconds */
  108. mtspr(tcr, val);
  109. val = mfspr(tsr);
  110. val |= 0x80000000; /* enable watchdog timer */
  111. mtspr(tsr, val);
  112. reset_4xx_watchdog();
  113. #endif /* CONFIG_WATCHDOG */
  114. }
  115. /*
  116. * initialize higher level parts of CPU like time base and timers
  117. */
  118. int cpu_init_r (void)
  119. {
  120. #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
  121. DECLARE_GLOBAL_DATA_PTR;
  122. bd_t *bd = gd->bd;
  123. unsigned long reg;
  124. #if defined(CONFIG_405GP)
  125. uint pvr = get_pvr();
  126. #endif
  127. /*
  128. * Write Ethernetaddress into on-chip register
  129. */
  130. reg = 0x00000000;
  131. reg |= bd->bi_enetaddr[0]; /* set high address */
  132. reg = reg << 8;
  133. reg |= bd->bi_enetaddr[1];
  134. out32 (EMAC_IAH, reg);
  135. reg = 0x00000000;
  136. reg |= bd->bi_enetaddr[2]; /* set low address */
  137. reg = reg << 8;
  138. reg |= bd->bi_enetaddr[3];
  139. reg = reg << 8;
  140. reg |= bd->bi_enetaddr[4];
  141. reg = reg << 8;
  142. reg |= bd->bi_enetaddr[5];
  143. out32 (EMAC_IAL, reg);
  144. #if defined(CONFIG_405GP)
  145. /*
  146. * Set edge conditioning circuitry on PPC405GPr
  147. * for compatibility to existing PPC405GP designs.
  148. */
  149. if ((pvr & 0xfffffff0) == (PVR_405GPR_RB & 0xfffffff0)) {
  150. mtdcr(ecr, 0x60606000);
  151. }
  152. #endif /* defined(CONFIG_405GP) */
  153. #endif /* defined(CONFIG_405GP) || defined(CONFIG_405EP) */
  154. return (0);
  155. }