mpc8641hpcn.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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 <asm/fsl_ddr_sdram.h>
  28. #include <asm/io.h>
  29. #include <libfdt.h>
  30. #include <fdt_support.h>
  31. #include <netdev.h>
  32. #include "../common/pixis.h"
  33. long int fixed_sdram(void);
  34. int board_early_init_f(void)
  35. {
  36. return 0;
  37. }
  38. int checkboard(void)
  39. {
  40. printf ("Board: MPC8641HPCN, System ID: 0x%02x, "
  41. "System Version: 0x%02x, FPGA Version: 0x%02x\n",
  42. in8(PIXIS_BASE + PIXIS_ID), in8(PIXIS_BASE + PIXIS_VER),
  43. in8(PIXIS_BASE + PIXIS_PVER));
  44. return 0;
  45. }
  46. phys_size_t
  47. initdram(int board_type)
  48. {
  49. long dram_size = 0;
  50. #if defined(CONFIG_SPD_EEPROM)
  51. dram_size = fsl_ddr_sdram();
  52. #else
  53. dram_size = fixed_sdram();
  54. #endif
  55. #if defined(CONFIG_SYS_RAMBOOT)
  56. puts(" DDR: ");
  57. return dram_size;
  58. #endif
  59. puts(" DDR: ");
  60. return dram_size;
  61. }
  62. #if !defined(CONFIG_SPD_EEPROM)
  63. /*
  64. * Fixed sdram init -- doesn't use serial presence detect.
  65. */
  66. long int
  67. fixed_sdram(void)
  68. {
  69. #if !defined(CONFIG_SYS_RAMBOOT)
  70. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  71. volatile ccsr_ddr_t *ddr = &immap->im_ddr1;
  72. ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
  73. ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
  74. ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
  75. ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
  76. ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  77. ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  78. ddr->sdram_mode_1 = CONFIG_SYS_DDR_MODE_1;
  79. ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2;
  80. ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  81. ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT;
  82. ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL;
  83. ddr->sdram_ocd_cntl = CONFIG_SYS_DDR_OCD_CTRL;
  84. ddr->sdram_ocd_status = CONFIG_SYS_DDR_OCD_STATUS;
  85. #if defined (CONFIG_DDR_ECC)
  86. ddr->err_disable = 0x0000008D;
  87. ddr->err_sbe = 0x00ff0000;
  88. #endif
  89. asm("sync;isync");
  90. udelay(500);
  91. #if defined (CONFIG_DDR_ECC)
  92. /* Enable ECC checking */
  93. ddr->sdram_cfg_1 = (CONFIG_SYS_DDR_CONTROL | 0x20000000);
  94. #else
  95. ddr->sdram_cfg_1 = CONFIG_SYS_DDR_CONTROL;
  96. ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL2;
  97. #endif
  98. asm("sync; isync");
  99. udelay(500);
  100. #endif
  101. return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
  102. }
  103. #endif /* !defined(CONFIG_SPD_EEPROM) */
  104. #if defined(CONFIG_PCI)
  105. /*
  106. * Initialize PCI Devices, report devices found.
  107. */
  108. #ifndef CONFIG_PCI_PNP
  109. static struct pci_config_table pci_fsl86xxads_config_table[] = {
  110. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  111. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  112. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  113. PCI_ENET0_MEMADDR,
  114. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER}},
  115. {}
  116. };
  117. #endif
  118. static struct pci_controller pci1_hose = {
  119. #ifndef CONFIG_PCI_PNP
  120. config_table:pci_mpc86xxcts_config_table
  121. #endif
  122. };
  123. #endif /* CONFIG_PCI */
  124. #ifdef CONFIG_PCI2
  125. static struct pci_controller pci2_hose;
  126. #endif /* CONFIG_PCI2 */
  127. int first_free_busno = 0;
  128. extern int fsl_pci_setup_inbound_windows(struct pci_region *r);
  129. extern void fsl_pci_init(struct pci_controller *hose);
  130. void pci_init_board(void)
  131. {
  132. volatile immap_t *immap = (immap_t *) CONFIG_SYS_CCSRBAR;
  133. volatile ccsr_gur_t *gur = &immap->im_gur;
  134. uint devdisr = gur->devdisr;
  135. uint io_sel = (gur->pordevsr & MPC8641_PORDEVSR_IO_SEL)
  136. >> MPC8641_PORDEVSR_IO_SEL_SHIFT;
  137. #ifdef CONFIG_PCI1
  138. {
  139. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI1_ADDR;
  140. struct pci_controller *hose = &pci1_hose;
  141. struct pci_region *r = hose->regions;
  142. #ifdef DEBUG
  143. uint host1_agent = (gur->porbmsr & MPC8641_PORBMSR_HA)
  144. >> MPC8641_PORBMSR_HA_SHIFT;
  145. uint pex1_agent = (host1_agent == 0) || (host1_agent == 1);
  146. #endif
  147. if ((io_sel == 2 || io_sel == 3 || io_sel == 5
  148. || io_sel == 6 || io_sel == 7 || io_sel == 0xF)
  149. && !(devdisr & MPC86xx_DEVDISR_PCIEX1)) {
  150. debug("PCI-EXPRESS 1: %s \n", pex1_agent ? "Agent" : "Host");
  151. debug("0x%08x=0x%08x ", &pci->pme_msg_det, pci->pme_msg_det);
  152. if (pci->pme_msg_det) {
  153. pci->pme_msg_det = 0xffffffff;
  154. debug(" with errors. Clearing. Now 0x%08x",
  155. pci->pme_msg_det);
  156. }
  157. debug("\n");
  158. /* inbound */
  159. r += fsl_pci_setup_inbound_windows(r);
  160. /* outbound memory */
  161. pci_set_region(r++,
  162. CONFIG_SYS_PCI1_MEM_BASE,
  163. CONFIG_SYS_PCI1_MEM_PHYS,
  164. CONFIG_SYS_PCI1_MEM_SIZE,
  165. PCI_REGION_MEM);
  166. /* outbound io */
  167. pci_set_region(r++,
  168. CONFIG_SYS_PCI1_IO_BASE,
  169. CONFIG_SYS_PCI1_IO_PHYS,
  170. CONFIG_SYS_PCI1_IO_SIZE,
  171. PCI_REGION_IO);
  172. hose->region_count = r - hose->regions;
  173. hose->first_busno=first_free_busno;
  174. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  175. fsl_pci_init(hose);
  176. first_free_busno=hose->last_busno+1;
  177. printf (" PCI-EXPRESS 1 on bus %02x - %02x\n",
  178. hose->first_busno,hose->last_busno);
  179. /*
  180. * Activate ULI1575 legacy chip by performing a fake
  181. * memory access. Needed to make ULI RTC work.
  182. */
  183. in_be32((unsigned *) ((char *)(CONFIG_SYS_PCI1_MEM_BASE
  184. + CONFIG_SYS_PCI1_MEM_SIZE - 0x1000000)));
  185. } else {
  186. puts("PCI-EXPRESS 1: Disabled\n");
  187. }
  188. }
  189. #else
  190. puts("PCI-EXPRESS1: Disabled\n");
  191. #endif /* CONFIG_PCI1 */
  192. #ifdef CONFIG_PCI2
  193. {
  194. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI2_ADDR;
  195. struct pci_controller *hose = &pci2_hose;
  196. struct pci_region *r = hose->regions;
  197. /* inbound */
  198. r += fsl_pci_setup_inbound_windows(r);
  199. /* outbound memory */
  200. pci_set_region(r++,
  201. CONFIG_SYS_PCI2_MEM_BASE,
  202. CONFIG_SYS_PCI2_MEM_PHYS,
  203. CONFIG_SYS_PCI2_MEM_SIZE,
  204. PCI_REGION_MEM);
  205. /* outbound io */
  206. pci_set_region(r++,
  207. CONFIG_SYS_PCI2_IO_BASE,
  208. CONFIG_SYS_PCI2_IO_PHYS,
  209. CONFIG_SYS_PCI2_IO_SIZE,
  210. PCI_REGION_IO);
  211. hose->region_count = r - hose->regions;
  212. hose->first_busno=first_free_busno;
  213. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  214. fsl_pci_init(hose);
  215. first_free_busno=hose->last_busno+1;
  216. printf (" PCI-EXPRESS 2 on bus %02x - %02x\n",
  217. hose->first_busno,hose->last_busno);
  218. }
  219. #else
  220. puts("PCI-EXPRESS 2: Disabled\n");
  221. #endif /* CONFIG_PCI2 */
  222. }
  223. #if defined(CONFIG_OF_BOARD_SETUP)
  224. extern void ft_fsl_pci_setup(void *blob, const char *pci_alias,
  225. struct pci_controller *hose);
  226. void
  227. ft_board_setup(void *blob, bd_t *bd)
  228. {
  229. ft_cpu_setup(blob, bd);
  230. #ifdef CONFIG_PCI1
  231. ft_fsl_pci_setup(blob, "pci0", &pci1_hose);
  232. #endif
  233. #ifdef CONFIG_PCI2
  234. ft_fsl_pci_setup(blob, "pci1", &pci2_hose);
  235. #endif
  236. }
  237. #endif
  238. /*
  239. * get_board_sys_clk
  240. * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
  241. */
  242. unsigned long
  243. get_board_sys_clk(ulong dummy)
  244. {
  245. u8 i, go_bit, rd_clks;
  246. ulong val = 0;
  247. go_bit = in8(PIXIS_BASE + PIXIS_VCTL);
  248. go_bit &= 0x01;
  249. rd_clks = in8(PIXIS_BASE + PIXIS_VCFGEN0);
  250. rd_clks &= 0x1C;
  251. /*
  252. * Only if both go bit and the SCLK bit in VCFGEN0 are set
  253. * should we be using the AUX register. Remember, we also set the
  254. * GO bit to boot from the alternate bank on the on-board flash
  255. */
  256. if (go_bit) {
  257. if (rd_clks == 0x1c)
  258. i = in8(PIXIS_BASE + PIXIS_AUX);
  259. else
  260. i = in8(PIXIS_BASE + PIXIS_SPD);
  261. } else {
  262. i = in8(PIXIS_BASE + PIXIS_SPD);
  263. }
  264. i &= 0x07;
  265. switch (i) {
  266. case 0:
  267. val = 33000000;
  268. break;
  269. case 1:
  270. val = 40000000;
  271. break;
  272. case 2:
  273. val = 50000000;
  274. break;
  275. case 3:
  276. val = 66000000;
  277. break;
  278. case 4:
  279. val = 83000000;
  280. break;
  281. case 5:
  282. val = 100000000;
  283. break;
  284. case 6:
  285. val = 134000000;
  286. break;
  287. case 7:
  288. val = 166000000;
  289. break;
  290. }
  291. return val;
  292. }
  293. int board_eth_init(bd_t *bis)
  294. {
  295. /* Initialize TSECs */
  296. cpu_eth_init(bis);
  297. return pci_eth_init(bis);
  298. }