mpc8641hpcn.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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 <asm/immap_fsl_pci.h>
  27. #include <spd.h>
  28. #include <asm/io.h>
  29. #if defined(CONFIG_OF_FLAT_TREE)
  30. #include <ft_build.h>
  31. extern void ft_cpu_setup(void *blob, bd_t *bd);
  32. #endif
  33. #include "../freescale/common/pixis.h"
  34. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  35. extern void ddr_enable_ecc(unsigned int dram_size);
  36. #endif
  37. #if defined(CONFIG_SPD_EEPROM)
  38. #include "spd_sdram.h"
  39. #endif
  40. void sdram_init(void);
  41. long int fixed_sdram(void);
  42. int board_early_init_f(void)
  43. {
  44. return 0;
  45. }
  46. int checkboard(void)
  47. {
  48. puts("Board: MPC8641HPCN\n");
  49. return 0;
  50. }
  51. long int
  52. initdram(int board_type)
  53. {
  54. long dram_size = 0;
  55. #if defined(CONFIG_SPD_EEPROM)
  56. dram_size = spd_sdram();
  57. #else
  58. dram_size = fixed_sdram();
  59. #endif
  60. #if defined(CFG_RAMBOOT)
  61. puts(" DDR: ");
  62. return dram_size;
  63. #endif
  64. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  65. /*
  66. * Initialize and enable DDR ECC.
  67. */
  68. ddr_enable_ecc(dram_size);
  69. #endif
  70. puts(" DDR: ");
  71. return dram_size;
  72. }
  73. #if defined(CFG_DRAM_TEST)
  74. int
  75. testdram(void)
  76. {
  77. uint *pstart = (uint *) CFG_MEMTEST_START;
  78. uint *pend = (uint *) CFG_MEMTEST_END;
  79. uint *p;
  80. puts("SDRAM test phase 1:\n");
  81. for (p = pstart; p < pend; p++)
  82. *p = 0xaaaaaaaa;
  83. for (p = pstart; p < pend; p++) {
  84. if (*p != 0xaaaaaaaa) {
  85. printf("SDRAM test fails at: %08x\n", (uint) p);
  86. return 1;
  87. }
  88. }
  89. puts("SDRAM test phase 2:\n");
  90. for (p = pstart; p < pend; p++)
  91. *p = 0x55555555;
  92. for (p = pstart; p < pend; p++) {
  93. if (*p != 0x55555555) {
  94. printf("SDRAM test fails at: %08x\n", (uint) p);
  95. return 1;
  96. }
  97. }
  98. puts("SDRAM test passed.\n");
  99. return 0;
  100. }
  101. #endif
  102. #if !defined(CONFIG_SPD_EEPROM)
  103. /*
  104. * Fixed sdram init -- doesn't use serial presence detect.
  105. */
  106. long int
  107. fixed_sdram(void)
  108. {
  109. #if !defined(CFG_RAMBOOT)
  110. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  111. volatile ccsr_ddr_t *ddr = &immap->im_ddr1;
  112. ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
  113. ddr->cs0_config = CFG_DDR_CS0_CONFIG;
  114. ddr->ext_refrec = CFG_DDR_EXT_REFRESH;
  115. ddr->timing_cfg_0 = CFG_DDR_TIMING_0;
  116. ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
  117. ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
  118. ddr->sdram_mode_1 = CFG_DDR_MODE_1;
  119. ddr->sdram_mode_2 = CFG_DDR_MODE_2;
  120. ddr->sdram_interval = CFG_DDR_INTERVAL;
  121. ddr->sdram_data_init = CFG_DDR_DATA_INIT;
  122. ddr->sdram_clk_cntl = CFG_DDR_CLK_CTRL;
  123. ddr->sdram_ocd_cntl = CFG_DDR_OCD_CTRL;
  124. ddr->sdram_ocd_status = CFG_DDR_OCD_STATUS;
  125. #if defined (CONFIG_DDR_ECC)
  126. ddr->err_disable = 0x0000008D;
  127. ddr->err_sbe = 0x00ff0000;
  128. #endif
  129. asm("sync;isync");
  130. udelay(500);
  131. #if defined (CONFIG_DDR_ECC)
  132. /* Enable ECC checking */
  133. ddr->sdram_cfg_1 = (CFG_DDR_CONTROL | 0x20000000);
  134. #else
  135. ddr->sdram_cfg_1 = CFG_DDR_CONTROL;
  136. ddr->sdram_cfg_2 = CFG_DDR_CONTROL2;
  137. #endif
  138. asm("sync; isync");
  139. udelay(500);
  140. #endif
  141. return CFG_SDRAM_SIZE * 1024 * 1024;
  142. }
  143. #endif /* !defined(CONFIG_SPD_EEPROM) */
  144. #if defined(CONFIG_PCI)
  145. /*
  146. * Initialize PCI Devices, report devices found.
  147. */
  148. #ifndef CONFIG_PCI_PNP
  149. static struct pci_config_table pci_fsl86xxads_config_table[] = {
  150. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  151. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  152. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  153. PCI_ENET0_MEMADDR,
  154. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER}},
  155. {}
  156. };
  157. #endif
  158. static struct pci_controller pci1_hose = {
  159. #ifndef CONFIG_PCI_PNP
  160. config_table:pci_mpc86xxcts_config_table
  161. #endif
  162. };
  163. #endif /* CONFIG_PCI */
  164. #ifdef CONFIG_PCI2
  165. static struct pci_controller pci2_hose;
  166. #endif /* CONFIG_PCI2 */
  167. int first_free_busno = 0;
  168. void pci_init_board(void)
  169. {
  170. volatile immap_t *immap = (immap_t *) CFG_CCSRBAR;
  171. volatile ccsr_gur_t *gur = &immap->im_gur;
  172. uint devdisr = gur->devdisr;
  173. uint io_sel = (gur->pordevsr & MPC86xx_PORDEVSR_IO_SEL) >> 16;
  174. #ifdef CONFIG_PCI1
  175. {
  176. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI1_ADDR;
  177. extern void fsl_pci_init(struct pci_controller *hose);
  178. struct pci_controller *hose = &pci1_hose;
  179. #ifdef DEBUG
  180. uint host1_agent = (gur->porbmsr & MPC86xx_PORBMSR_HA) >> 17;
  181. uint pex1_agent = (host1_agent == 0) || (host1_agent == 1);
  182. #endif
  183. if ((io_sel == 2 || io_sel == 3 || io_sel == 5
  184. || io_sel == 6 || io_sel == 7 || io_sel == 0xF)
  185. && !(devdisr & MPC86xx_DEVDISR_PCIEX1)) {
  186. debug("PCI-EXPRESS 1: %s \n", pex1_agent ? "Agent" : "Host");
  187. debug("0x%08x=0x%08x ", &pci->pme_msg_det, pci->pme_msg_det);
  188. if (pci->pme_msg_det) {
  189. pci->pme_msg_det = 0xffffffff;
  190. debug(" with errors. Clearing. Now 0x%08x",
  191. pci->pme_msg_det);
  192. }
  193. debug("\n");
  194. /* inbound */
  195. pci_set_region(hose->regions + 0,
  196. CFG_PCI_MEMORY_BUS,
  197. CFG_PCI_MEMORY_PHYS,
  198. CFG_PCI_MEMORY_SIZE,
  199. PCI_REGION_MEM | PCI_REGION_MEMORY);
  200. /* outbound memory */
  201. pci_set_region(hose->regions + 1,
  202. CFG_PCI1_MEM_BASE,
  203. CFG_PCI1_MEM_PHYS,
  204. CFG_PCI1_MEM_SIZE,
  205. PCI_REGION_MEM);
  206. /* outbound io */
  207. pci_set_region(hose->regions + 2,
  208. CFG_PCI1_IO_BASE,
  209. CFG_PCI1_IO_PHYS,
  210. CFG_PCI1_IO_SIZE,
  211. PCI_REGION_IO);
  212. hose->region_count = 3;
  213. hose->first_busno=first_free_busno;
  214. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  215. fsl_pci_init(hose);
  216. first_free_busno=hose->last_busno+1;
  217. printf (" PCI-EXPRESS 1 on bus %02x - %02x\n",
  218. hose->first_busno,hose->last_busno);
  219. /*
  220. * Activate ULI1575 legacy chip by performing a fake
  221. * memory access. Needed to make ULI RTC work.
  222. */
  223. in_be32((unsigned *) ((char *)(CFG_PCI1_MEM_BASE
  224. + CFG_PCI1_MEM_SIZE - 0x1000000)));
  225. } else {
  226. puts("PCI-EXPRESS 1: Disabled\n");
  227. }
  228. }
  229. #else
  230. puts("PCI-EXPRESS1: Disabled\n");
  231. #endif /* CONFIG_PCI1 */
  232. #ifdef CONFIG_PCI2
  233. {
  234. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI2_ADDR;
  235. extern void fsl_pci_init(struct pci_controller *hose);
  236. struct pci_controller *hose = &pci2_hose;
  237. /* inbound */
  238. pci_set_region(hose->regions + 0,
  239. CFG_PCI_MEMORY_BUS,
  240. CFG_PCI_MEMORY_PHYS,
  241. CFG_PCI_MEMORY_SIZE,
  242. PCI_REGION_MEM | PCI_REGION_MEMORY);
  243. /* outbound memory */
  244. pci_set_region(hose->regions + 1,
  245. CFG_PCI2_MEM_BASE,
  246. CFG_PCI2_MEM_PHYS,
  247. CFG_PCI2_MEM_SIZE,
  248. PCI_REGION_MEM);
  249. /* outbound io */
  250. pci_set_region(hose->regions + 2,
  251. CFG_PCI2_IO_BASE,
  252. CFG_PCI2_IO_PHYS,
  253. CFG_PCI2_IO_SIZE,
  254. PCI_REGION_IO);
  255. hose->region_count = 3;
  256. hose->first_busno=first_free_busno;
  257. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  258. fsl_pci_init(hose);
  259. first_free_busno=hose->last_busno+1;
  260. printf (" PCI-EXPRESS 2 on bus %02x - %02x\n",
  261. hose->first_busno,hose->last_busno);
  262. }
  263. #else
  264. puts("PCI-EXPRESS 2: Disabled\n");
  265. #endif /* CONFIG_PCI2 */
  266. }
  267. #if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
  268. void
  269. ft_board_setup(void *blob, bd_t *bd)
  270. {
  271. u32 *p;
  272. int len;
  273. ft_cpu_setup(blob, bd);
  274. p = ft_get_prop(blob, "/memory/reg", &len);
  275. if (p != NULL) {
  276. *p++ = cpu_to_be32(bd->bi_memstart);
  277. *p = cpu_to_be32(bd->bi_memsize);
  278. }
  279. }
  280. #endif
  281. /*
  282. * get_board_sys_clk
  283. * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
  284. */
  285. unsigned long
  286. get_board_sys_clk(ulong dummy)
  287. {
  288. u8 i, go_bit, rd_clks;
  289. ulong val = 0;
  290. go_bit = in8(PIXIS_BASE + PIXIS_VCTL);
  291. go_bit &= 0x01;
  292. rd_clks = in8(PIXIS_BASE + PIXIS_VCFGEN0);
  293. rd_clks &= 0x1C;
  294. /*
  295. * Only if both go bit and the SCLK bit in VCFGEN0 are set
  296. * should we be using the AUX register. Remember, we also set the
  297. * GO bit to boot from the alternate bank on the on-board flash
  298. */
  299. if (go_bit) {
  300. if (rd_clks == 0x1c)
  301. i = in8(PIXIS_BASE + PIXIS_AUX);
  302. else
  303. i = in8(PIXIS_BASE + PIXIS_SPD);
  304. } else {
  305. i = in8(PIXIS_BASE + PIXIS_SPD);
  306. }
  307. i &= 0x07;
  308. switch (i) {
  309. case 0:
  310. val = 33000000;
  311. break;
  312. case 1:
  313. val = 40000000;
  314. break;
  315. case 2:
  316. val = 50000000;
  317. break;
  318. case 3:
  319. val = 66000000;
  320. break;
  321. case 4:
  322. val = 83000000;
  323. break;
  324. case 5:
  325. val = 100000000;
  326. break;
  327. case 6:
  328. val = 134000000;
  329. break;
  330. case 7:
  331. val = 166000000;
  332. break;
  333. }
  334. return val;
  335. }