mpc8568mds.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. /*
  2. * Copyright 2007 Freescale Semiconductor.
  3. *
  4. * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <pci.h>
  26. #include <asm/processor.h>
  27. #include <asm/mmu.h>
  28. #include <asm/immap_85xx.h>
  29. #include <asm/immap_fsl_pci.h>
  30. #include <asm/fsl_ddr_sdram.h>
  31. #include <spd_sdram.h>
  32. #include <i2c.h>
  33. #include <ioports.h>
  34. #include <libfdt.h>
  35. #include <fdt_support.h>
  36. #include "bcsr.h"
  37. const qe_iop_conf_t qe_iop_conf_tab[] = {
  38. /* GETH1 */
  39. {4, 10, 1, 0, 2}, /* TxD0 */
  40. {4, 9, 1, 0, 2}, /* TxD1 */
  41. {4, 8, 1, 0, 2}, /* TxD2 */
  42. {4, 7, 1, 0, 2}, /* TxD3 */
  43. {4, 23, 1, 0, 2}, /* TxD4 */
  44. {4, 22, 1, 0, 2}, /* TxD5 */
  45. {4, 21, 1, 0, 2}, /* TxD6 */
  46. {4, 20, 1, 0, 2}, /* TxD7 */
  47. {4, 15, 2, 0, 2}, /* RxD0 */
  48. {4, 14, 2, 0, 2}, /* RxD1 */
  49. {4, 13, 2, 0, 2}, /* RxD2 */
  50. {4, 12, 2, 0, 2}, /* RxD3 */
  51. {4, 29, 2, 0, 2}, /* RxD4 */
  52. {4, 28, 2, 0, 2}, /* RxD5 */
  53. {4, 27, 2, 0, 2}, /* RxD6 */
  54. {4, 26, 2, 0, 2}, /* RxD7 */
  55. {4, 11, 1, 0, 2}, /* TX_EN */
  56. {4, 24, 1, 0, 2}, /* TX_ER */
  57. {4, 16, 2, 0, 2}, /* RX_DV */
  58. {4, 30, 2, 0, 2}, /* RX_ER */
  59. {4, 17, 2, 0, 2}, /* RX_CLK */
  60. {4, 19, 1, 0, 2}, /* GTX_CLK */
  61. {1, 31, 2, 0, 3}, /* GTX125 */
  62. /* GETH2 */
  63. {5, 10, 1, 0, 2}, /* TxD0 */
  64. {5, 9, 1, 0, 2}, /* TxD1 */
  65. {5, 8, 1, 0, 2}, /* TxD2 */
  66. {5, 7, 1, 0, 2}, /* TxD3 */
  67. {5, 23, 1, 0, 2}, /* TxD4 */
  68. {5, 22, 1, 0, 2}, /* TxD5 */
  69. {5, 21, 1, 0, 2}, /* TxD6 */
  70. {5, 20, 1, 0, 2}, /* TxD7 */
  71. {5, 15, 2, 0, 2}, /* RxD0 */
  72. {5, 14, 2, 0, 2}, /* RxD1 */
  73. {5, 13, 2, 0, 2}, /* RxD2 */
  74. {5, 12, 2, 0, 2}, /* RxD3 */
  75. {5, 29, 2, 0, 2}, /* RxD4 */
  76. {5, 28, 2, 0, 2}, /* RxD5 */
  77. {5, 27, 2, 0, 3}, /* RxD6 */
  78. {5, 26, 2, 0, 2}, /* RxD7 */
  79. {5, 11, 1, 0, 2}, /* TX_EN */
  80. {5, 24, 1, 0, 2}, /* TX_ER */
  81. {5, 16, 2, 0, 2}, /* RX_DV */
  82. {5, 30, 2, 0, 2}, /* RX_ER */
  83. {5, 17, 2, 0, 2}, /* RX_CLK */
  84. {5, 19, 1, 0, 2}, /* GTX_CLK */
  85. {1, 31, 2, 0, 3}, /* GTX125 */
  86. {4, 6, 3, 0, 2}, /* MDIO */
  87. {4, 5, 1, 0, 2}, /* MDC */
  88. /* UART1 */
  89. {2, 0, 1, 0, 2}, /* UART_SOUT1 */
  90. {2, 1, 1, 0, 2}, /* UART_RTS1 */
  91. {2, 2, 2, 0, 2}, /* UART_CTS1 */
  92. {2, 3, 2, 0, 2}, /* UART_SIN1 */
  93. {0, 0, 0, 0, QE_IOP_TAB_END}, /* END of table */
  94. };
  95. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  96. extern void ddr_enable_ecc(unsigned int dram_size);
  97. #endif
  98. void local_bus_init(void);
  99. void sdram_init(void);
  100. int board_early_init_f (void)
  101. {
  102. /*
  103. * Initialize local bus.
  104. */
  105. local_bus_init ();
  106. enable_8568mds_duart();
  107. enable_8568mds_flash_write();
  108. #if defined(CONFIG_UEC_ETH1) || defined(CONFIG_UEC_ETH2)
  109. reset_8568mds_uccs();
  110. #endif
  111. #if defined(CONFIG_QE) && !defined(CONFIG_eTSEC_MDIO_BUS)
  112. enable_8568mds_qe_mdio();
  113. #endif
  114. #ifdef CONFIG_SYS_I2C2_OFFSET
  115. /* Enable I2C2_SCL and I2C2_SDA */
  116. volatile struct par_io *port_c;
  117. port_c = (struct par_io*)(CONFIG_SYS_IMMR + 0xe0140);
  118. port_c->cpdir2 |= 0x0f000000;
  119. port_c->cppar2 &= ~0x0f000000;
  120. port_c->cppar2 |= 0x0a000000;
  121. #endif
  122. return 0;
  123. }
  124. int checkboard (void)
  125. {
  126. printf ("Board: 8568 MDS\n");
  127. return 0;
  128. }
  129. phys_size_t
  130. initdram(int board_type)
  131. {
  132. long dram_size = 0;
  133. puts("Initializing\n");
  134. #if defined(CONFIG_DDR_DLL)
  135. {
  136. /*
  137. * Work around to stabilize DDR DLL MSYNC_IN.
  138. * Errata DDR9 seems to have been fixed.
  139. * This is now the workaround for Errata DDR11:
  140. * Override DLL = 1, Course Adj = 1, Tap Select = 0
  141. */
  142. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  143. gur->ddrdllcr = 0x81000000;
  144. asm("sync;isync;msync");
  145. udelay(200);
  146. }
  147. #endif
  148. dram_size = fsl_ddr_sdram();
  149. dram_size = setup_ddr_tlbs(dram_size / 0x100000);
  150. dram_size *= 0x100000;
  151. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  152. /*
  153. * Initialize and enable DDR ECC.
  154. */
  155. ddr_enable_ecc(dram_size);
  156. #endif
  157. /*
  158. * SDRAM Initialization
  159. */
  160. sdram_init();
  161. puts(" DDR: ");
  162. return dram_size;
  163. }
  164. /*
  165. * Initialize Local Bus
  166. */
  167. void
  168. local_bus_init(void)
  169. {
  170. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  171. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  172. uint clkdiv;
  173. uint lbc_hz;
  174. sys_info_t sysinfo;
  175. get_sys_info(&sysinfo);
  176. clkdiv = (lbc->lcrr & 0x0f) * 2;
  177. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  178. gur->lbiuiplldcr1 = 0x00078080;
  179. if (clkdiv == 16) {
  180. gur->lbiuiplldcr0 = 0x7c0f1bf0;
  181. } else if (clkdiv == 8) {
  182. gur->lbiuiplldcr0 = 0x6c0f1bf0;
  183. } else if (clkdiv == 4) {
  184. gur->lbiuiplldcr0 = 0x5c0f1bf0;
  185. }
  186. lbc->lcrr |= 0x00030000;
  187. asm("sync;isync;msync");
  188. }
  189. /*
  190. * Initialize SDRAM memory on the Local Bus.
  191. */
  192. void
  193. sdram_init(void)
  194. {
  195. #if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM)
  196. uint idx;
  197. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  198. uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
  199. uint lsdmr_common;
  200. puts(" SDRAM: ");
  201. print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  202. /*
  203. * Setup SDRAM Base and Option Registers
  204. */
  205. lbc->or2 = CONFIG_SYS_OR2_PRELIM;
  206. asm("msync");
  207. lbc->br2 = CONFIG_SYS_BR2_PRELIM;
  208. asm("msync");
  209. lbc->lbcr = CONFIG_SYS_LBC_LBCR;
  210. asm("msync");
  211. lbc->lsrt = CONFIG_SYS_LBC_LSRT;
  212. lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
  213. asm("msync");
  214. /*
  215. * MPC8568 uses "new" 15-16 style addressing.
  216. */
  217. lsdmr_common = CONFIG_SYS_LBC_LSDMR_COMMON;
  218. lsdmr_common |= CONFIG_SYS_LBC_LSDMR_BSMA1516;
  219. /*
  220. * Issue PRECHARGE ALL command.
  221. */
  222. lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_PCHALL;
  223. asm("sync;msync");
  224. *sdram_addr = 0xff;
  225. ppcDcbf((unsigned long) sdram_addr);
  226. udelay(100);
  227. /*
  228. * Issue 8 AUTO REFRESH commands.
  229. */
  230. for (idx = 0; idx < 8; idx++) {
  231. lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_ARFRSH;
  232. asm("sync;msync");
  233. *sdram_addr = 0xff;
  234. ppcDcbf((unsigned long) sdram_addr);
  235. udelay(100);
  236. }
  237. /*
  238. * Issue 8 MODE-set command.
  239. */
  240. lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_MRW;
  241. asm("sync;msync");
  242. *sdram_addr = 0xff;
  243. ppcDcbf((unsigned long) sdram_addr);
  244. udelay(100);
  245. /*
  246. * Issue NORMAL OP command.
  247. */
  248. lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_NORMAL;
  249. asm("sync;msync");
  250. *sdram_addr = 0xff;
  251. ppcDcbf((unsigned long) sdram_addr);
  252. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  253. #endif /* enable SDRAM init */
  254. }
  255. #if defined(CONFIG_PCI)
  256. #ifndef CONFIG_PCI_PNP
  257. static struct pci_config_table pci_mpc8568mds_config_table[] = {
  258. {
  259. PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  260. pci_cfgfunc_config_device,
  261. {PCI_ENET0_IOADDR,
  262. PCI_ENET0_MEMADDR,
  263. PCI_COMMON_MEMORY | PCI_COMMAND_MASTER}
  264. },
  265. {}
  266. };
  267. #endif
  268. static struct pci_controller pci1_hose = {
  269. #ifndef CONFIG_PCI_PNP
  270. config_table: pci_mpc8568mds_config_table,
  271. #endif
  272. };
  273. #endif /* CONFIG_PCI */
  274. #ifdef CONFIG_PCIE1
  275. static struct pci_controller pcie1_hose;
  276. #endif /* CONFIG_PCIE1 */
  277. extern int fsl_pci_setup_inbound_windows(struct pci_region *r);
  278. extern void fsl_pci_init(struct pci_controller *hose);
  279. int first_free_busno = 0;
  280. /*
  281. * pib_init() -- Initialize the PCA9555 IO expander on the PIB board
  282. */
  283. void
  284. pib_init(void)
  285. {
  286. u8 val8, orig_i2c_bus;
  287. /*
  288. * Assign PIB PMC2/3 to PCI bus
  289. */
  290. /*switch temporarily to I2C bus #2 */
  291. orig_i2c_bus = i2c_get_bus_num();
  292. i2c_set_bus_num(1);
  293. val8 = 0x00;
  294. i2c_write(0x23, 0x6, 1, &val8, 1);
  295. i2c_write(0x23, 0x7, 1, &val8, 1);
  296. val8 = 0xff;
  297. i2c_write(0x23, 0x2, 1, &val8, 1);
  298. i2c_write(0x23, 0x3, 1, &val8, 1);
  299. val8 = 0x00;
  300. i2c_write(0x26, 0x6, 1, &val8, 1);
  301. val8 = 0x34;
  302. i2c_write(0x26, 0x7, 1, &val8, 1);
  303. val8 = 0xf9;
  304. i2c_write(0x26, 0x2, 1, &val8, 1);
  305. val8 = 0xff;
  306. i2c_write(0x26, 0x3, 1, &val8, 1);
  307. val8 = 0x00;
  308. i2c_write(0x27, 0x6, 1, &val8, 1);
  309. i2c_write(0x27, 0x7, 1, &val8, 1);
  310. val8 = 0xff;
  311. i2c_write(0x27, 0x2, 1, &val8, 1);
  312. val8 = 0xef;
  313. i2c_write(0x27, 0x3, 1, &val8, 1);
  314. asm("eieio");
  315. }
  316. #ifdef CONFIG_PCI
  317. void
  318. pci_init_board(void)
  319. {
  320. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  321. uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  322. uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  323. #ifdef CONFIG_PCI1
  324. {
  325. pib_init();
  326. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI1_ADDR;
  327. struct pci_controller *hose = &pci1_hose;
  328. struct pci_region *r = hose->regions;
  329. uint pci_32 = 1; /* PORDEVSR[15] */
  330. uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB; /* PORDEVSR[14] */
  331. uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD; /* PORPLLSR[16] */
  332. uint pci_agent = (host_agent == 3) || (host_agent == 4 ) || (host_agent == 6);
  333. uint pci_speed = 66666000;
  334. if (!(gur->devdisr & MPC85xx_DEVDISR_PCI1)) {
  335. printf (" PCI: %d bit, %s MHz, %s, %s, %s\n",
  336. (pci_32) ? 32 : 64,
  337. (pci_speed == 33333000) ? "33" :
  338. (pci_speed == 66666000) ? "66" : "unknown",
  339. pci_clk_sel ? "sync" : "async",
  340. pci_agent ? "agent" : "host",
  341. pci_arb ? "arbiter" : "external-arbiter"
  342. );
  343. /* inbound */
  344. r += fsl_pci_setup_inbound_windows(r);
  345. /* outbound memory */
  346. pci_set_region(r++,
  347. CONFIG_SYS_PCI1_MEM_BASE,
  348. CONFIG_SYS_PCI1_MEM_PHYS,
  349. CONFIG_SYS_PCI1_MEM_SIZE,
  350. PCI_REGION_MEM);
  351. /* outbound io */
  352. pci_set_region(r++,
  353. CONFIG_SYS_PCI1_IO_BASE,
  354. CONFIG_SYS_PCI1_IO_PHYS,
  355. CONFIG_SYS_PCI1_IO_SIZE,
  356. PCI_REGION_IO);
  357. hose->region_count = r - hose->regions;
  358. hose->first_busno = first_free_busno;
  359. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  360. fsl_pci_init(hose);
  361. first_free_busno = hose->last_busno+1;
  362. printf ("PCI on bus %02x - %02x\n",hose->first_busno,hose->last_busno);
  363. } else {
  364. printf (" PCI: disabled\n");
  365. }
  366. }
  367. #else
  368. gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
  369. #endif
  370. #ifdef CONFIG_PCIE1
  371. {
  372. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
  373. struct pci_controller *hose = &pcie1_hose;
  374. int pcie_ep = (host_agent == 0) || (host_agent == 2 ) || (host_agent == 3);
  375. struct pci_region *r = hose->regions;
  376. int pcie_configured = io_sel >= 1;
  377. if (pcie_configured && !(gur->devdisr & MPC85xx_DEVDISR_PCIE)){
  378. printf ("\n PCIE connected to slot as %s (base address %x)",
  379. pcie_ep ? "End Point" : "Root Complex",
  380. (uint)pci);
  381. if (pci->pme_msg_det) {
  382. pci->pme_msg_det = 0xffffffff;
  383. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  384. }
  385. printf ("\n");
  386. /* inbound */
  387. r += fsl_pci_setup_inbound_windows(r);
  388. /* outbound memory */
  389. pci_set_region(r++,
  390. CONFIG_SYS_PCIE1_MEM_BASE,
  391. CONFIG_SYS_PCIE1_MEM_PHYS,
  392. CONFIG_SYS_PCIE1_MEM_SIZE,
  393. PCI_REGION_MEM);
  394. /* outbound io */
  395. pci_set_region(r++,
  396. CONFIG_SYS_PCIE1_IO_BASE,
  397. CONFIG_SYS_PCIE1_IO_PHYS,
  398. CONFIG_SYS_PCIE1_IO_SIZE,
  399. PCI_REGION_IO);
  400. hose->region_count = r - hose->regions;
  401. hose->first_busno=first_free_busno;
  402. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  403. fsl_pci_init(hose);
  404. printf ("PCIE on bus %02x - %02x\n",hose->first_busno,hose->last_busno);
  405. first_free_busno=hose->last_busno+1;
  406. } else {
  407. printf (" PCIE: disabled\n");
  408. }
  409. }
  410. #else
  411. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  412. #endif
  413. }
  414. #endif /* CONFIG_PCI */
  415. #if defined(CONFIG_OF_BOARD_SETUP)
  416. extern void ft_fsl_pci_setup(void *blob, const char *pci_alias,
  417. struct pci_controller *hose);
  418. void ft_board_setup(void *blob, bd_t *bd)
  419. {
  420. ft_cpu_setup(blob, bd);
  421. #ifdef CONFIG_PCI1
  422. ft_fsl_pci_setup(blob, "pci0", &pci1_hose);
  423. #endif
  424. #ifdef CONFIG_PCIE1
  425. ft_fsl_pci_setup(blob, "pci1", &pcie1_hose);
  426. #endif
  427. }
  428. #endif