atum8548.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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/immap_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. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  39. extern void ddr_enable_ecc(unsigned int dram_size);
  40. #endif
  41. long int fixed_sdram(void);
  42. int board_early_init_f (void)
  43. {
  44. return 0;
  45. }
  46. int checkboard (void)
  47. {
  48. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  49. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  50. volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
  51. if ((uint)&gur->porpllsr != 0xe00e0000) {
  52. printf("immap size error %lx\n",(ulong)&gur->porpllsr);
  53. }
  54. printf ("Board: ATUM8548\n");
  55. lbc->ltesr = 0xffffffff; /* Clear LBC error interrupts */
  56. lbc->lteir = 0xffffffff; /* Enable LBC error interrupts */
  57. ecm->eedr = 0xffffffff; /* Clear ecm errors */
  58. ecm->eeer = 0xffffffff; /* Enable ecm errors */
  59. return 0;
  60. }
  61. #if !defined(CONFIG_SPD_EEPROM)
  62. /*************************************************************************
  63. * fixed sdram init -- doesn't use serial presence detect.
  64. ************************************************************************/
  65. long int fixed_sdram (void)
  66. {
  67. volatile ccsr_ddr_t *ddr= (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
  68. ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
  69. ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
  70. ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
  71. ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  72. ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  73. ddr->sdram_mode = CONFIG_SYS_DDR_MODE;
  74. ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  75. #if defined (CONFIG_DDR_ECC)
  76. ddr->err_disable = 0x0000000D;
  77. ddr->err_sbe = 0x00ff0000;
  78. #endif
  79. asm("sync;isync;msync");
  80. udelay(500);
  81. #if defined (CONFIG_DDR_ECC)
  82. /* Enable ECC checking */
  83. ddr->sdram_cfg = (CONFIG_SYS_DDR_CONTROL | 0x20000000);
  84. #else
  85. ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
  86. #endif
  87. asm("sync; isync; msync");
  88. udelay(500);
  89. return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
  90. }
  91. #endif /* !defined(CONFIG_SPD_EEPROM) */
  92. phys_size_t
  93. initdram(int board_type)
  94. {
  95. long dram_size = 0;
  96. puts("Initializing\n");
  97. #if defined(CONFIG_SPD_EEPROM)
  98. puts("fsl_ddr_sdram\n");
  99. dram_size = fsl_ddr_sdram();
  100. dram_size = setup_ddr_tlbs(dram_size / 0x100000);
  101. dram_size *= 0x100000;
  102. #else
  103. puts("fixed_sdram\n");
  104. dram_size = fixed_sdram ();
  105. #endif
  106. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  107. /*
  108. * Initialize and enable DDR ECC.
  109. */
  110. ddr_enable_ecc(dram_size);
  111. #endif
  112. puts(" DDR: ");
  113. return dram_size;
  114. }
  115. #if defined(CONFIG_SYS_DRAM_TEST)
  116. int
  117. testdram(void)
  118. {
  119. uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
  120. uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
  121. uint *p;
  122. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  123. CONFIG_SYS_MEMTEST_START,
  124. CONFIG_SYS_MEMTEST_END);
  125. printf("DRAM test phase 1:\n");
  126. for (p = pstart; p < pend; p++) {
  127. printf ("DRAM test attempting to write 0xaaaaaaaa at: %08x\n", (uint) p);
  128. *p = 0xaaaaaaaa;
  129. }
  130. for (p = pstart; p < pend; p++) {
  131. if (*p != 0xaaaaaaaa) {
  132. printf ("DRAM test fails at: %08x\n", (uint) p);
  133. return 1;
  134. }
  135. }
  136. printf("DRAM test phase 2:\n");
  137. for (p = pstart; p < pend; p++)
  138. *p = 0x55555555;
  139. for (p = pstart; p < pend; p++) {
  140. if (*p != 0x55555555) {
  141. printf ("DRAM test fails at: %08x\n", (uint) p);
  142. return 1;
  143. }
  144. }
  145. printf("DRAM test passed.\n");
  146. return 0;
  147. }
  148. #endif
  149. #ifdef CONFIG_PCI1
  150. static struct pci_controller pci1_hose;
  151. #endif
  152. #ifdef CONFIG_PCI2
  153. static struct pci_controller pci2_hose;
  154. #endif
  155. #ifdef CONFIG_PCIE1
  156. static struct pci_controller pcie1_hose;
  157. #endif
  158. int first_free_busno=0;
  159. extern int fsl_pci_setup_inbound_windows(struct pci_region *r);
  160. extern void fsl_pci_init(struct pci_controller *hose);
  161. void
  162. pci_init_board(void)
  163. {
  164. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  165. uint devdisr = gur->devdisr;
  166. uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  167. uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  168. debug (" pci_init_board: devdisr=%x, io_sel=%x, host_agent=%x\n",
  169. devdisr, io_sel, host_agent);
  170. /* explicitly set 'Clock out select register' to echo SYSCLK input to our CPLD */
  171. gur->clkocr |= MPC85xx_ATUM_CLKOCR;
  172. if (io_sel & 1) {
  173. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII1_DIS))
  174. printf (" eTSEC1 is in sgmii mode.\n");
  175. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII2_DIS))
  176. printf (" eTSEC2 is in sgmii mode.\n");
  177. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII3_DIS))
  178. printf (" eTSEC3 is in sgmii mode.\n");
  179. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII4_DIS))
  180. printf (" eTSEC4 is in sgmii mode.\n");
  181. }
  182. #ifdef CONFIG_PCIE1
  183. {
  184. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
  185. struct pci_controller *hose = &pcie1_hose;
  186. int pcie_ep = (host_agent == 5);
  187. int pcie_configured = io_sel & 6;
  188. struct pci_region *r = hose->regions;
  189. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  190. printf ("\n PCIE1 connected to slot as %s (base address %x)",
  191. pcie_ep ? "End Point" : "Root Complex",
  192. (uint)pci);
  193. if (pci->pme_msg_det) {
  194. pci->pme_msg_det = 0xffffffff;
  195. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  196. }
  197. printf ("\n");
  198. /* inbound */
  199. r += fsl_pci_setup_inbound_windows(r);
  200. /* outbound memory */
  201. pci_set_region(r++,
  202. CONFIG_SYS_PCIE1_MEM_BASE,
  203. CONFIG_SYS_PCIE1_MEM_PHYS,
  204. CONFIG_SYS_PCIE1_MEM_SIZE,
  205. PCI_REGION_MEM);
  206. /* outbound io */
  207. pci_set_region(r++,
  208. CONFIG_SYS_PCIE1_IO_BASE,
  209. CONFIG_SYS_PCIE1_IO_PHYS,
  210. CONFIG_SYS_PCIE1_IO_SIZE,
  211. PCI_REGION_IO);
  212. #ifdef CONFIG_SYS_PCIE1_MEM_BASE2
  213. /* outbound memory */
  214. pci_set_region(r++,
  215. CONFIG_SYS_PCIE1_MEM_BASE2,
  216. CONFIG_SYS_PCIE1_MEM_PHYS2,
  217. CONFIG_SYS_PCIE1_MEM_SIZE2,
  218. PCI_REGION_MEM);
  219. #endif
  220. hose->region_count = r - hose->regions;
  221. hose->first_busno=first_free_busno;
  222. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  223. fsl_pci_init(hose);
  224. first_free_busno=hose->last_busno+1;
  225. printf(" PCIE1 on bus %02x - %02x\n",
  226. hose->first_busno,hose->last_busno);
  227. } else {
  228. printf (" PCIE1: disabled\n");
  229. }
  230. }
  231. #else
  232. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  233. #endif
  234. #ifdef CONFIG_PCI1
  235. {
  236. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI1_ADDR;
  237. struct pci_controller *hose = &pci1_hose;
  238. struct pci_region *r = hose->regions;
  239. uint pci_agent = (host_agent == 6);
  240. uint pci_speed = 33333000; /*get_clock_freq (); PCI PSPEED in [4:5] */
  241. uint pci_32 = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32; /* PORDEVSR[15] */
  242. uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB; /* PORDEVSR[14] */
  243. uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD; /* PORPLLSR[16] */
  244. if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
  245. printf ("\n PCI1: %d bit, %s MHz, %s, %s, %s (base address %x)\n",
  246. (pci_32) ? 32 : 64,
  247. (pci_speed == 33333000) ? "33" :
  248. (pci_speed == 66666000) ? "66" : "unknown",
  249. pci_clk_sel ? "sync" : "async",
  250. pci_agent ? "agent" : "host",
  251. pci_arb ? "arbiter" : "external-arbiter",
  252. (uint)pci
  253. );
  254. /* inbound */
  255. r += fsl_pci_setup_inbound_windows(r);
  256. /* outbound memory */
  257. pci_set_region(r++,
  258. CONFIG_SYS_PCI1_MEM_BASE,
  259. CONFIG_SYS_PCI1_MEM_PHYS,
  260. CONFIG_SYS_PCI1_MEM_SIZE,
  261. PCI_REGION_MEM);
  262. /* outbound io */
  263. pci_set_region(r++,
  264. CONFIG_SYS_PCI1_IO_BASE,
  265. CONFIG_SYS_PCI1_IO_PHYS,
  266. CONFIG_SYS_PCI1_IO_SIZE,
  267. PCI_REGION_IO);
  268. hose->region_count = r - hose->regions;
  269. hose->first_busno=first_free_busno;
  270. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  271. fsl_pci_init(hose);
  272. first_free_busno=hose->last_busno+1;
  273. printf ("PCI1 on bus %02x - %02x\n",
  274. hose->first_busno,hose->last_busno);
  275. } else {
  276. printf (" PCI1: disabled\n");
  277. }
  278. }
  279. #else
  280. gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
  281. #endif
  282. #ifdef CONFIG_PCI2
  283. {
  284. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI2_ADDR;
  285. extern void fsl_pci_init(struct pci_controller *hose);
  286. struct pci_controller *hose = &pci2_hose;
  287. struct pci_region *r = hose->regions;
  288. if (!(devdisr & MPC85xx_DEVDISR_PCI2)) {
  289. r += fsl_pci_setup_inbound_windows(r);
  290. pci_set_region(r++,
  291. CONFIG_SYS_PCI2_MEM_BASE,
  292. CONFIG_SYS_PCI2_MEM_PHYS,
  293. CONFIG_SYS_PCI2_MEM_SIZE,
  294. PCI_REGION_MEM);
  295. pci_set_region(r++,
  296. CONFIG_SYS_PCI2_IO_BASE,
  297. CONFIG_SYS_PCI2_IO_PHYS,
  298. CONFIG_SYS_PCI2_IO_SIZE,
  299. PCI_REGION_IO);
  300. hose->region_count = r - hose->regions;
  301. hose->first_busno=first_free_busno;
  302. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  303. fsl_pci_init(hose);
  304. first_free_busno=hose->last_busno+1;
  305. printf ("PCI2 on bus %02x - %02x\n",
  306. hose->first_busno,hose->last_busno);
  307. } else {
  308. printf (" PCI2: disabled\n");
  309. }
  310. }
  311. #else
  312. gur->devdisr |= MPC85xx_DEVDISR_PCI2;
  313. #endif
  314. }
  315. int last_stage_init(void)
  316. {
  317. int ic = icache_status ();
  318. printf ("icache_status: %d\n", ic);
  319. return 0;
  320. }
  321. #if defined(CONFIG_OF_BOARD_SETUP)
  322. extern void ft_fsl_pci_setup(void *blob, const char *pci_alias,
  323. struct pci_controller *hose);
  324. void ft_board_setup(void *blob, bd_t *bd)
  325. {
  326. ft_cpu_setup(blob, bd);
  327. #ifdef CONFIG_PCI1
  328. ft_fsl_pci_setup(blob, "pci0", &pci1_hose);
  329. #endif
  330. #ifdef CONFIG_PCI2
  331. ft_fsl_pci_setup(blob, "pci1", &pci2_hose);
  332. #endif
  333. #ifdef CONFIG_PCIE1
  334. ft_fsl_pci_setup(blob, "pci2", &pcie1_hose);
  335. #endif
  336. }
  337. #endif