sbc8641d.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /*
  2. * Copyright 2007 Wind River Systemes, Inc. <www.windriver.com>
  3. * Copyright 2007 Embedded Specialties, Inc.
  4. * Joe Hamman joe.hamman@embeddedspecialties.com
  5. *
  6. * Copyright 2004 Freescale Semiconductor.
  7. * Jeff Brown
  8. * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
  9. *
  10. * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
  11. *
  12. * See file CREDITS for list of people who contributed to this
  13. * project.
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License as
  17. * published by the Free Software Foundation; either version 2 of
  18. * the License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  28. * MA 02111-1307 USA
  29. */
  30. #include <common.h>
  31. #include <command.h>
  32. #include <pci.h>
  33. #include <asm/processor.h>
  34. #include <asm/immap_86xx.h>
  35. #include <asm/immap_fsl_pci.h>
  36. #include <spd_sdram.h>
  37. #include <libfdt.h>
  38. #include <fdt_support.h>
  39. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  40. extern void ddr_enable_ecc (unsigned int dram_size);
  41. #endif
  42. void sdram_init (void);
  43. long int fixed_sdram (void);
  44. int board_early_init_f (void)
  45. {
  46. return 0;
  47. }
  48. int checkboard (void)
  49. {
  50. puts ("Board: Wind River SBC8641D\n");
  51. return 0;
  52. }
  53. long int initdram (int board_type)
  54. {
  55. long dram_size = 0;
  56. #if defined(CONFIG_SPD_EEPROM)
  57. dram_size = spd_sdram ();
  58. #else
  59. dram_size = fixed_sdram ();
  60. #endif
  61. #if defined(CFG_RAMBOOT)
  62. puts (" DDR: ");
  63. return dram_size;
  64. #endif
  65. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  66. /*
  67. * Initialize and enable DDR ECC.
  68. */
  69. ddr_enable_ecc (dram_size);
  70. #endif
  71. puts (" DDR: ");
  72. return dram_size;
  73. }
  74. #if defined(CFG_DRAM_TEST)
  75. int testdram (void)
  76. {
  77. uint *pstart = (uint *) CFG_MEMTEST_START;
  78. uint *pend = (uint *) CFG_MEMTEST_END;
  79. uint *p;
  80. puts ("SDRAM test phase 1:\n");
  81. for (p = pstart; p < pend; p++)
  82. *p = 0xaaaaaaaa;
  83. for (p = pstart; p < pend; p++) {
  84. if (*p != 0xaaaaaaaa) {
  85. printf ("SDRAM test fails at: %08x\n", (uint) p);
  86. return 1;
  87. }
  88. }
  89. puts ("SDRAM test phase 2:\n");
  90. for (p = pstart; p < pend; p++)
  91. *p = 0x55555555;
  92. for (p = pstart; p < pend; p++) {
  93. if (*p != 0x55555555) {
  94. printf ("SDRAM test fails at: %08x\n", (uint) p);
  95. return 1;
  96. }
  97. }
  98. puts ("SDRAM test passed.\n");
  99. return 0;
  100. }
  101. #endif
  102. #if !defined(CONFIG_SPD_EEPROM)
  103. /*
  104. * Fixed sdram init -- doesn't use serial presence detect.
  105. */
  106. long int fixed_sdram (void)
  107. {
  108. #if !defined(CFG_RAMBOOT)
  109. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  110. volatile ccsr_ddr_t *ddr = &immap->im_ddr1;
  111. ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
  112. ddr->cs1_bnds = CFG_DDR_CS1_BNDS;
  113. ddr->cs2_bnds = CFG_DDR_CS2_BNDS;
  114. ddr->cs3_bnds = CFG_DDR_CS3_BNDS;
  115. ddr->cs0_config = CFG_DDR_CS0_CONFIG;
  116. ddr->cs1_config = CFG_DDR_CS1_CONFIG;
  117. ddr->cs2_config = CFG_DDR_CS2_CONFIG;
  118. ddr->cs3_config = CFG_DDR_CS3_CONFIG;
  119. ddr->ext_refrec = CFG_DDR_EXT_REFRESH;
  120. ddr->timing_cfg_0 = CFG_DDR_TIMING_0;
  121. ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
  122. ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
  123. ddr->sdram_cfg_1 = CFG_DDR_CFG_1A;
  124. ddr->sdram_cfg_2 = CFG_DDR_CFG_2;
  125. ddr->sdram_mode_1 = CFG_DDR_MODE_1;
  126. ddr->sdram_mode_2 = CFG_DDR_MODE_2;
  127. ddr->sdram_mode_cntl = CFG_DDR_MODE_CTL;
  128. ddr->sdram_interval = CFG_DDR_INTERVAL;
  129. ddr->sdram_data_init = CFG_DDR_DATA_INIT;
  130. ddr->sdram_clk_cntl = CFG_DDR_CLK_CTRL;
  131. asm ("sync;isync");
  132. udelay (500);
  133. ddr->sdram_cfg_1 = CFG_DDR_CFG_1B;
  134. asm ("sync; isync");
  135. udelay (500);
  136. ddr = &immap->im_ddr2;
  137. ddr->cs0_bnds = CFG_DDR2_CS0_BNDS;
  138. ddr->cs1_bnds = CFG_DDR2_CS1_BNDS;
  139. ddr->cs2_bnds = CFG_DDR2_CS2_BNDS;
  140. ddr->cs3_bnds = CFG_DDR2_CS3_BNDS;
  141. ddr->cs0_config = CFG_DDR2_CS0_CONFIG;
  142. ddr->cs1_config = CFG_DDR2_CS1_CONFIG;
  143. ddr->cs2_config = CFG_DDR2_CS2_CONFIG;
  144. ddr->cs3_config = CFG_DDR2_CS3_CONFIG;
  145. ddr->ext_refrec = CFG_DDR2_EXT_REFRESH;
  146. ddr->timing_cfg_0 = CFG_DDR2_TIMING_0;
  147. ddr->timing_cfg_1 = CFG_DDR2_TIMING_1;
  148. ddr->timing_cfg_2 = CFG_DDR2_TIMING_2;
  149. ddr->sdram_cfg_1 = CFG_DDR2_CFG_1A;
  150. ddr->sdram_cfg_2 = CFG_DDR2_CFG_2;
  151. ddr->sdram_mode_1 = CFG_DDR2_MODE_1;
  152. ddr->sdram_mode_2 = CFG_DDR2_MODE_2;
  153. ddr->sdram_mode_cntl = CFG_DDR2_MODE_CTL;
  154. ddr->sdram_interval = CFG_DDR2_INTERVAL;
  155. ddr->sdram_data_init = CFG_DDR2_DATA_INIT;
  156. ddr->sdram_clk_cntl = CFG_DDR2_CLK_CTRL;
  157. asm ("sync;isync");
  158. udelay (500);
  159. ddr->sdram_cfg_1 = CFG_DDR2_CFG_1B;
  160. asm ("sync; isync");
  161. udelay (500);
  162. #endif
  163. return CFG_SDRAM_SIZE * 1024 * 1024;
  164. }
  165. #endif /* !defined(CONFIG_SPD_EEPROM) */
  166. #if defined(CONFIG_PCI)
  167. /*
  168. * Initialize PCI Devices, report devices found.
  169. */
  170. #ifndef CONFIG_PCI_PNP
  171. static struct pci_config_table pci_fsl86xxads_config_table[] = {
  172. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  173. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  174. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  175. PCI_ENET0_MEMADDR,
  176. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER}},
  177. {}
  178. };
  179. #endif
  180. static struct pci_controller pci1_hose = {
  181. #ifndef CONFIG_PCI_PNP
  182. config_table:pci_mpc86xxcts_config_table
  183. #endif
  184. };
  185. #endif /* CONFIG_PCI */
  186. #ifdef CONFIG_PCI2
  187. static struct pci_controller pci2_hose;
  188. #endif /* CONFIG_PCI2 */
  189. int first_free_busno = 0;
  190. void pci_init_board(void)
  191. {
  192. volatile immap_t *immap = (immap_t *) CFG_CCSRBAR;
  193. volatile ccsr_gur_t *gur = &immap->im_gur;
  194. uint devdisr = gur->devdisr;
  195. uint io_sel = (gur->pordevsr & MPC8641_PORDEVSR_IO_SEL)
  196. >> MPC8641_PORDEVSR_IO_SEL_SHIFT;
  197. #ifdef CONFIG_PCI1
  198. {
  199. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI1_ADDR;
  200. extern void fsl_pci_init(struct pci_controller *hose);
  201. struct pci_controller *hose = &pci1_hose;
  202. #ifdef DEBUG
  203. uint host1_agent = (gur->porbmsr & MPC8641_PORBMSR_HA)
  204. >> MPC8641_PORBMSR_HA_SHIFT;
  205. uint pex1_agent = (host1_agent == 0) || (host1_agent == 1);
  206. #endif
  207. if ((io_sel == 2 || io_sel == 3 || io_sel == 5
  208. || io_sel == 6 || io_sel == 7 || io_sel == 0xF)
  209. && !(devdisr & MPC86xx_DEVDISR_PCIEX1)) {
  210. debug("PCI-EXPRESS 1: %s \n", pex1_agent ? "Agent" : "Host");
  211. debug("0x%08x=0x%08x ", &pci->pme_msg_det, pci->pme_msg_det);
  212. if (pci->pme_msg_det) {
  213. pci->pme_msg_det = 0xffffffff;
  214. debug(" with errors. Clearing. Now 0x%08x",
  215. pci->pme_msg_det);
  216. }
  217. debug("\n");
  218. /* inbound */
  219. pci_set_region(hose->regions + 0,
  220. CFG_PCI_MEMORY_BUS,
  221. CFG_PCI_MEMORY_PHYS,
  222. CFG_PCI_MEMORY_SIZE,
  223. PCI_REGION_MEM | PCI_REGION_MEMORY);
  224. /* outbound memory */
  225. pci_set_region(hose->regions + 1,
  226. CFG_PCI1_MEM_BASE,
  227. CFG_PCI1_MEM_PHYS,
  228. CFG_PCI1_MEM_SIZE,
  229. PCI_REGION_MEM);
  230. /* outbound io */
  231. pci_set_region(hose->regions + 2,
  232. CFG_PCI1_IO_BASE,
  233. CFG_PCI1_IO_PHYS,
  234. CFG_PCI1_IO_SIZE,
  235. PCI_REGION_IO);
  236. hose->region_count = 3;
  237. hose->first_busno=first_free_busno;
  238. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  239. fsl_pci_init(hose);
  240. first_free_busno=hose->last_busno+1;
  241. printf (" PCI-EXPRESS 1 on bus %02x - %02x\n",
  242. hose->first_busno,hose->last_busno);
  243. } else {
  244. puts("PCI-EXPRESS 1: Disabled\n");
  245. }
  246. }
  247. #else
  248. puts("PCI-EXPRESS1: Disabled\n");
  249. #endif /* CONFIG_PCI1 */
  250. #ifdef CONFIG_PCI2
  251. {
  252. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI2_ADDR;
  253. extern void fsl_pci_init(struct pci_controller *hose);
  254. struct pci_controller *hose = &pci2_hose;
  255. /* inbound */
  256. pci_set_region(hose->regions + 0,
  257. CFG_PCI_MEMORY_BUS,
  258. CFG_PCI_MEMORY_PHYS,
  259. CFG_PCI_MEMORY_SIZE,
  260. PCI_REGION_MEM | PCI_REGION_MEMORY);
  261. /* outbound memory */
  262. pci_set_region(hose->regions + 1,
  263. CFG_PCI2_MEM_BASE,
  264. CFG_PCI2_MEM_PHYS,
  265. CFG_PCI2_MEM_SIZE,
  266. PCI_REGION_MEM);
  267. /* outbound io */
  268. pci_set_region(hose->regions + 2,
  269. CFG_PCI2_IO_BASE,
  270. CFG_PCI2_IO_PHYS,
  271. CFG_PCI2_IO_SIZE,
  272. PCI_REGION_IO);
  273. hose->region_count = 3;
  274. hose->first_busno=first_free_busno;
  275. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  276. fsl_pci_init(hose);
  277. first_free_busno=hose->last_busno+1;
  278. printf (" PCI-EXPRESS 2 on bus %02x - %02x\n",
  279. hose->first_busno,hose->last_busno);
  280. }
  281. #else
  282. puts("PCI-EXPRESS 2: Disabled\n");
  283. #endif /* CONFIG_PCI2 */
  284. }
  285. #if defined(CONFIG_OF_BOARD_SETUP)
  286. void
  287. ft_board_setup (void *blob, bd_t *bd)
  288. {
  289. int node, tmp[2];
  290. const char *path;
  291. ft_cpu_setup(blob, bd);
  292. node = fdt_path_offset(blob, "/aliases");
  293. tmp[0] = 0;
  294. if (node >= 0) {
  295. #ifdef CONFIG_PCI1
  296. path = fdt_getprop(blob, node, "pci0", NULL);
  297. if (path) {
  298. tmp[1] = pci1_hose.last_busno - pci1_hose.first_busno;
  299. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  300. }
  301. #endif
  302. #ifdef CONFIG_PCI2
  303. path = fdt_getprop(blob, node, "pci1", NULL);
  304. if (path) {
  305. tmp[1] = pci2_hose.last_busno - pci2_hose.first_busno;
  306. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  307. }
  308. #endif
  309. }
  310. }
  311. #endif
  312. void sbc8641d_reset_board (void)
  313. {
  314. puts ("Resetting board....\n");
  315. }
  316. /*
  317. * get_board_sys_clk
  318. * Clock is fixed at 1GHz on this board. Used for CONFIG_SYS_CLK_FREQ
  319. */
  320. unsigned long get_board_sys_clk (ulong dummy)
  321. {
  322. int i;
  323. ulong val = 0;
  324. i = 5;
  325. i &= 0x07;
  326. switch (i) {
  327. case 0:
  328. val = 33000000;
  329. break;
  330. case 1:
  331. val = 40000000;
  332. break;
  333. case 2:
  334. val = 50000000;
  335. break;
  336. case 3:
  337. val = 66000000;
  338. break;
  339. case 4:
  340. val = 83000000;
  341. break;
  342. case 5:
  343. val = 100000000;
  344. break;
  345. case 6:
  346. val = 134000000;
  347. break;
  348. case 7:
  349. val = 166000000;
  350. break;
  351. }
  352. return val;
  353. }