atum8548.c 11 KB

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