mpc8641hpcn.c 8.7 KB

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