sbc8641d.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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.h>
  37. #if defined(CONFIG_OF_FLAT_TREE)
  38. #include <ft_build.h>
  39. extern void ft_cpu_setup (void *blob, bd_t * bd);
  40. #endif
  41. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  42. extern void ddr_enable_ecc (unsigned int dram_size);
  43. #endif
  44. #if defined(CONFIG_SPD_EEPROM)
  45. #include "spd_sdram.h"
  46. #endif
  47. void sdram_init (void);
  48. long int fixed_sdram (void);
  49. int board_early_init_f (void)
  50. {
  51. return 0;
  52. }
  53. int checkboard (void)
  54. {
  55. puts ("Board: Wind River SBC8641D\n");
  56. return 0;
  57. }
  58. long int initdram (int board_type)
  59. {
  60. long dram_size = 0;
  61. #if defined(CONFIG_SPD_EEPROM)
  62. dram_size = spd_sdram ();
  63. #else
  64. dram_size = fixed_sdram ();
  65. #endif
  66. #if defined(CFG_RAMBOOT)
  67. puts (" DDR: ");
  68. return dram_size;
  69. #endif
  70. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  71. /*
  72. * Initialize and enable DDR ECC.
  73. */
  74. ddr_enable_ecc (dram_size);
  75. #endif
  76. puts (" DDR: ");
  77. return dram_size;
  78. }
  79. #if defined(CFG_DRAM_TEST)
  80. int testdram (void)
  81. {
  82. uint *pstart = (uint *) CFG_MEMTEST_START;
  83. uint *pend = (uint *) CFG_MEMTEST_END;
  84. uint *p;
  85. puts ("SDRAM test phase 1:\n");
  86. for (p = pstart; p < pend; p++)
  87. *p = 0xaaaaaaaa;
  88. for (p = pstart; p < pend; p++) {
  89. if (*p != 0xaaaaaaaa) {
  90. printf ("SDRAM test fails at: %08x\n", (uint) p);
  91. return 1;
  92. }
  93. }
  94. puts ("SDRAM test phase 2:\n");
  95. for (p = pstart; p < pend; p++)
  96. *p = 0x55555555;
  97. for (p = pstart; p < pend; p++) {
  98. if (*p != 0x55555555) {
  99. printf ("SDRAM test fails at: %08x\n", (uint) p);
  100. return 1;
  101. }
  102. }
  103. puts ("SDRAM test passed.\n");
  104. return 0;
  105. }
  106. #endif
  107. #if !defined(CONFIG_SPD_EEPROM)
  108. /*
  109. * Fixed sdram init -- doesn't use serial presence detect.
  110. */
  111. long int fixed_sdram (void)
  112. {
  113. #if !defined(CFG_RAMBOOT)
  114. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  115. volatile ccsr_ddr_t *ddr = &immap->im_ddr1;
  116. ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
  117. ddr->cs1_bnds = CFG_DDR_CS1_BNDS;
  118. ddr->cs2_bnds = CFG_DDR_CS2_BNDS;
  119. ddr->cs3_bnds = CFG_DDR_CS3_BNDS;
  120. ddr->cs0_config = CFG_DDR_CS0_CONFIG;
  121. ddr->cs1_config = CFG_DDR_CS1_CONFIG;
  122. ddr->cs2_config = CFG_DDR_CS2_CONFIG;
  123. ddr->cs3_config = CFG_DDR_CS3_CONFIG;
  124. ddr->ext_refrec = CFG_DDR_EXT_REFRESH;
  125. ddr->timing_cfg_0 = CFG_DDR_TIMING_0;
  126. ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
  127. ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
  128. ddr->sdram_cfg_1 = CFG_DDR_CFG_1A;
  129. ddr->sdram_cfg_2 = CFG_DDR_CFG_2;
  130. ddr->sdram_mode_1 = CFG_DDR_MODE_1;
  131. ddr->sdram_mode_2 = CFG_DDR_MODE_2;
  132. ddr->sdram_mode_cntl = CFG_DDR_MODE_CTL;
  133. ddr->sdram_interval = CFG_DDR_INTERVAL;
  134. ddr->sdram_data_init = CFG_DDR_DATA_INIT;
  135. ddr->sdram_clk_cntl = CFG_DDR_CLK_CTRL;
  136. asm ("sync;isync");
  137. udelay (500);
  138. ddr->sdram_cfg_1 = CFG_DDR_CFG_1B;
  139. asm ("sync; isync");
  140. udelay (500);
  141. ddr = &immap->im_ddr2;
  142. ddr->cs0_bnds = CFG_DDR2_CS0_BNDS;
  143. ddr->cs1_bnds = CFG_DDR2_CS1_BNDS;
  144. ddr->cs2_bnds = CFG_DDR2_CS2_BNDS;
  145. ddr->cs3_bnds = CFG_DDR2_CS3_BNDS;
  146. ddr->cs0_config = CFG_DDR2_CS0_CONFIG;
  147. ddr->cs1_config = CFG_DDR2_CS1_CONFIG;
  148. ddr->cs2_config = CFG_DDR2_CS2_CONFIG;
  149. ddr->cs3_config = CFG_DDR2_CS3_CONFIG;
  150. ddr->ext_refrec = CFG_DDR2_EXT_REFRESH;
  151. ddr->timing_cfg_0 = CFG_DDR2_TIMING_0;
  152. ddr->timing_cfg_1 = CFG_DDR2_TIMING_1;
  153. ddr->timing_cfg_2 = CFG_DDR2_TIMING_2;
  154. ddr->sdram_cfg_1 = CFG_DDR2_CFG_1A;
  155. ddr->sdram_cfg_2 = CFG_DDR2_CFG_2;
  156. ddr->sdram_mode_1 = CFG_DDR2_MODE_1;
  157. ddr->sdram_mode_2 = CFG_DDR2_MODE_2;
  158. ddr->sdram_mode_cntl = CFG_DDR2_MODE_CTL;
  159. ddr->sdram_interval = CFG_DDR2_INTERVAL;
  160. ddr->sdram_data_init = CFG_DDR2_DATA_INIT;
  161. ddr->sdram_clk_cntl = CFG_DDR2_CLK_CTRL;
  162. asm ("sync;isync");
  163. udelay (500);
  164. ddr->sdram_cfg_1 = CFG_DDR2_CFG_1B;
  165. asm ("sync; isync");
  166. udelay (500);
  167. #endif
  168. return CFG_SDRAM_SIZE * 1024 * 1024;
  169. }
  170. #endif /* !defined(CONFIG_SPD_EEPROM) */
  171. #if defined(CONFIG_PCI)
  172. /*
  173. * Initialize PCI Devices, report devices found.
  174. */
  175. #ifndef CONFIG_PCI_PNP
  176. static struct pci_config_table pci_fsl86xxads_config_table[] = {
  177. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  178. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  179. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  180. PCI_ENET0_MEMADDR,
  181. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER}},
  182. {}
  183. };
  184. #endif
  185. static struct pci_controller pci1_hose = {
  186. #ifndef CONFIG_PCI_PNP
  187. config_table:pci_mpc86xxcts_config_table
  188. #endif
  189. };
  190. #endif /* CONFIG_PCI */
  191. #ifdef CONFIG_PCI2
  192. static struct pci_controller pci2_hose;
  193. #endif /* CONFIG_PCI2 */
  194. int first_free_busno = 0;
  195. void pci_init_board(void)
  196. {
  197. volatile immap_t *immap = (immap_t *) CFG_CCSRBAR;
  198. volatile ccsr_gur_t *gur = &immap->im_gur;
  199. uint devdisr = gur->devdisr;
  200. uint io_sel = (gur->pordevsr & MPC86xx_PORDEVSR_IO_SEL) >> 16;
  201. #ifdef CONFIG_PCI1
  202. {
  203. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI1_ADDR;
  204. extern void fsl_pci_init(struct pci_controller *hose);
  205. struct pci_controller *hose = &pci1_hose;
  206. #ifdef DEBUG
  207. uint host1_agent = (gur->porbmsr & MPC86xx_PORBMSR_HA) >> 17;
  208. uint pex1_agent = (host1_agent == 0) || (host1_agent == 1);
  209. #endif
  210. if ((io_sel == 2 || io_sel == 3 || io_sel == 5
  211. || io_sel == 6 || io_sel == 7 || io_sel == 0xF)
  212. && !(devdisr & MPC86xx_DEVDISR_PCIEX1)) {
  213. debug("PCI-EXPRESS 1: %s \n", pex1_agent ? "Agent" : "Host");
  214. debug("0x%08x=0x%08x ", &pci->pme_msg_det, pci->pme_msg_det);
  215. if (pci->pme_msg_det) {
  216. pci->pme_msg_det = 0xffffffff;
  217. debug(" with errors. Clearing. Now 0x%08x",
  218. pci->pme_msg_det);
  219. }
  220. debug("\n");
  221. /* inbound */
  222. pci_set_region(hose->regions + 0,
  223. CFG_PCI_MEMORY_BUS,
  224. CFG_PCI_MEMORY_PHYS,
  225. CFG_PCI_MEMORY_SIZE,
  226. PCI_REGION_MEM | PCI_REGION_MEMORY);
  227. /* outbound memory */
  228. pci_set_region(hose->regions + 1,
  229. CFG_PCI1_MEM_BASE,
  230. CFG_PCI1_MEM_PHYS,
  231. CFG_PCI1_MEM_SIZE,
  232. PCI_REGION_MEM);
  233. /* outbound io */
  234. pci_set_region(hose->regions + 2,
  235. CFG_PCI1_IO_BASE,
  236. CFG_PCI1_IO_PHYS,
  237. CFG_PCI1_IO_SIZE,
  238. PCI_REGION_IO);
  239. hose->region_count = 3;
  240. hose->first_busno=first_free_busno;
  241. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  242. fsl_pci_init(hose);
  243. first_free_busno=hose->last_busno+1;
  244. printf (" PCI-EXPRESS 1 on bus %02x - %02x\n",
  245. hose->first_busno,hose->last_busno);
  246. } else {
  247. puts("PCI-EXPRESS 1: Disabled\n");
  248. }
  249. }
  250. #else
  251. puts("PCI-EXPRESS1: Disabled\n");
  252. #endif /* CONFIG_PCI1 */
  253. #ifdef CONFIG_PCI2
  254. {
  255. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI2_ADDR;
  256. extern void fsl_pci_init(struct pci_controller *hose);
  257. struct pci_controller *hose = &pci2_hose;
  258. /* inbound */
  259. pci_set_region(hose->regions + 0,
  260. CFG_PCI_MEMORY_BUS,
  261. CFG_PCI_MEMORY_PHYS,
  262. CFG_PCI_MEMORY_SIZE,
  263. PCI_REGION_MEM | PCI_REGION_MEMORY);
  264. /* outbound memory */
  265. pci_set_region(hose->regions + 1,
  266. CFG_PCI2_MEM_BASE,
  267. CFG_PCI2_MEM_PHYS,
  268. CFG_PCI2_MEM_SIZE,
  269. PCI_REGION_MEM);
  270. /* outbound io */
  271. pci_set_region(hose->regions + 2,
  272. CFG_PCI2_IO_BASE,
  273. CFG_PCI2_IO_PHYS,
  274. CFG_PCI2_IO_SIZE,
  275. PCI_REGION_IO);
  276. hose->region_count = 3;
  277. hose->first_busno=first_free_busno;
  278. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  279. fsl_pci_init(hose);
  280. first_free_busno=hose->last_busno+1;
  281. printf (" PCI-EXPRESS 2 on bus %02x - %02x\n",
  282. hose->first_busno,hose->last_busno);
  283. }
  284. #else
  285. puts("PCI-EXPRESS 2: Disabled\n");
  286. #endif /* CONFIG_PCI2 */
  287. }
  288. #if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
  289. void ft_board_setup (void *blob, bd_t * bd)
  290. {
  291. u32 *p;
  292. int len;
  293. ft_cpu_setup (blob, bd);
  294. p = ft_get_prop (blob, "/memory/reg", &len);
  295. if (p != NULL) {
  296. *p++ = cpu_to_be32 (bd->bi_memstart);
  297. *p = cpu_to_be32 (bd->bi_memsize);
  298. }
  299. }
  300. #endif
  301. void sbc8641d_reset_board (void)
  302. {
  303. puts ("Resetting board....\n");
  304. }
  305. /*
  306. * get_board_sys_clk
  307. * Clock is fixed at 1GHz on this board. Used for CONFIG_SYS_CLK_FREQ
  308. */
  309. unsigned long get_board_sys_clk (ulong dummy)
  310. {
  311. int i;
  312. ulong val = 0;
  313. i = 5;
  314. i &= 0x07;
  315. switch (i) {
  316. case 0:
  317. val = 33000000;
  318. break;
  319. case 1:
  320. val = 40000000;
  321. break;
  322. case 2:
  323. val = 50000000;
  324. break;
  325. case 3:
  326. val = 66000000;
  327. break;
  328. case 4:
  329. val = 83000000;
  330. break;
  331. case 5:
  332. val = 100000000;
  333. break;
  334. case 6:
  335. val = 134000000;
  336. break;
  337. case 7:
  338. val = 166000000;
  339. break;
  340. }
  341. return val;
  342. }