atum8548.c 11 KB

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