mpc8544ds.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. /*
  2. * Copyright 2007 Freescale Semiconductor, Inc.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <command.h>
  24. #include <pci.h>
  25. #include <asm/processor.h>
  26. #include <asm/immap_85xx.h>
  27. #include <asm/immap_fsl_pci.h>
  28. #include <asm/io.h>
  29. #include <spd_sdram.h>
  30. #include <miiphy.h>
  31. #include <libfdt.h>
  32. #include <fdt_support.h>
  33. #include "../common/pixis.h"
  34. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  35. extern void ddr_enable_ecc(unsigned int dram_size);
  36. #endif
  37. void sdram_init(void);
  38. int checkboard (void)
  39. {
  40. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  41. volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
  42. volatile ccsr_local_ecm_t *ecm = (void *)(CFG_MPC85xx_ECM_ADDR);
  43. if ((uint)&gur->porpllsr != 0xe00e0000) {
  44. printf("immap size error %lx\n",(ulong)&gur->porpllsr);
  45. }
  46. printf ("Board: MPC8544DS\n");
  47. lbc->ltesr = 0xffffffff; /* Clear LBC error interrupts */
  48. lbc->lteir = 0xffffffff; /* Enable LBC error interrupts */
  49. ecm->eedr = 0xffffffff; /* Clear ecm errors */
  50. ecm->eeer = 0xffffffff; /* Enable ecm errors */
  51. return 0;
  52. }
  53. phys_size_t
  54. initdram(int board_type)
  55. {
  56. long dram_size = 0;
  57. puts("Initializing\n");
  58. dram_size = spd_sdram();
  59. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  60. /*
  61. * Initialize and enable DDR ECC.
  62. */
  63. ddr_enable_ecc(dram_size);
  64. #endif
  65. puts(" DDR: ");
  66. return dram_size;
  67. }
  68. #ifdef CONFIG_PCI1
  69. static struct pci_controller pci1_hose;
  70. #endif
  71. #ifdef CONFIG_PCIE1
  72. static struct pci_controller pcie1_hose;
  73. #endif
  74. #ifdef CONFIG_PCIE2
  75. static struct pci_controller pcie2_hose;
  76. #endif
  77. #ifdef CONFIG_PCIE3
  78. static struct pci_controller pcie3_hose;
  79. #endif
  80. int first_free_busno=0;
  81. void
  82. pci_init_board(void)
  83. {
  84. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  85. uint devdisr = gur->devdisr;
  86. uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  87. uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  88. debug (" pci_init_board: devdisr=%x, io_sel=%x, host_agent=%x\n",
  89. devdisr, io_sel, host_agent);
  90. if (io_sel & 1) {
  91. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII1_DIS))
  92. printf (" eTSEC1 is in sgmii mode.\n");
  93. if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII3_DIS))
  94. printf (" eTSEC3 is in sgmii mode.\n");
  95. }
  96. #ifdef CONFIG_PCIE3
  97. {
  98. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE3_ADDR;
  99. extern void fsl_pci_init(struct pci_controller *hose);
  100. struct pci_controller *hose = &pcie3_hose;
  101. int pcie_ep = (host_agent == 1);
  102. int pcie_configured = io_sel >= 1;
  103. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  104. printf ("\n PCIE3 connected to ULI as %s (base address %x)",
  105. pcie_ep ? "End Point" : "Root Complex",
  106. (uint)pci);
  107. if (pci->pme_msg_det) {
  108. pci->pme_msg_det = 0xffffffff;
  109. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  110. }
  111. printf ("\n");
  112. /* inbound */
  113. pci_set_region(hose->regions + 0,
  114. CFG_PCI_MEMORY_BUS,
  115. CFG_PCI_MEMORY_PHYS,
  116. CFG_PCI_MEMORY_SIZE,
  117. PCI_REGION_MEM | PCI_REGION_MEMORY);
  118. /* outbound memory */
  119. pci_set_region(hose->regions + 1,
  120. CFG_PCIE3_MEM_BASE,
  121. CFG_PCIE3_MEM_PHYS,
  122. CFG_PCIE3_MEM_SIZE,
  123. PCI_REGION_MEM);
  124. /* outbound io */
  125. pci_set_region(hose->regions + 2,
  126. CFG_PCIE3_IO_BASE,
  127. CFG_PCIE3_IO_PHYS,
  128. CFG_PCIE3_IO_SIZE,
  129. PCI_REGION_IO);
  130. hose->region_count = 3;
  131. #ifdef CFG_PCIE3_MEM_BASE2
  132. /* outbound memory */
  133. pci_set_region(hose->regions + 3,
  134. CFG_PCIE3_MEM_BASE2,
  135. CFG_PCIE3_MEM_PHYS2,
  136. CFG_PCIE3_MEM_SIZE2,
  137. PCI_REGION_MEM);
  138. hose->region_count++;
  139. #endif
  140. hose->first_busno=first_free_busno;
  141. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  142. fsl_pci_init(hose);
  143. first_free_busno=hose->last_busno+1;
  144. printf (" PCIE3 on bus %02x - %02x\n",
  145. hose->first_busno,hose->last_busno);
  146. /*
  147. * Activate ULI1575 legacy chip by performing a fake
  148. * memory access. Needed to make ULI RTC work.
  149. */
  150. in_be32((u32 *)CFG_PCIE3_MEM_BASE);
  151. } else {
  152. printf (" PCIE3: disabled\n");
  153. }
  154. }
  155. #else
  156. gur->devdisr |= MPC85xx_DEVDISR_PCIE3; /* disable */
  157. #endif
  158. #ifdef CONFIG_PCIE1
  159. {
  160. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE1_ADDR;
  161. extern void fsl_pci_init(struct pci_controller *hose);
  162. struct pci_controller *hose = &pcie1_hose;
  163. int pcie_ep = (host_agent == 5);
  164. int pcie_configured = io_sel & 6;
  165. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  166. printf ("\n PCIE1 connected to Slot2 as %s (base address %x)",
  167. pcie_ep ? "End Point" : "Root Complex",
  168. (uint)pci);
  169. if (pci->pme_msg_det) {
  170. pci->pme_msg_det = 0xffffffff;
  171. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  172. }
  173. printf ("\n");
  174. /* inbound */
  175. pci_set_region(hose->regions + 0,
  176. CFG_PCI_MEMORY_BUS,
  177. CFG_PCI_MEMORY_PHYS,
  178. CFG_PCI_MEMORY_SIZE,
  179. PCI_REGION_MEM | PCI_REGION_MEMORY);
  180. /* outbound memory */
  181. pci_set_region(hose->regions + 1,
  182. CFG_PCIE1_MEM_BASE,
  183. CFG_PCIE1_MEM_PHYS,
  184. CFG_PCIE1_MEM_SIZE,
  185. PCI_REGION_MEM);
  186. /* outbound io */
  187. pci_set_region(hose->regions + 2,
  188. CFG_PCIE1_IO_BASE,
  189. CFG_PCIE1_IO_PHYS,
  190. CFG_PCIE1_IO_SIZE,
  191. PCI_REGION_IO);
  192. hose->region_count = 3;
  193. #ifdef CFG_PCIE1_MEM_BASE2
  194. /* outbound memory */
  195. pci_set_region(hose->regions + 3,
  196. CFG_PCIE1_MEM_BASE2,
  197. CFG_PCIE1_MEM_PHYS2,
  198. CFG_PCIE1_MEM_SIZE2,
  199. PCI_REGION_MEM);
  200. hose->region_count++;
  201. #endif
  202. hose->first_busno=first_free_busno;
  203. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  204. fsl_pci_init(hose);
  205. first_free_busno=hose->last_busno+1;
  206. printf(" PCIE1 on bus %02x - %02x\n",
  207. hose->first_busno,hose->last_busno);
  208. } else {
  209. printf (" PCIE1: disabled\n");
  210. }
  211. }
  212. #else
  213. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  214. #endif
  215. #ifdef CONFIG_PCIE2
  216. {
  217. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE2_ADDR;
  218. extern void fsl_pci_init(struct pci_controller *hose);
  219. struct pci_controller *hose = &pcie2_hose;
  220. int pcie_ep = (host_agent == 3);
  221. int pcie_configured = io_sel & 4;
  222. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  223. printf ("\n PCIE2 connected to Slot 1 as %s (base address %x)",
  224. pcie_ep ? "End Point" : "Root Complex",
  225. (uint)pci);
  226. if (pci->pme_msg_det) {
  227. pci->pme_msg_det = 0xffffffff;
  228. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  229. }
  230. printf ("\n");
  231. /* inbound */
  232. pci_set_region(hose->regions + 0,
  233. CFG_PCI_MEMORY_BUS,
  234. CFG_PCI_MEMORY_PHYS,
  235. CFG_PCI_MEMORY_SIZE,
  236. PCI_REGION_MEM | PCI_REGION_MEMORY);
  237. /* outbound memory */
  238. pci_set_region(hose->regions + 1,
  239. CFG_PCIE2_MEM_BASE,
  240. CFG_PCIE2_MEM_PHYS,
  241. CFG_PCIE2_MEM_SIZE,
  242. PCI_REGION_MEM);
  243. /* outbound io */
  244. pci_set_region(hose->regions + 2,
  245. CFG_PCIE2_IO_BASE,
  246. CFG_PCIE2_IO_PHYS,
  247. CFG_PCIE2_IO_SIZE,
  248. PCI_REGION_IO);
  249. hose->region_count = 3;
  250. #ifdef CFG_PCIE2_MEM_BASE2
  251. /* outbound memory */
  252. pci_set_region(hose->regions + 3,
  253. CFG_PCIE2_MEM_BASE2,
  254. CFG_PCIE2_MEM_PHYS2,
  255. CFG_PCIE2_MEM_SIZE2,
  256. PCI_REGION_MEM);
  257. hose->region_count++;
  258. #endif
  259. hose->first_busno=first_free_busno;
  260. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  261. fsl_pci_init(hose);
  262. first_free_busno=hose->last_busno+1;
  263. printf (" PCIE2 on bus %02x - %02x\n",
  264. hose->first_busno,hose->last_busno);
  265. } else {
  266. printf (" PCIE2: disabled\n");
  267. }
  268. }
  269. #else
  270. gur->devdisr |= MPC85xx_DEVDISR_PCIE2; /* disable */
  271. #endif
  272. #ifdef CONFIG_PCI1
  273. {
  274. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI1_ADDR;
  275. extern void fsl_pci_init(struct pci_controller *hose);
  276. struct pci_controller *hose = &pci1_hose;
  277. uint pci_agent = (host_agent == 6);
  278. uint pci_speed = 66666000; /*get_clock_freq (); PCI PSPEED in [4:5] */
  279. uint pci_32 = 1;
  280. uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB; /* PORDEVSR[14] */
  281. uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD; /* PORPLLSR[16] */
  282. if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
  283. printf ("\n PCI: %d bit, %s MHz, %s, %s, %s (base address %x)\n",
  284. (pci_32) ? 32 : 64,
  285. (pci_speed == 33333000) ? "33" :
  286. (pci_speed == 66666000) ? "66" : "unknown",
  287. pci_clk_sel ? "sync" : "async",
  288. pci_agent ? "agent" : "host",
  289. pci_arb ? "arbiter" : "external-arbiter",
  290. (uint)pci
  291. );
  292. /* inbound */
  293. pci_set_region(hose->regions + 0,
  294. CFG_PCI_MEMORY_BUS,
  295. CFG_PCI_MEMORY_PHYS,
  296. CFG_PCI_MEMORY_SIZE,
  297. PCI_REGION_MEM | PCI_REGION_MEMORY);
  298. /* outbound memory */
  299. pci_set_region(hose->regions + 1,
  300. CFG_PCI1_MEM_BASE,
  301. CFG_PCI1_MEM_PHYS,
  302. CFG_PCI1_MEM_SIZE,
  303. PCI_REGION_MEM);
  304. /* outbound io */
  305. pci_set_region(hose->regions + 2,
  306. CFG_PCI1_IO_BASE,
  307. CFG_PCI1_IO_PHYS,
  308. CFG_PCI1_IO_SIZE,
  309. PCI_REGION_IO);
  310. hose->region_count = 3;
  311. #ifdef CFG_PCIE3_MEM_BASE2
  312. /* outbound memory */
  313. pci_set_region(hose->regions + 3,
  314. CFG_PCIE3_MEM_BASE2,
  315. CFG_PCIE3_MEM_PHYS2,
  316. CFG_PCIE3_MEM_SIZE2,
  317. PCI_REGION_MEM);
  318. hose->region_count++;
  319. #endif
  320. hose->first_busno=first_free_busno;
  321. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  322. fsl_pci_init(hose);
  323. first_free_busno=hose->last_busno+1;
  324. printf ("PCI on bus %02x - %02x\n",
  325. hose->first_busno,hose->last_busno);
  326. } else {
  327. printf (" PCI: disabled\n");
  328. }
  329. }
  330. #else
  331. gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
  332. #endif
  333. }
  334. int last_stage_init(void)
  335. {
  336. return 0;
  337. }
  338. unsigned long
  339. get_board_sys_clk(ulong dummy)
  340. {
  341. u8 i, go_bit, rd_clks;
  342. ulong val = 0;
  343. go_bit = in8(PIXIS_BASE + PIXIS_VCTL);
  344. go_bit &= 0x01;
  345. rd_clks = in8(PIXIS_BASE + PIXIS_VCFGEN0);
  346. rd_clks &= 0x1C;
  347. /*
  348. * Only if both go bit and the SCLK bit in VCFGEN0 are set
  349. * should we be using the AUX register. Remember, we also set the
  350. * GO bit to boot from the alternate bank on the on-board flash
  351. */
  352. if (go_bit) {
  353. if (rd_clks == 0x1c)
  354. i = in8(PIXIS_BASE + PIXIS_AUX);
  355. else
  356. i = in8(PIXIS_BASE + PIXIS_SPD);
  357. } else {
  358. i = in8(PIXIS_BASE + PIXIS_SPD);
  359. }
  360. i &= 0x07;
  361. switch (i) {
  362. case 0:
  363. val = 33333333;
  364. break;
  365. case 1:
  366. val = 40000000;
  367. break;
  368. case 2:
  369. val = 50000000;
  370. break;
  371. case 3:
  372. val = 66666666;
  373. break;
  374. case 4:
  375. val = 83000000;
  376. break;
  377. case 5:
  378. val = 100000000;
  379. break;
  380. case 6:
  381. val = 133333333;
  382. break;
  383. case 7:
  384. val = 166666666;
  385. break;
  386. }
  387. return val;
  388. }
  389. #if defined(CONFIG_OF_BOARD_SETUP)
  390. void
  391. ft_board_setup(void *blob, bd_t *bd)
  392. {
  393. int node, tmp[2];
  394. const char *path;
  395. ft_cpu_setup(blob, bd);
  396. node = fdt_path_offset(blob, "/aliases");
  397. tmp[0] = 0;
  398. if (node >= 0) {
  399. #ifdef CONFIG_PCI1
  400. path = fdt_getprop(blob, node, "pci0", NULL);
  401. if (path) {
  402. tmp[1] = pci1_hose.last_busno - pci1_hose.first_busno;
  403. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  404. }
  405. #endif
  406. #ifdef CONFIG_PCIE2
  407. path = fdt_getprop(blob, node, "pci1", NULL);
  408. if (path) {
  409. tmp[1] = pcie2_hose.last_busno - pcie2_hose.first_busno;
  410. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  411. }
  412. #endif
  413. #ifdef CONFIG_PCIE1
  414. path = fdt_getprop(blob, node, "pci2", NULL);
  415. if (path) {
  416. tmp[1] = pcie1_hose.last_busno - pcie1_hose.first_busno;
  417. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  418. }
  419. #endif
  420. #ifdef CONFIG_PCIE3
  421. path = fdt_getprop(blob, node, "pci3", NULL);
  422. if (path) {
  423. tmp[1] = pcie3_hose.last_busno - pcie3_hose.first_busno;
  424. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  425. }
  426. #endif
  427. }
  428. }
  429. #endif