atum8548.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. /*
  2. * Copyright 2007
  3. * Robert Lazarski, Instituto Atlantico, robertlazarski@gmail.com
  4. *
  5. * Copyright 2007 Freescale Semiconductor, Inc.
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <command.h>
  27. #include <pci.h>
  28. #include <asm/processor.h>
  29. #include <asm/immap_85xx.h>
  30. #include <asm/fsl_pci.h>
  31. #include <asm/fsl_ddr_sdram.h>
  32. #include <asm/io.h>
  33. #include <asm/mmu.h>
  34. #include <spd_sdram.h>
  35. #include <miiphy.h>
  36. #include <libfdt.h>
  37. #include <fdt_support.h>
  38. long int fixed_sdram(void);
  39. int board_early_init_f (void)
  40. {
  41. return 0;
  42. }
  43. int checkboard (void)
  44. {
  45. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  46. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  47. volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
  48. if ((uint)&gur->porpllsr != 0xe00e0000) {
  49. printf("immap size error %lx\n",(ulong)&gur->porpllsr);
  50. }
  51. printf ("Board: ATUM8548\n");
  52. lbc->ltesr = 0xffffffff; /* Clear LBC error interrupts */
  53. lbc->lteir = 0xffffffff; /* Enable LBC error interrupts */
  54. ecm->eedr = 0xffffffff; /* Clear ecm errors */
  55. ecm->eeer = 0xffffffff; /* Enable ecm errors */
  56. return 0;
  57. }
  58. #if !defined(CONFIG_SPD_EEPROM)
  59. /*************************************************************************
  60. * fixed sdram init -- doesn't use serial presence detect.
  61. ************************************************************************/
  62. long int fixed_sdram (void)
  63. {
  64. volatile ccsr_ddr_t *ddr= (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
  65. ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
  66. ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
  67. ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
  68. ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  69. ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  70. ddr->sdram_mode = CONFIG_SYS_DDR_MODE;
  71. ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  72. #if defined (CONFIG_DDR_ECC)
  73. ddr->err_disable = 0x0000000D;
  74. ddr->err_sbe = 0x00ff0000;
  75. #endif
  76. asm("sync;isync;msync");
  77. udelay(500);
  78. #if defined (CONFIG_DDR_ECC)
  79. /* Enable ECC checking */
  80. ddr->sdram_cfg = (CONFIG_SYS_DDR_CONTROL | 0x20000000);
  81. #else
  82. ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
  83. #endif
  84. asm("sync; isync; msync");
  85. udelay(500);
  86. return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
  87. }
  88. #endif /* !defined(CONFIG_SPD_EEPROM) */
  89. phys_size_t
  90. initdram(int board_type)
  91. {
  92. long dram_size = 0;
  93. puts("Initializing\n");
  94. #if defined(CONFIG_SPD_EEPROM)
  95. puts("fsl_ddr_sdram\n");
  96. dram_size = fsl_ddr_sdram();
  97. dram_size = setup_ddr_tlbs(dram_size / 0x100000);
  98. dram_size *= 0x100000;
  99. #else
  100. puts("fixed_sdram\n");
  101. dram_size = fixed_sdram ();
  102. #endif
  103. puts(" DDR: ");
  104. return dram_size;
  105. }
  106. #if defined(CONFIG_SYS_DRAM_TEST)
  107. int
  108. testdram(void)
  109. {
  110. uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
  111. uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
  112. uint *p;
  113. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  114. CONFIG_SYS_MEMTEST_START,
  115. CONFIG_SYS_MEMTEST_END);
  116. printf("DRAM test phase 1:\n");
  117. for (p = pstart; p < pend; p++) {
  118. printf ("DRAM test attempting to write 0xaaaaaaaa at: %08x\n", (uint) p);
  119. *p = 0xaaaaaaaa;
  120. }
  121. for (p = pstart; p < pend; p++) {
  122. if (*p != 0xaaaaaaaa) {
  123. printf ("DRAM test fails at: %08x\n", (uint) p);
  124. return 1;
  125. }
  126. }
  127. printf("DRAM test phase 2:\n");
  128. for (p = pstart; p < pend; p++)
  129. *p = 0x55555555;
  130. for (p = pstart; p < pend; p++) {
  131. if (*p != 0x55555555) {
  132. printf ("DRAM test fails at: %08x\n", (uint) p);
  133. return 1;
  134. }
  135. }
  136. printf("DRAM test passed.\n");
  137. return 0;
  138. }
  139. #endif
  140. #ifdef CONFIG_PCI1
  141. static struct pci_controller pci1_hose;
  142. #endif
  143. #ifdef CONFIG_PCI2
  144. static struct pci_controller pci2_hose;
  145. #endif
  146. #ifdef CONFIG_PCIE1
  147. static struct pci_controller pcie1_hose;
  148. #endif
  149. int first_free_busno=0;
  150. void
  151. pci_init_board(void)
  152. {
  153. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  154. uint devdisr = gur->devdisr;
  155. uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  156. uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  157. debug (" pci_init_board: devdisr=%x, io_sel=%x, host_agent=%x\n",
  158. devdisr, io_sel, host_agent);
  159. /* explicitly set 'Clock out select register' to echo SYSCLK input to our CPLD */
  160. gur->clkocr |= MPC85xx_ATUM_CLKOCR;
  161. if (io_sel & 1) {
  162. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII1_DIS))
  163. printf (" eTSEC1 is in sgmii mode.\n");
  164. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII2_DIS))
  165. printf (" eTSEC2 is in sgmii mode.\n");
  166. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII3_DIS))
  167. printf (" eTSEC3 is in sgmii mode.\n");
  168. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII4_DIS))
  169. printf (" eTSEC4 is in sgmii mode.\n");
  170. }
  171. #ifdef CONFIG_PCIE1
  172. {
  173. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
  174. struct pci_controller *hose = &pcie1_hose;
  175. int pcie_ep = (host_agent == 5);
  176. int pcie_configured = io_sel & 6;
  177. struct pci_region *r = hose->regions;
  178. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  179. printf ("\n PCIE1 connected to slot as %s (base address %x)",
  180. pcie_ep ? "End Point" : "Root Complex",
  181. (uint)pci);
  182. if (pci->pme_msg_det) {
  183. pci->pme_msg_det = 0xffffffff;
  184. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  185. }
  186. printf ("\n");
  187. /* inbound */
  188. r += fsl_pci_setup_inbound_windows(r);
  189. /* outbound memory */
  190. pci_set_region(r++,
  191. CONFIG_SYS_PCIE1_MEM_BASE,
  192. CONFIG_SYS_PCIE1_MEM_PHYS,
  193. CONFIG_SYS_PCIE1_MEM_SIZE,
  194. PCI_REGION_MEM);
  195. /* outbound io */
  196. pci_set_region(r++,
  197. CONFIG_SYS_PCIE1_IO_BASE,
  198. CONFIG_SYS_PCIE1_IO_PHYS,
  199. CONFIG_SYS_PCIE1_IO_SIZE,
  200. PCI_REGION_IO);
  201. #ifdef CONFIG_SYS_PCIE1_MEM_BASE2
  202. /* outbound memory */
  203. pci_set_region(r++,
  204. CONFIG_SYS_PCIE1_MEM_BASE2,
  205. CONFIG_SYS_PCIE1_MEM_PHYS2,
  206. CONFIG_SYS_PCIE1_MEM_SIZE2,
  207. PCI_REGION_MEM);
  208. #endif
  209. hose->region_count = r - hose->regions;
  210. hose->first_busno=first_free_busno;
  211. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  212. fsl_pci_init(hose);
  213. first_free_busno=hose->last_busno+1;
  214. printf(" PCIE1 on bus %02x - %02x\n",
  215. hose->first_busno,hose->last_busno);
  216. } else {
  217. printf (" PCIE1: disabled\n");
  218. }
  219. }
  220. #else
  221. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  222. #endif
  223. #ifdef CONFIG_PCI1
  224. {
  225. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI1_ADDR;
  226. struct pci_controller *hose = &pci1_hose;
  227. struct pci_region *r = hose->regions;
  228. uint pci_agent = (host_agent == 6);
  229. uint pci_speed = 33333000; /*get_clock_freq (); PCI PSPEED in [4:5] */
  230. uint pci_32 = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32; /* PORDEVSR[15] */
  231. uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB; /* PORDEVSR[14] */
  232. uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD; /* PORPLLSR[16] */
  233. if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
  234. printf ("\n PCI1: %d bit, %s MHz, %s, %s, %s (base address %x)\n",
  235. (pci_32) ? 32 : 64,
  236. (pci_speed == 33333000) ? "33" :
  237. (pci_speed == 66666000) ? "66" : "unknown",
  238. pci_clk_sel ? "sync" : "async",
  239. pci_agent ? "agent" : "host",
  240. pci_arb ? "arbiter" : "external-arbiter",
  241. (uint)pci
  242. );
  243. /* inbound */
  244. r += fsl_pci_setup_inbound_windows(r);
  245. /* outbound memory */
  246. pci_set_region(r++,
  247. CONFIG_SYS_PCI1_MEM_BASE,
  248. CONFIG_SYS_PCI1_MEM_PHYS,
  249. CONFIG_SYS_PCI1_MEM_SIZE,
  250. PCI_REGION_MEM);
  251. /* outbound io */
  252. pci_set_region(r++,
  253. CONFIG_SYS_PCI1_IO_BASE,
  254. CONFIG_SYS_PCI1_IO_PHYS,
  255. CONFIG_SYS_PCI1_IO_SIZE,
  256. PCI_REGION_IO);
  257. hose->region_count = r - hose->regions;
  258. hose->first_busno=first_free_busno;
  259. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  260. fsl_pci_init(hose);
  261. first_free_busno=hose->last_busno+1;
  262. printf ("PCI1 on bus %02x - %02x\n",
  263. hose->first_busno,hose->last_busno);
  264. } else {
  265. printf (" PCI1: disabled\n");
  266. }
  267. }
  268. #else
  269. gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
  270. #endif
  271. #ifdef CONFIG_PCI2
  272. {
  273. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI2_ADDR;
  274. struct pci_controller *hose = &pci2_hose;
  275. struct pci_region *r = hose->regions;
  276. if (!(devdisr & MPC85xx_DEVDISR_PCI2)) {
  277. r += fsl_pci_setup_inbound_windows(r);
  278. pci_set_region(r++,
  279. CONFIG_SYS_PCI2_MEM_BASE,
  280. CONFIG_SYS_PCI2_MEM_PHYS,
  281. CONFIG_SYS_PCI2_MEM_SIZE,
  282. PCI_REGION_MEM);
  283. pci_set_region(r++,
  284. CONFIG_SYS_PCI2_IO_BASE,
  285. CONFIG_SYS_PCI2_IO_PHYS,
  286. CONFIG_SYS_PCI2_IO_SIZE,
  287. PCI_REGION_IO);
  288. hose->region_count = r - hose->regions;
  289. hose->first_busno=first_free_busno;
  290. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  291. fsl_pci_init(hose);
  292. first_free_busno=hose->last_busno+1;
  293. printf ("PCI2 on bus %02x - %02x\n",
  294. hose->first_busno,hose->last_busno);
  295. } else {
  296. printf (" PCI2: disabled\n");
  297. }
  298. }
  299. #else
  300. gur->devdisr |= MPC85xx_DEVDISR_PCI2;
  301. #endif
  302. }
  303. int last_stage_init(void)
  304. {
  305. int ic = icache_status ();
  306. printf ("icache_status: %d\n", ic);
  307. return 0;
  308. }
  309. #if defined(CONFIG_OF_BOARD_SETUP)
  310. void ft_board_setup(void *blob, bd_t *bd)
  311. {
  312. ft_cpu_setup(blob, bd);
  313. #ifdef CONFIG_PCI1
  314. ft_fsl_pci_setup(blob, "pci0", &pci1_hose);
  315. #endif
  316. #ifdef CONFIG_PCI2
  317. ft_fsl_pci_setup(blob, "pci1", &pci2_hose);
  318. #endif
  319. #ifdef CONFIG_PCIE1
  320. ft_fsl_pci_setup(blob, "pci2", &pcie1_hose);
  321. #endif
  322. }
  323. #endif