mpc8641hpcn.c 8.6 KB

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