mpc8641hpcn.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. /*
  2. * Copyright 2004 Freescale Semiconductor.
  3. * Jeff Brown
  4. * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
  5. *
  6. * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <command.h>
  28. #include <pci.h>
  29. #include <asm/processor.h>
  30. #include <asm/immap_86xx.h>
  31. #include <spd.h>
  32. #if defined(CONFIG_OF_FLAT_TREE)
  33. #include <ft_build.h>
  34. extern void ft_cpu_setup(void *blob, bd_t *bd);
  35. #endif
  36. #include "pixis.h"
  37. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  38. extern void ddr_enable_ecc(unsigned int dram_size);
  39. #endif
  40. #if defined(CONFIG_SPD_EEPROM)
  41. #include "spd_sdram.h"
  42. #endif
  43. void sdram_init(void);
  44. long int fixed_sdram(void);
  45. int board_early_init_f(void)
  46. {
  47. return 0;
  48. }
  49. int checkboard(void)
  50. {
  51. puts("Board: MPC8641HPCN\n");
  52. #ifdef CONFIG_PCI
  53. volatile immap_t *immap = (immap_t *) CFG_CCSRBAR;
  54. volatile ccsr_gur_t *gur = &immap->im_gur;
  55. volatile ccsr_pex_t *pex1 = &immap->im_pex1;
  56. uint devdisr = gur->devdisr;
  57. uint io_sel = (gur->pordevsr & MPC86xx_PORDEVSR_IO_SEL) >> 16;
  58. uint host1_agent = (gur->porbmsr & MPC86xx_PORBMSR_HA) >> 17;
  59. uint pex1_agent = (host1_agent == 0) || (host1_agent == 1);
  60. if ((io_sel == 2 || io_sel == 3 || io_sel == 5
  61. || io_sel == 6 || io_sel == 7 || io_sel == 0xF)
  62. && !(devdisr & MPC86xx_DEVDISR_PCIEX1)) {
  63. debug("PCI-EXPRESS 1: %s \n", pex1_agent ? "Agent" : "Host");
  64. debug("0x%08x=0x%08x ", &pex1->pme_msg_det, pex1->pme_msg_det);
  65. if (pex1->pme_msg_det) {
  66. pex1->pme_msg_det = 0xffffffff;
  67. debug(" with errors. Clearing. Now 0x%08x",
  68. pex1->pme_msg_det);
  69. }
  70. debug("\n");
  71. } else {
  72. puts("PCI-EXPRESS 1: Disabled\n");
  73. }
  74. #else
  75. puts("PCI-EXPRESS1: Disabled\n");
  76. #endif
  77. return 0;
  78. }
  79. long int
  80. initdram(int board_type)
  81. {
  82. long dram_size = 0;
  83. #if defined(CONFIG_SPD_EEPROM)
  84. dram_size = spd_sdram();
  85. #else
  86. dram_size = fixed_sdram();
  87. #endif
  88. #if defined(CFG_RAMBOOT)
  89. puts(" DDR: ");
  90. return dram_size;
  91. #endif
  92. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  93. /*
  94. * Initialize and enable DDR ECC.
  95. */
  96. ddr_enable_ecc(dram_size);
  97. #endif
  98. puts(" DDR: ");
  99. return dram_size;
  100. }
  101. #if defined(CFG_DRAM_TEST)
  102. int
  103. testdram(void)
  104. {
  105. uint *pstart = (uint *) CFG_MEMTEST_START;
  106. uint *pend = (uint *) CFG_MEMTEST_END;
  107. uint *p;
  108. puts("SDRAM test phase 1:\n");
  109. for (p = pstart; p < pend; p++)
  110. *p = 0xaaaaaaaa;
  111. for (p = pstart; p < pend; p++) {
  112. if (*p != 0xaaaaaaaa) {
  113. printf("SDRAM test fails at: %08x\n", (uint) p);
  114. return 1;
  115. }
  116. }
  117. puts("SDRAM test phase 2:\n");
  118. for (p = pstart; p < pend; p++)
  119. *p = 0x55555555;
  120. for (p = pstart; p < pend; p++) {
  121. if (*p != 0x55555555) {
  122. printf("SDRAM test fails at: %08x\n", (uint) p);
  123. return 1;
  124. }
  125. }
  126. puts("SDRAM test passed.\n");
  127. return 0;
  128. }
  129. #endif
  130. #if !defined(CONFIG_SPD_EEPROM)
  131. /*
  132. * Fixed sdram init -- doesn't use serial presence detect.
  133. */
  134. long int
  135. fixed_sdram(void)
  136. {
  137. #if !defined(CFG_RAMBOOT)
  138. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  139. volatile ccsr_ddr_t *ddr = &immap->im_ddr1;
  140. ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
  141. ddr->cs0_config = CFG_DDR_CS0_CONFIG;
  142. ddr->ext_refrec = CFG_DDR_EXT_REFRESH;
  143. ddr->timing_cfg_0 = CFG_DDR_TIMING_0;
  144. ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
  145. ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
  146. ddr->sdram_mode_1 = CFG_DDR_MODE_1;
  147. ddr->sdram_mode_2 = CFG_DDR_MODE_2;
  148. ddr->sdram_interval = CFG_DDR_INTERVAL;
  149. ddr->sdram_data_init = CFG_DDR_DATA_INIT;
  150. ddr->sdram_clk_cntl = CFG_DDR_CLK_CTRL;
  151. ddr->sdram_ocd_cntl = CFG_DDR_OCD_CTRL;
  152. ddr->sdram_ocd_status = CFG_DDR_OCD_STATUS;
  153. #if defined (CONFIG_DDR_ECC)
  154. ddr->err_disable = 0x0000008D;
  155. ddr->err_sbe = 0x00ff0000;
  156. #endif
  157. asm("sync;isync");
  158. udelay(500);
  159. #if defined (CONFIG_DDR_ECC)
  160. /* Enable ECC checking */
  161. ddr->sdram_cfg_1 = (CFG_DDR_CONTROL | 0x20000000);
  162. #else
  163. ddr->sdram_cfg_1 = CFG_DDR_CONTROL;
  164. ddr->sdram_cfg_2 = CFG_DDR_CONTROL2;
  165. #endif
  166. asm("sync; isync");
  167. udelay(500);
  168. #endif
  169. return CFG_SDRAM_SIZE * 1024 * 1024;
  170. }
  171. #endif /* !defined(CONFIG_SPD_EEPROM) */
  172. #if defined(CONFIG_PCI)
  173. /*
  174. * Initialize PCI Devices, report devices found.
  175. */
  176. #ifndef CONFIG_PCI_PNP
  177. static struct pci_config_table pci_fsl86xxads_config_table[] = {
  178. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  179. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  180. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  181. PCI_ENET0_MEMADDR,
  182. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER}},
  183. {}
  184. };
  185. #endif
  186. static struct pci_controller hose = {
  187. #ifndef CONFIG_PCI_PNP
  188. config_table:pci_mpc86xxcts_config_table,
  189. #endif
  190. };
  191. #endif /* CONFIG_PCI */
  192. void pci_init_board(void)
  193. {
  194. #ifdef CONFIG_PCI
  195. extern void pci_mpc86xx_init(struct pci_controller *hose);
  196. pci_mpc86xx_init(&hose);
  197. #endif /* CONFIG_PCI */
  198. }
  199. #if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
  200. void
  201. ft_board_setup(void *blob, bd_t *bd)
  202. {
  203. u32 *p;
  204. int len;
  205. ft_cpu_setup(blob, bd);
  206. p = ft_get_prop(blob, "/memory/reg", &len);
  207. if (p != NULL) {
  208. *p++ = cpu_to_be32(bd->bi_memstart);
  209. *p = cpu_to_be32(bd->bi_memsize);
  210. }
  211. }
  212. #endif
  213. void
  214. mpc8641_reset_board(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  215. {
  216. char cmd;
  217. ulong val;
  218. ulong corepll;
  219. /*
  220. * No args is a simple reset request.
  221. */
  222. if (argc <= 1) {
  223. out8(PIXIS_BASE + PIXIS_RST, 0);
  224. /* not reached */
  225. }
  226. cmd = argv[1][1];
  227. switch (cmd) {
  228. case 'f': /* reset with frequency changed */
  229. if (argc < 5)
  230. goto my_usage;
  231. read_from_px_regs(0);
  232. val = set_px_sysclk(simple_strtoul(argv[2], NULL, 10));
  233. corepll = strfractoint(argv[3]);
  234. val = val + set_px_corepll(corepll);
  235. val = val + set_px_mpxpll(simple_strtoul(argv[4], NULL, 10));
  236. if (val == 3) {
  237. puts("Setting registers VCFGEN0 and VCTL\n");
  238. read_from_px_regs(1);
  239. puts("Resetting board with values from VSPEED0, VSPEED1, VCLKH, and VCLKL ....\n");
  240. set_px_go();
  241. } else
  242. goto my_usage;
  243. while (1) ; /* Not reached */
  244. case 'l':
  245. if (argv[2][1] == 'f') {
  246. read_from_px_regs(0);
  247. read_from_px_regs_altbank(0);
  248. /* reset with frequency changed */
  249. val = set_px_sysclk(simple_strtoul(argv[3], NULL, 10));
  250. corepll = strfractoint(argv[4]);
  251. val = val + set_px_corepll(corepll);
  252. val = val + set_px_mpxpll(simple_strtoul(argv[5],
  253. NULL, 10));
  254. if (val == 3) {
  255. puts("Setting registers VCFGEN0, VCFGEN1, VBOOT, and VCTL\n");
  256. set_altbank();
  257. read_from_px_regs(1);
  258. read_from_px_regs_altbank(1);
  259. puts("Enabling watchdog timer on the FPGA and resetting board with values from VSPEED0, VSPEED1, VCLKH, and VCLKL to boot from the other bank ....\n");
  260. set_px_go_with_watchdog();
  261. } else
  262. goto my_usage;
  263. while (1) ; /* Not reached */
  264. } else if (argv[2][1] == 'd') {
  265. /*
  266. * Reset from alternate bank without changing
  267. * frequencies but with watchdog timer enabled.
  268. */
  269. read_from_px_regs(0);
  270. read_from_px_regs_altbank(0);
  271. puts("Setting registers VCFGEN1, VBOOT, and VCTL\n");
  272. set_altbank();
  273. read_from_px_regs_altbank(1);
  274. puts("Enabling watchdog timer on the FPGA and resetting board to boot from the other bank....\n");
  275. set_px_go_with_watchdog();
  276. while (1) ; /* Not reached */
  277. } else {
  278. /*
  279. * Reset from next bank without changing
  280. * frequency and without watchdog timer enabled.
  281. */
  282. read_from_px_regs(0);
  283. read_from_px_regs_altbank(0);
  284. if (argc > 2)
  285. goto my_usage;
  286. puts("Setting registers VCFGNE1, VBOOT, and VCTL\n");
  287. set_altbank();
  288. read_from_px_regs_altbank(1);
  289. puts("Resetting board to boot from the other bank....\n");
  290. set_px_go();
  291. }
  292. default:
  293. goto my_usage;
  294. }
  295. my_usage:
  296. puts("\nUsage: reset cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>\n");
  297. puts(" reset altbank [cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>]\n");
  298. puts(" reset altbank [wd]\n");
  299. puts("For example: reset cf 40 2.5 10\n");
  300. puts("See MPC8641HPCN Design Workbook for valid values of command line parameters.\n");
  301. }
  302. /*
  303. * get_board_sys_clk
  304. * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
  305. */
  306. unsigned long
  307. get_board_sys_clk(ulong dummy)
  308. {
  309. u8 i, go_bit, rd_clks;
  310. ulong val = 0;
  311. go_bit = in8(PIXIS_BASE + PIXIS_VCTL);
  312. go_bit &= 0x01;
  313. rd_clks = in8(PIXIS_BASE + PIXIS_VCFGEN0);
  314. rd_clks &= 0x1C;
  315. /*
  316. * Only if both go bit and the SCLK bit in VCFGEN0 are set
  317. * should we be using the AUX register. Remember, we also set the
  318. * GO bit to boot from the alternate bank on the on-board flash
  319. */
  320. if (go_bit) {
  321. if (rd_clks == 0x1c)
  322. i = in8(PIXIS_BASE + PIXIS_AUX);
  323. else
  324. i = in8(PIXIS_BASE + PIXIS_SPD);
  325. } else {
  326. i = in8(PIXIS_BASE + PIXIS_SPD);
  327. }
  328. i &= 0x07;
  329. switch (i) {
  330. case 0:
  331. val = 33000000;
  332. break;
  333. case 1:
  334. val = 40000000;
  335. break;
  336. case 2:
  337. val = 50000000;
  338. break;
  339. case 3:
  340. val = 66000000;
  341. break;
  342. case 4:
  343. val = 83000000;
  344. break;
  345. case 5:
  346. val = 100000000;
  347. break;
  348. case 6:
  349. val = 134000000;
  350. break;
  351. case 7:
  352. val = 166000000;
  353. break;
  354. }
  355. return val;
  356. }