atum8548.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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 *)(CFG_MPC85xx_GUTS_ADDR);
  49. volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
  50. volatile ccsr_local_ecm_t *ecm = (void *)(CFG_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 *)(CFG_MPC85xx_DDR_ADDR);
  68. ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
  69. ddr->cs0_config = CFG_DDR_CS0_CONFIG;
  70. ddr->timing_cfg_0 = CFG_DDR_TIMING_0;
  71. ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
  72. ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
  73. ddr->sdram_mode = CFG_DDR_MODE;
  74. ddr->sdram_interval = CFG_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 = (CFG_DDR_CONTROL | 0x20000000);
  84. #else
  85. ddr->sdram_cfg = CFG_DDR_CONTROL;
  86. #endif
  87. asm("sync; isync; msync");
  88. udelay(500);
  89. return CFG_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(CFG_DRAM_TEST)
  116. int
  117. testdram(void)
  118. {
  119. uint *pstart = (uint *) CFG_MEMTEST_START;
  120. uint *pend = (uint *) CFG_MEMTEST_END;
  121. uint *p;
  122. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  123. CFG_MEMTEST_START,
  124. CFG_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. void
  160. pci_init_board(void)
  161. {
  162. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  163. uint devdisr = gur->devdisr;
  164. uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  165. uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  166. debug (" pci_init_board: devdisr=%x, io_sel=%x, host_agent=%x\n",
  167. devdisr, io_sel, host_agent);
  168. /* explicitly set 'Clock out select register' to echo SYSCLK input to our CPLD */
  169. gur->clkocr |= MPC85xx_ATUM_CLKOCR;
  170. if (io_sel & 1) {
  171. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII1_DIS))
  172. printf (" eTSEC1 is in sgmii mode.\n");
  173. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII2_DIS))
  174. printf (" eTSEC2 is in sgmii mode.\n");
  175. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII3_DIS))
  176. printf (" eTSEC3 is in sgmii mode.\n");
  177. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII4_DIS))
  178. printf (" eTSEC4 is in sgmii mode.\n");
  179. }
  180. #ifdef CONFIG_PCIE1
  181. {
  182. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE1_ADDR;
  183. extern void fsl_pci_init(struct pci_controller *hose);
  184. struct pci_controller *hose = &pcie1_hose;
  185. int pcie_ep = (host_agent == 5);
  186. int pcie_configured = io_sel & 6;
  187. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  188. printf ("\n PCIE1 connected to slot as %s (base address %x)",
  189. pcie_ep ? "End Point" : "Root Complex",
  190. (uint)pci);
  191. if (pci->pme_msg_det) {
  192. pci->pme_msg_det = 0xffffffff;
  193. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  194. }
  195. printf ("\n");
  196. /* inbound */
  197. pci_set_region(hose->regions + 0,
  198. CFG_PCI_MEMORY_BUS,
  199. CFG_PCI_MEMORY_PHYS,
  200. CFG_PCI_MEMORY_SIZE,
  201. PCI_REGION_MEM | PCI_REGION_MEMORY);
  202. /* outbound memory */
  203. pci_set_region(hose->regions + 1,
  204. CFG_PCIE1_MEM_BASE,
  205. CFG_PCIE1_MEM_PHYS,
  206. CFG_PCIE1_MEM_SIZE,
  207. PCI_REGION_MEM);
  208. /* outbound io */
  209. pci_set_region(hose->regions + 2,
  210. CFG_PCIE1_IO_BASE,
  211. CFG_PCIE1_IO_PHYS,
  212. CFG_PCIE1_IO_SIZE,
  213. PCI_REGION_IO);
  214. hose->region_count = 3;
  215. #ifdef CFG_PCIE1_MEM_BASE2
  216. /* outbound memory */
  217. pci_set_region(hose->regions + 3,
  218. CFG_PCIE1_MEM_BASE2,
  219. CFG_PCIE1_MEM_PHYS2,
  220. CFG_PCIE1_MEM_SIZE2,
  221. PCI_REGION_MEM);
  222. hose->region_count++;
  223. #endif
  224. hose->first_busno=first_free_busno;
  225. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  226. fsl_pci_init(hose);
  227. first_free_busno=hose->last_busno+1;
  228. printf(" PCIE1 on bus %02x - %02x\n",
  229. hose->first_busno,hose->last_busno);
  230. } else {
  231. printf (" PCIE1: disabled\n");
  232. }
  233. }
  234. #else
  235. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  236. #endif
  237. #ifdef CONFIG_PCI1
  238. {
  239. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI1_ADDR;
  240. extern void fsl_pci_init(struct pci_controller *hose);
  241. struct pci_controller *hose = &pci1_hose;
  242. uint pci_agent = (host_agent == 6);
  243. uint pci_speed = 33333000; /*get_clock_freq (); PCI PSPEED in [4:5] */
  244. uint pci_32 = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32; /* PORDEVSR[15] */
  245. uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB; /* PORDEVSR[14] */
  246. uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD; /* PORPLLSR[16] */
  247. if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
  248. printf ("\n PCI1: %d bit, %s MHz, %s, %s, %s (base address %x)\n",
  249. (pci_32) ? 32 : 64,
  250. (pci_speed == 33333000) ? "33" :
  251. (pci_speed == 66666000) ? "66" : "unknown",
  252. pci_clk_sel ? "sync" : "async",
  253. pci_agent ? "agent" : "host",
  254. pci_arb ? "arbiter" : "external-arbiter",
  255. (uint)pci
  256. );
  257. /* inbound */
  258. pci_set_region(hose->regions + 0,
  259. CFG_PCI_MEMORY_BUS,
  260. CFG_PCI_MEMORY_PHYS,
  261. CFG_PCI_MEMORY_SIZE,
  262. PCI_REGION_MEM | PCI_REGION_MEMORY);
  263. /* outbound memory */
  264. pci_set_region(hose->regions + 1,
  265. CFG_PCI1_MEM_BASE,
  266. CFG_PCI1_MEM_PHYS,
  267. CFG_PCI1_MEM_SIZE,
  268. PCI_REGION_MEM);
  269. /* outbound io */
  270. pci_set_region(hose->regions + 2,
  271. CFG_PCI1_IO_BASE,
  272. CFG_PCI1_IO_PHYS,
  273. CFG_PCI1_IO_SIZE,
  274. PCI_REGION_IO);
  275. hose->region_count = 3;
  276. hose->first_busno=first_free_busno;
  277. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  278. fsl_pci_init(hose);
  279. first_free_busno=hose->last_busno+1;
  280. printf ("PCI1 on bus %02x - %02x\n",
  281. hose->first_busno,hose->last_busno);
  282. } else {
  283. printf (" PCI1: disabled\n");
  284. }
  285. }
  286. #else
  287. gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
  288. #endif
  289. #ifdef CONFIG_PCI2
  290. {
  291. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI2_ADDR;
  292. extern void fsl_pci_init(struct pci_controller *hose);
  293. struct pci_controller *hose = &pci2_hose;
  294. if (!(devdisr & MPC85xx_DEVDISR_PCI2)) {
  295. pci_set_region(hose->regions + 0,
  296. CFG_PCI_MEMORY_BUS,
  297. CFG_PCI_MEMORY_PHYS,
  298. CFG_PCI_MEMORY_SIZE,
  299. PCI_REGION_MEM | PCI_REGION_MEMORY);
  300. pci_set_region(hose->regions + 1,
  301. CFG_PCI2_MEM_BASE,
  302. CFG_PCI2_MEM_PHYS,
  303. CFG_PCI2_MEM_SIZE,
  304. PCI_REGION_MEM);
  305. pci_set_region(hose->regions + 2,
  306. CFG_PCI2_IO_BASE,
  307. CFG_PCI2_IO_PHYS,
  308. CFG_PCI2_IO_SIZE,
  309. PCI_REGION_IO);
  310. hose->region_count = 3;
  311. hose->first_busno=first_free_busno;
  312. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  313. fsl_pci_init(hose);
  314. first_free_busno=hose->last_busno+1;
  315. printf ("PCI2 on bus %02x - %02x\n",
  316. hose->first_busno,hose->last_busno);
  317. } else {
  318. printf (" PCI2: disabled\n");
  319. }
  320. }
  321. #else
  322. gur->devdisr |= MPC85xx_DEVDISR_PCI2;
  323. #endif
  324. }
  325. int last_stage_init(void)
  326. {
  327. int ic = icache_status ();
  328. printf ("icache_status: %d\n", ic);
  329. return 0;
  330. }
  331. #if defined(CONFIG_OF_BOARD_SETUP)
  332. void
  333. ft_board_setup(void *blob, bd_t *bd)
  334. {
  335. int node, tmp[2];
  336. const char *path;
  337. ft_cpu_setup(blob, bd);
  338. node = fdt_path_offset(blob, "/aliases");
  339. tmp[0] = 0;
  340. if (node >= 0) {
  341. #ifdef CONFIG_PCI1
  342. path = fdt_getprop(blob, node, "pci0", NULL);
  343. if (path) {
  344. tmp[1] = pci1_hose.last_busno - pci1_hose.first_busno;
  345. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  346. }
  347. #endif
  348. #ifdef CONFIG_PCI2
  349. path = fdt_getprop(blob, node, "pci1", NULL);
  350. if (path) {
  351. tmp[1] = pci2_hose.last_busno - pci2_hose.first_busno;
  352. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  353. }
  354. #endif
  355. #ifdef CONFIG_PCIE1
  356. path = fdt_getprop(blob, node, "pci2", NULL);
  357. if (path) {
  358. tmp[1] = pcie1_hose.last_busno - pcie1_hose.first_busno;
  359. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  360. }
  361. #endif
  362. }
  363. }
  364. #endif