cpu_init.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * (C) Copyright 2000-2009
  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 <mpc5xxx.h>
  25. #include <asm/io.h>
  26. DECLARE_GLOBAL_DATA_PTR;
  27. /*
  28. * Breath some life into the CPU...
  29. *
  30. * Set up the memory map,
  31. * initialize a bunch of registers.
  32. */
  33. void cpu_init_f (void)
  34. {
  35. volatile struct mpc5xxx_mmap_ctl *mm =
  36. (struct mpc5xxx_mmap_ctl *) CONFIG_SYS_MBAR;
  37. volatile struct mpc5xxx_lpb *lpb =
  38. (struct mpc5xxx_lpb *) MPC5XXX_LPB;
  39. volatile struct mpc5xxx_cdm *cdm =
  40. (struct mpc5xxx_cdm *) MPC5XXX_CDM;
  41. volatile struct mpc5xxx_gpio *gpio =
  42. (struct mpc5xxx_gpio *) MPC5XXX_GPIO;
  43. volatile struct mpc5xxx_xlb *xlb =
  44. (struct mpc5xxx_xlb *) MPC5XXX_XLBARB;
  45. unsigned long addecr = (1 << 25); /* Boot_CS */
  46. #if defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_MGT5100)
  47. addecr |= (1 << 22); /* SDRAM enable */
  48. #endif
  49. /* Pointer is writable since we allocated a register for it */
  50. gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
  51. /* Clear initial global data */
  52. memset ((void *) gd, 0, sizeof (gd_t));
  53. /*
  54. * Memory Controller: configure chip selects and enable them
  55. */
  56. #if defined(CONFIG_SYS_BOOTCS_START) && defined(CONFIG_SYS_BOOTCS_SIZE)
  57. out_be32(&mm->boot_start, START_REG(CONFIG_SYS_BOOTCS_START));
  58. out_be32(&mm->boot_stop, STOP_REG(CONFIG_SYS_BOOTCS_START,
  59. CONFIG_SYS_BOOTCS_SIZE));
  60. #endif
  61. #if defined(CONFIG_SYS_BOOTCS_CFG)
  62. out_be32(&lpb->cs0_cfg, CONFIG_SYS_BOOTCS_CFG);
  63. #endif
  64. #if defined(CONFIG_SYS_CS0_START) && defined(CONFIG_SYS_CS0_SIZE)
  65. out_be32(&mm->cs0_start, START_REG(CONFIG_SYS_CS0_START));
  66. out_be32(&mm->cs0_stop, STOP_REG(CONFIG_SYS_CS0_START,
  67. CONFIG_SYS_CS0_SIZE));
  68. /* CS0 and BOOT_CS cannot be enabled at once. */
  69. /* addecr |= (1 << 16); */
  70. #endif
  71. #if defined(CONFIG_SYS_CS0_CFG)
  72. out_be32(&lpb->cs0_cfg, CONFIG_SYS_CS0_CFG);
  73. #endif
  74. #if defined(CONFIG_SYS_CS1_START) && defined(CONFIG_SYS_CS1_SIZE)
  75. out_be32(&mm->cs1_start, START_REG(CONFIG_SYS_CS1_START));
  76. out_be32(&mm->cs1_stop, STOP_REG(CONFIG_SYS_CS1_START,
  77. CONFIG_SYS_CS1_SIZE));
  78. addecr |= (1 << 17);
  79. #endif
  80. #if defined(CONFIG_SYS_CS1_CFG)
  81. out_be32(&lpb->cs1_cfg, CONFIG_SYS_CS1_CFG);
  82. #endif
  83. #if defined(CONFIG_SYS_CS2_START) && defined(CONFIG_SYS_CS2_SIZE)
  84. out_be32(&mm->cs2_start, START_REG(CONFIG_SYS_CS2_START));
  85. out_be32(&mm->cs2_stop, STOP_REG(CONFIG_SYS_CS2_START,
  86. CONFIG_SYS_CS2_SIZE));
  87. addecr |= (1 << 18);
  88. #endif
  89. #if defined(CONFIG_SYS_CS2_CFG)
  90. out_be32(&lpb->cs2_cfg, CONFIG_SYS_CS2_CFG);
  91. #endif
  92. #if defined(CONFIG_SYS_CS3_START) && defined(CONFIG_SYS_CS3_SIZE)
  93. out_be32(&mm->cs3_start, START_REG(CONFIG_SYS_CS3_START));
  94. out_be32(&mm->cs3_stop, STOP_REG(CONFIG_SYS_CS3_START,
  95. CONFIG_SYS_CS3_SIZE));
  96. addecr |= (1 << 19);
  97. #endif
  98. #if defined(CONFIG_SYS_CS3_CFG)
  99. out_be32(&lpb->cs3_cfg, CONFIG_SYS_CS3_CFG);
  100. #endif
  101. #if defined(CONFIG_SYS_CS4_START) && defined(CONFIG_SYS_CS4_SIZE)
  102. out_be32(&mm->cs4_start, START_REG(CONFIG_SYS_CS4_START));
  103. out_be32(&mm->cs4_stop, STOP_REG(CONFIG_SYS_CS4_START,
  104. CONFIG_SYS_CS4_SIZE));
  105. addecr |= (1 << 20);
  106. #endif
  107. #if defined(CONFIG_SYS_CS4_CFG)
  108. out_be32(&lpb->cs4_cfg, CONFIG_SYS_CS4_CFG);
  109. #endif
  110. #if defined(CONFIG_SYS_CS5_START) && defined(CONFIG_SYS_CS5_SIZE)
  111. out_be32(&mm->cs5_start, START_REG(CONFIG_SYS_CS5_START));
  112. out_be32(&mm->cs5_stop, STOP_REG(CONFIG_SYS_CS5_START,
  113. CONFIG_SYS_CS5_SIZE));
  114. addecr |= (1 << 21);
  115. #endif
  116. #if defined(CONFIG_SYS_CS5_CFG)
  117. out_be32(&lpb->cs5_cfg, CONFIG_SYS_CS5_CFG);
  118. #endif
  119. #if defined(CONFIG_MPC5200)
  120. addecr |= 1;
  121. #if defined(CONFIG_SYS_CS6_START) && defined(CONFIG_SYS_CS6_SIZE)
  122. out_be32(&mm->cs6_start, START_REG(CONFIG_SYS_CS6_START));
  123. out_be32(&mm->cs6_stop, STOP_REG(CONFIG_SYS_CS6_START,
  124. CONFIG_SYS_CS6_SIZE));
  125. addecr |= (1 << 26);
  126. #endif
  127. #if defined(CONFIG_SYS_CS6_CFG)
  128. out_be32(&lpb->cs6_cfg, CONFIG_SYS_CS6_CFG);
  129. #endif
  130. #if defined(CONFIG_SYS_CS7_START) && defined(CONFIG_SYS_CS7_SIZE)
  131. out_be32(&mm->cs7_start, START_REG(CONFIG_SYS_CS7_START));
  132. out_be32(&mm->cs7_stop, STOP_REG(CONFIG_SYS_CS7_START,
  133. CONFIG_SYS_CS7_SIZE));
  134. addecr |= (1 << 27);
  135. #endif
  136. #if defined(CONFIG_SYS_CS7_CFG)
  137. out_be32(&lpb->cs7_cfg, CONFIG_SYS_CS7_CFG);
  138. #endif
  139. #if defined(CONFIG_SYS_CS_BURST)
  140. out_be32(&lpb->cs_burst, CONFIG_SYS_CS_BURST);
  141. #endif
  142. #if defined(CONFIG_SYS_CS_DEADCYCLE)
  143. out_be32(&lpb->cs_deadcycle, CONFIG_SYS_CS_DEADCYCLE);
  144. #endif
  145. #endif /* CONFIG_MPC5200 */
  146. /* Enable chip selects */
  147. #if defined(CONFIG_MGT5100)
  148. out_be32(&mm->addecr, addecr);
  149. #elif defined(CONFIG_MPC5200)
  150. out_be32(&mm->ipbi_ws_ctrl, addecr);
  151. #endif
  152. out_be32(&lpb->cs_ctrl, (1 << 24));
  153. /* Setup pin multiplexing */
  154. #if defined(CONFIG_SYS_GPS_PORT_CONFIG)
  155. out_be32(&gpio->port_config, CONFIG_SYS_GPS_PORT_CONFIG);
  156. #endif
  157. #if defined(CONFIG_MPC5200)
  158. /* enable timebase */
  159. setbits_be32(&xlb->config, (1 << 13));
  160. /* Enable snooping for RAM */
  161. setbits_be32(&xlb->config, (1 << 15));
  162. out_be32(&xlb->snoop_window, CONFIG_SYS_SDRAM_BASE | 0x1d);
  163. # if defined(CONFIG_SYS_IPBCLK_EQUALS_XLBCLK)
  164. /* Motorola reports IPB should better run at 133 MHz. */
  165. #if defined(CONFIG_MGT5100)
  166. setbits_be32(&mm->addecr, 1);
  167. #elif defined(CONFIG_MPC5200)
  168. setbits_be32(&mm->ipbi_ws_ctrl, 1);
  169. #endif
  170. /* pci_clk_sel = 0x02, ipb_clk_sel = 0x00; */
  171. addecr = in_be32(&cdm->cfg);
  172. addecr &= ~0x103;
  173. # if defined(CONFIG_SYS_PCICLK_EQUALS_IPBCLK_DIV2)
  174. /* pci_clk_sel = 0x01 -> IPB_CLK/2 */
  175. addecr |= 0x01;
  176. # else
  177. /* pci_clk_sel = 0x02 -> XLB_CLK/4 = IPB_CLK/4 */
  178. addecr |= 0x02;
  179. # endif /* CONFIG_SYS_PCICLK_EQUALS_IPBCLK_DIV2 */
  180. out_be32(&cdm->cfg, addecr);
  181. # endif /* CONFIG_SYS_IPBCLK_EQUALS_XLBCLK */
  182. /* Configure the XLB Arbiter */
  183. out_be32(&xlb->master_pri_enable, 0xff);
  184. out_be32(&xlb->master_priority, 0x11111111);
  185. # if defined(CONFIG_SYS_XLB_PIPELINING)
  186. /* Enable piplining */
  187. clrbits_be32(&xlb->config, (1 << 31));
  188. # endif
  189. #endif /* CONFIG_MPC5200 */
  190. }
  191. /*
  192. * initialize higher level parts of CPU like time base and timers
  193. */
  194. int cpu_init_r (void)
  195. {
  196. volatile struct mpc5xxx_intr *intr =
  197. (struct mpc5xxx_intr *) MPC5XXX_ICTL;
  198. /* mask all interrupts */
  199. #if defined(CONFIG_MGT5100)
  200. out_be32(&intr->per_mask, 0xfffffc00);
  201. #elif defined(CONFIG_MPC5200)
  202. out_be32(&intr->per_mask, 0xffffff00);
  203. #endif
  204. setbits_be32(&intr->main_mask, 0x0001ffff);
  205. clrbits_be32(&intr->ctrl, 0x00000f00);
  206. /* route critical ints to normal ints */
  207. setbits_be32(&intr->ctrl, 0x00000001);
  208. #if defined(CONFIG_CMD_NET) && defined(CONFIG_MPC5xxx_FEC)
  209. /* load FEC microcode */
  210. loadtask(0, 2);
  211. #endif
  212. return (0);
  213. }