mpc8641hpcn.c 8.4 KB

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