mpc8641hpcn.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*
  2. * Copyright 2006, 2007 Freescale Semiconductor.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <pci.h>
  24. #include <asm/processor.h>
  25. #include <asm/immap_86xx.h>
  26. #include <spd.h>
  27. #include <asm/io.h>
  28. #if defined(CONFIG_OF_FLAT_TREE)
  29. #include <ft_build.h>
  30. extern void ft_cpu_setup(void *blob, bd_t *bd);
  31. #endif
  32. #include "../freescale/common/pixis.h"
  33. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  34. extern void ddr_enable_ecc(unsigned int dram_size);
  35. #endif
  36. #if defined(CONFIG_SPD_EEPROM)
  37. #include "spd_sdram.h"
  38. #endif
  39. void sdram_init(void);
  40. long int fixed_sdram(void);
  41. int board_early_init_f(void)
  42. {
  43. return 0;
  44. }
  45. int checkboard(void)
  46. {
  47. puts("Board: MPC8641HPCN\n");
  48. #ifdef CONFIG_PCI
  49. volatile immap_t *immap = (immap_t *) CFG_CCSRBAR;
  50. volatile ccsr_gur_t *gur = &immap->im_gur;
  51. volatile ccsr_pex_t *pex1 = &immap->im_pex1;
  52. uint devdisr = gur->devdisr;
  53. uint io_sel = (gur->pordevsr & MPC86xx_PORDEVSR_IO_SEL) >> 16;
  54. uint host1_agent = (gur->porbmsr & MPC86xx_PORBMSR_HA) >> 17;
  55. uint pex1_agent = (host1_agent == 0) || (host1_agent == 1);
  56. if ((io_sel == 2 || io_sel == 3 || io_sel == 5
  57. || io_sel == 6 || io_sel == 7 || io_sel == 0xF)
  58. && !(devdisr & MPC86xx_DEVDISR_PCIEX1)) {
  59. debug("PCI-EXPRESS 1: %s \n", pex1_agent ? "Agent" : "Host");
  60. debug("0x%08x=0x%08x ", &pex1->pme_msg_det, pex1->pme_msg_det);
  61. if (pex1->pme_msg_det) {
  62. pex1->pme_msg_det = 0xffffffff;
  63. debug(" with errors. Clearing. Now 0x%08x",
  64. pex1->pme_msg_det);
  65. }
  66. debug("\n");
  67. } else {
  68. puts("PCI-EXPRESS 1: Disabled\n");
  69. }
  70. #else
  71. puts("PCI-EXPRESS1: Disabled\n");
  72. #endif
  73. return 0;
  74. }
  75. long int
  76. initdram(int board_type)
  77. {
  78. long dram_size = 0;
  79. #if defined(CONFIG_SPD_EEPROM)
  80. dram_size = spd_sdram();
  81. #else
  82. dram_size = fixed_sdram();
  83. #endif
  84. #if defined(CFG_RAMBOOT)
  85. puts(" DDR: ");
  86. return dram_size;
  87. #endif
  88. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  89. /*
  90. * Initialize and enable DDR ECC.
  91. */
  92. ddr_enable_ecc(dram_size);
  93. #endif
  94. puts(" DDR: ");
  95. return dram_size;
  96. }
  97. #if defined(CFG_DRAM_TEST)
  98. int
  99. testdram(void)
  100. {
  101. uint *pstart = (uint *) CFG_MEMTEST_START;
  102. uint *pend = (uint *) CFG_MEMTEST_END;
  103. uint *p;
  104. puts("SDRAM test phase 1:\n");
  105. for (p = pstart; p < pend; p++)
  106. *p = 0xaaaaaaaa;
  107. for (p = pstart; p < pend; p++) {
  108. if (*p != 0xaaaaaaaa) {
  109. printf("SDRAM test fails at: %08x\n", (uint) p);
  110. return 1;
  111. }
  112. }
  113. puts("SDRAM test phase 2:\n");
  114. for (p = pstart; p < pend; p++)
  115. *p = 0x55555555;
  116. for (p = pstart; p < pend; p++) {
  117. if (*p != 0x55555555) {
  118. printf("SDRAM test fails at: %08x\n", (uint) p);
  119. return 1;
  120. }
  121. }
  122. puts("SDRAM test passed.\n");
  123. return 0;
  124. }
  125. #endif
  126. #if !defined(CONFIG_SPD_EEPROM)
  127. /*
  128. * Fixed sdram init -- doesn't use serial presence detect.
  129. */
  130. long int
  131. fixed_sdram(void)
  132. {
  133. #if !defined(CFG_RAMBOOT)
  134. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  135. volatile ccsr_ddr_t *ddr = &immap->im_ddr1;
  136. ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
  137. ddr->cs0_config = CFG_DDR_CS0_CONFIG;
  138. ddr->ext_refrec = CFG_DDR_EXT_REFRESH;
  139. ddr->timing_cfg_0 = CFG_DDR_TIMING_0;
  140. ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
  141. ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
  142. ddr->sdram_mode_1 = CFG_DDR_MODE_1;
  143. ddr->sdram_mode_2 = CFG_DDR_MODE_2;
  144. ddr->sdram_interval = CFG_DDR_INTERVAL;
  145. ddr->sdram_data_init = CFG_DDR_DATA_INIT;
  146. ddr->sdram_clk_cntl = CFG_DDR_CLK_CTRL;
  147. ddr->sdram_ocd_cntl = CFG_DDR_OCD_CTRL;
  148. ddr->sdram_ocd_status = CFG_DDR_OCD_STATUS;
  149. #if defined (CONFIG_DDR_ECC)
  150. ddr->err_disable = 0x0000008D;
  151. ddr->err_sbe = 0x00ff0000;
  152. #endif
  153. asm("sync;isync");
  154. udelay(500);
  155. #if defined (CONFIG_DDR_ECC)
  156. /* Enable ECC checking */
  157. ddr->sdram_cfg_1 = (CFG_DDR_CONTROL | 0x20000000);
  158. #else
  159. ddr->sdram_cfg_1 = CFG_DDR_CONTROL;
  160. ddr->sdram_cfg_2 = CFG_DDR_CONTROL2;
  161. #endif
  162. asm("sync; isync");
  163. udelay(500);
  164. #endif
  165. return CFG_SDRAM_SIZE * 1024 * 1024;
  166. }
  167. #endif /* !defined(CONFIG_SPD_EEPROM) */
  168. #if defined(CONFIG_PCI)
  169. /*
  170. * Initialize PCI Devices, report devices found.
  171. */
  172. #ifndef CONFIG_PCI_PNP
  173. static struct pci_config_table pci_fsl86xxads_config_table[] = {
  174. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  175. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  176. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  177. PCI_ENET0_MEMADDR,
  178. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER}},
  179. {}
  180. };
  181. #endif
  182. static struct pci_controller hose = {
  183. #ifndef CONFIG_PCI_PNP
  184. config_table:pci_mpc86xxcts_config_table,
  185. #endif
  186. };
  187. #endif /* CONFIG_PCI */
  188. void pci_init_board(void)
  189. {
  190. #ifdef CONFIG_PCI
  191. extern void pci_mpc86xx_init(struct pci_controller *hose);
  192. pci_mpc86xx_init(&hose);
  193. #endif /* CONFIG_PCI */
  194. }
  195. #if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
  196. void
  197. ft_board_setup(void *blob, bd_t *bd)
  198. {
  199. u32 *p;
  200. int len;
  201. ft_cpu_setup(blob, bd);
  202. p = ft_get_prop(blob, "/memory/reg", &len);
  203. if (p != NULL) {
  204. *p++ = cpu_to_be32(bd->bi_memstart);
  205. *p = cpu_to_be32(bd->bi_memsize);
  206. }
  207. }
  208. #endif
  209. /*
  210. * get_board_sys_clk
  211. * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
  212. */
  213. unsigned long
  214. get_board_sys_clk(ulong dummy)
  215. {
  216. u8 i, go_bit, rd_clks;
  217. ulong val = 0;
  218. go_bit = in8(PIXIS_BASE + PIXIS_VCTL);
  219. go_bit &= 0x01;
  220. rd_clks = in8(PIXIS_BASE + PIXIS_VCFGEN0);
  221. rd_clks &= 0x1C;
  222. /*
  223. * Only if both go bit and the SCLK bit in VCFGEN0 are set
  224. * should we be using the AUX register. Remember, we also set the
  225. * GO bit to boot from the alternate bank on the on-board flash
  226. */
  227. if (go_bit) {
  228. if (rd_clks == 0x1c)
  229. i = in8(PIXIS_BASE + PIXIS_AUX);
  230. else
  231. i = in8(PIXIS_BASE + PIXIS_SPD);
  232. } else {
  233. i = in8(PIXIS_BASE + PIXIS_SPD);
  234. }
  235. i &= 0x07;
  236. switch (i) {
  237. case 0:
  238. val = 33000000;
  239. break;
  240. case 1:
  241. val = 40000000;
  242. break;
  243. case 2:
  244. val = 50000000;
  245. break;
  246. case 3:
  247. val = 66000000;
  248. break;
  249. case 4:
  250. val = 83000000;
  251. break;
  252. case 5:
  253. val = 100000000;
  254. break;
  255. case 6:
  256. val = 134000000;
  257. break;
  258. case 7:
  259. val = 166000000;
  260. break;
  261. }
  262. return val;
  263. }