mpc8568mds.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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/immap_85xx.h>
  28. #include <asm/immap_fsl_pci.h>
  29. #include <spd.h>
  30. #include <i2c.h>
  31. #include <ioports.h>
  32. #include <libfdt.h>
  33. #include <fdt_support.h>
  34. #include "bcsr.h"
  35. const qe_iop_conf_t qe_iop_conf_tab[] = {
  36. /* GETH1 */
  37. {4, 10, 1, 0, 2}, /* TxD0 */
  38. {4, 9, 1, 0, 2}, /* TxD1 */
  39. {4, 8, 1, 0, 2}, /* TxD2 */
  40. {4, 7, 1, 0, 2}, /* TxD3 */
  41. {4, 23, 1, 0, 2}, /* TxD4 */
  42. {4, 22, 1, 0, 2}, /* TxD5 */
  43. {4, 21, 1, 0, 2}, /* TxD6 */
  44. {4, 20, 1, 0, 2}, /* TxD7 */
  45. {4, 15, 2, 0, 2}, /* RxD0 */
  46. {4, 14, 2, 0, 2}, /* RxD1 */
  47. {4, 13, 2, 0, 2}, /* RxD2 */
  48. {4, 12, 2, 0, 2}, /* RxD3 */
  49. {4, 29, 2, 0, 2}, /* RxD4 */
  50. {4, 28, 2, 0, 2}, /* RxD5 */
  51. {4, 27, 2, 0, 2}, /* RxD6 */
  52. {4, 26, 2, 0, 2}, /* RxD7 */
  53. {4, 11, 1, 0, 2}, /* TX_EN */
  54. {4, 24, 1, 0, 2}, /* TX_ER */
  55. {4, 16, 2, 0, 2}, /* RX_DV */
  56. {4, 30, 2, 0, 2}, /* RX_ER */
  57. {4, 17, 2, 0, 2}, /* RX_CLK */
  58. {4, 19, 1, 0, 2}, /* GTX_CLK */
  59. {1, 31, 2, 0, 3}, /* GTX125 */
  60. /* GETH2 */
  61. {5, 10, 1, 0, 2}, /* TxD0 */
  62. {5, 9, 1, 0, 2}, /* TxD1 */
  63. {5, 8, 1, 0, 2}, /* TxD2 */
  64. {5, 7, 1, 0, 2}, /* TxD3 */
  65. {5, 23, 1, 0, 2}, /* TxD4 */
  66. {5, 22, 1, 0, 2}, /* TxD5 */
  67. {5, 21, 1, 0, 2}, /* TxD6 */
  68. {5, 20, 1, 0, 2}, /* TxD7 */
  69. {5, 15, 2, 0, 2}, /* RxD0 */
  70. {5, 14, 2, 0, 2}, /* RxD1 */
  71. {5, 13, 2, 0, 2}, /* RxD2 */
  72. {5, 12, 2, 0, 2}, /* RxD3 */
  73. {5, 29, 2, 0, 2}, /* RxD4 */
  74. {5, 28, 2, 0, 2}, /* RxD5 */
  75. {5, 27, 2, 0, 3}, /* RxD6 */
  76. {5, 26, 2, 0, 2}, /* RxD7 */
  77. {5, 11, 1, 0, 2}, /* TX_EN */
  78. {5, 24, 1, 0, 2}, /* TX_ER */
  79. {5, 16, 2, 0, 2}, /* RX_DV */
  80. {5, 30, 2, 0, 2}, /* RX_ER */
  81. {5, 17, 2, 0, 2}, /* RX_CLK */
  82. {5, 19, 1, 0, 2}, /* GTX_CLK */
  83. {1, 31, 2, 0, 3}, /* GTX125 */
  84. {4, 6, 3, 0, 2}, /* MDIO */
  85. {4, 5, 1, 0, 2}, /* MDC */
  86. /* UART1 */
  87. {2, 0, 1, 0, 2}, /* UART_SOUT1 */
  88. {2, 1, 1, 0, 2}, /* UART_RTS1 */
  89. {2, 2, 2, 0, 2}, /* UART_CTS1 */
  90. {2, 3, 2, 0, 2}, /* UART_SIN1 */
  91. {0, 0, 0, 0, QE_IOP_TAB_END}, /* END of table */
  92. };
  93. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  94. extern void ddr_enable_ecc(unsigned int dram_size);
  95. #endif
  96. extern long int spd_sdram(void);
  97. void local_bus_init(void);
  98. void sdram_init(void);
  99. int board_early_init_f (void)
  100. {
  101. /*
  102. * Initialize local bus.
  103. */
  104. local_bus_init ();
  105. enable_8568mds_duart();
  106. enable_8568mds_flash_write();
  107. #if defined(CONFIG_UEC_ETH1) || defined(CONFIG_UEC_ETH2)
  108. reset_8568mds_uccs();
  109. #endif
  110. #if defined(CONFIG_QE) && !defined(CONFIG_eTSEC_MDIO_BUS)
  111. enable_8568mds_qe_mdio();
  112. #endif
  113. #ifdef CFG_I2C2_OFFSET
  114. /* Enable I2C2_SCL and I2C2_SDA */
  115. volatile struct par_io *port_c;
  116. port_c = (struct par_io*)(CFG_IMMR + 0xe0140);
  117. port_c->cpdir2 |= 0x0f000000;
  118. port_c->cppar2 &= ~0x0f000000;
  119. port_c->cppar2 |= 0x0a000000;
  120. #endif
  121. return 0;
  122. }
  123. int checkboard (void)
  124. {
  125. printf ("Board: 8568 MDS\n");
  126. return 0;
  127. }
  128. long int
  129. initdram(int board_type)
  130. {
  131. long dram_size = 0;
  132. puts("Initializing\n");
  133. #if defined(CONFIG_DDR_DLL)
  134. {
  135. /*
  136. * Work around to stabilize DDR DLL MSYNC_IN.
  137. * Errata DDR9 seems to have been fixed.
  138. * This is now the workaround for Errata DDR11:
  139. * Override DLL = 1, Course Adj = 1, Tap Select = 0
  140. */
  141. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  142. gur->ddrdllcr = 0x81000000;
  143. asm("sync;isync;msync");
  144. udelay(200);
  145. }
  146. #endif
  147. dram_size = spd_sdram();
  148. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  149. /*
  150. * Initialize and enable DDR ECC.
  151. */
  152. ddr_enable_ecc(dram_size);
  153. #endif
  154. /*
  155. * SDRAM Initialization
  156. */
  157. sdram_init();
  158. puts(" DDR: ");
  159. return dram_size;
  160. }
  161. /*
  162. * Initialize Local Bus
  163. */
  164. void
  165. local_bus_init(void)
  166. {
  167. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  168. volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
  169. uint clkdiv;
  170. uint lbc_hz;
  171. sys_info_t sysinfo;
  172. get_sys_info(&sysinfo);
  173. clkdiv = (lbc->lcrr & 0x0f) * 2;
  174. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  175. gur->lbiuiplldcr1 = 0x00078080;
  176. if (clkdiv == 16) {
  177. gur->lbiuiplldcr0 = 0x7c0f1bf0;
  178. } else if (clkdiv == 8) {
  179. gur->lbiuiplldcr0 = 0x6c0f1bf0;
  180. } else if (clkdiv == 4) {
  181. gur->lbiuiplldcr0 = 0x5c0f1bf0;
  182. }
  183. lbc->lcrr |= 0x00030000;
  184. asm("sync;isync;msync");
  185. }
  186. /*
  187. * Initialize SDRAM memory on the Local Bus.
  188. */
  189. void
  190. sdram_init(void)
  191. {
  192. #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
  193. uint idx;
  194. volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
  195. uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
  196. uint lsdmr_common;
  197. puts(" SDRAM: ");
  198. print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  199. /*
  200. * Setup SDRAM Base and Option Registers
  201. */
  202. lbc->or2 = CFG_OR2_PRELIM;
  203. asm("msync");
  204. lbc->br2 = CFG_BR2_PRELIM;
  205. asm("msync");
  206. lbc->lbcr = CFG_LBC_LBCR;
  207. asm("msync");
  208. lbc->lsrt = CFG_LBC_LSRT;
  209. lbc->mrtpr = CFG_LBC_MRTPR;
  210. asm("msync");
  211. /*
  212. * MPC8568 uses "new" 15-16 style addressing.
  213. */
  214. lsdmr_common = CFG_LBC_LSDMR_COMMON;
  215. lsdmr_common |= CFG_LBC_LSDMR_BSMA1516;
  216. /*
  217. * Issue PRECHARGE ALL command.
  218. */
  219. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL;
  220. asm("sync;msync");
  221. *sdram_addr = 0xff;
  222. ppcDcbf((unsigned long) sdram_addr);
  223. udelay(100);
  224. /*
  225. * Issue 8 AUTO REFRESH commands.
  226. */
  227. for (idx = 0; idx < 8; idx++) {
  228. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH;
  229. asm("sync;msync");
  230. *sdram_addr = 0xff;
  231. ppcDcbf((unsigned long) sdram_addr);
  232. udelay(100);
  233. }
  234. /*
  235. * Issue 8 MODE-set command.
  236. */
  237. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW;
  238. asm("sync;msync");
  239. *sdram_addr = 0xff;
  240. ppcDcbf((unsigned long) sdram_addr);
  241. udelay(100);
  242. /*
  243. * Issue NORMAL OP command.
  244. */
  245. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL;
  246. asm("sync;msync");
  247. *sdram_addr = 0xff;
  248. ppcDcbf((unsigned long) sdram_addr);
  249. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  250. #endif /* enable SDRAM init */
  251. }
  252. #if defined(CFG_DRAM_TEST)
  253. int
  254. testdram(void)
  255. {
  256. uint *pstart = (uint *) CFG_MEMTEST_START;
  257. uint *pend = (uint *) CFG_MEMTEST_END;
  258. uint *p;
  259. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  260. CFG_MEMTEST_START,
  261. CFG_MEMTEST_END);
  262. printf("DRAM test phase 1:\n");
  263. for (p = pstart; p < pend; p++)
  264. *p = 0xaaaaaaaa;
  265. for (p = pstart; p < pend; p++) {
  266. if (*p != 0xaaaaaaaa) {
  267. printf ("DRAM test fails at: %08x\n", (uint) p);
  268. return 1;
  269. }
  270. }
  271. printf("DRAM test phase 2:\n");
  272. for (p = pstart; p < pend; p++)
  273. *p = 0x55555555;
  274. for (p = pstart; p < pend; p++) {
  275. if (*p != 0x55555555) {
  276. printf ("DRAM test fails at: %08x\n", (uint) p);
  277. return 1;
  278. }
  279. }
  280. printf("DRAM test passed.\n");
  281. return 0;
  282. }
  283. #endif
  284. #if defined(CONFIG_PCI)
  285. #ifndef CONFIG_PCI_PNP
  286. static struct pci_config_table pci_mpc8568mds_config_table[] = {
  287. {
  288. PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  289. pci_cfgfunc_config_device,
  290. {PCI_ENET0_IOADDR,
  291. PCI_ENET0_MEMADDR,
  292. PCI_COMMON_MEMORY | PCI_COMMAND_MASTER}
  293. },
  294. {}
  295. };
  296. #endif
  297. static struct pci_controller pci1_hose = {
  298. #ifndef CONFIG_PCI_PNP
  299. config_table: pci_mpc8568mds_config_table,
  300. #endif
  301. };
  302. #endif /* CONFIG_PCI */
  303. #ifdef CONFIG_PCIE1
  304. static struct pci_controller pcie1_hose;
  305. #endif /* CONFIG_PCIE1 */
  306. int first_free_busno = 0;
  307. /*
  308. * pib_init() -- Initialize the PCA9555 IO expander on the PIB board
  309. */
  310. void
  311. pib_init(void)
  312. {
  313. u8 val8, orig_i2c_bus;
  314. /*
  315. * Assign PIB PMC2/3 to PCI bus
  316. */
  317. /*switch temporarily to I2C bus #2 */
  318. orig_i2c_bus = i2c_get_bus_num();
  319. i2c_set_bus_num(1);
  320. val8 = 0x00;
  321. i2c_write(0x23, 0x6, 1, &val8, 1);
  322. i2c_write(0x23, 0x7, 1, &val8, 1);
  323. val8 = 0xff;
  324. i2c_write(0x23, 0x2, 1, &val8, 1);
  325. i2c_write(0x23, 0x3, 1, &val8, 1);
  326. val8 = 0x00;
  327. i2c_write(0x26, 0x6, 1, &val8, 1);
  328. val8 = 0x34;
  329. i2c_write(0x26, 0x7, 1, &val8, 1);
  330. val8 = 0xf9;
  331. i2c_write(0x26, 0x2, 1, &val8, 1);
  332. val8 = 0xff;
  333. i2c_write(0x26, 0x3, 1, &val8, 1);
  334. val8 = 0x00;
  335. i2c_write(0x27, 0x6, 1, &val8, 1);
  336. i2c_write(0x27, 0x7, 1, &val8, 1);
  337. val8 = 0xff;
  338. i2c_write(0x27, 0x2, 1, &val8, 1);
  339. val8 = 0xef;
  340. i2c_write(0x27, 0x3, 1, &val8, 1);
  341. asm("eieio");
  342. }
  343. #ifdef CONFIG_PCI
  344. void
  345. pci_init_board(void)
  346. {
  347. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  348. uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  349. uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  350. #ifdef CONFIG_PCI1
  351. {
  352. pib_init();
  353. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI1_ADDR;
  354. extern void fsl_pci_init(struct pci_controller *hose);
  355. struct pci_controller *hose = &pci1_hose;
  356. uint pci_32 = 1; /* PORDEVSR[15] */
  357. uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB; /* PORDEVSR[14] */
  358. uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD; /* PORPLLSR[16] */
  359. uint pci_agent = (host_agent == 3) || (host_agent == 4 ) || (host_agent == 6);
  360. uint pci_speed = 66666000;
  361. if (!(gur->devdisr & MPC85xx_DEVDISR_PCI1)) {
  362. printf (" PCI: %d bit, %s MHz, %s, %s, %s\n",
  363. (pci_32) ? 32 : 64,
  364. (pci_speed == 33333000) ? "33" :
  365. (pci_speed == 66666000) ? "66" : "unknown",
  366. pci_clk_sel ? "sync" : "async",
  367. pci_agent ? "agent" : "host",
  368. pci_arb ? "arbiter" : "external-arbiter"
  369. );
  370. /* inbound */
  371. pci_set_region(hose->regions + 0,
  372. CFG_PCI_MEMORY_BUS,
  373. CFG_PCI_MEMORY_PHYS,
  374. CFG_PCI_MEMORY_SIZE,
  375. PCI_REGION_MEM | PCI_REGION_MEMORY);
  376. /* outbound memory */
  377. pci_set_region(hose->regions + 1,
  378. CFG_PCI1_MEM_BASE,
  379. CFG_PCI1_MEM_PHYS,
  380. CFG_PCI1_MEM_SIZE,
  381. PCI_REGION_MEM);
  382. /* outbound io */
  383. pci_set_region(hose->regions + 2,
  384. CFG_PCI1_IO_BASE,
  385. CFG_PCI1_IO_PHYS,
  386. CFG_PCI1_IO_SIZE,
  387. PCI_REGION_IO);
  388. hose->region_count = 3;
  389. hose->first_busno = first_free_busno;
  390. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  391. fsl_pci_init(hose);
  392. first_free_busno = hose->last_busno+1;
  393. printf ("PCI on bus %02x - %02x\n",hose->first_busno,hose->last_busno);
  394. } else {
  395. printf (" PCI: disabled\n");
  396. }
  397. }
  398. #else
  399. gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
  400. #endif
  401. #ifdef CONFIG_PCIE1
  402. {
  403. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE1_ADDR;
  404. extern void fsl_pci_init(struct pci_controller *hose);
  405. struct pci_controller *hose = &pcie1_hose;
  406. int pcie_ep = (host_agent == 0) || (host_agent == 2 ) || (host_agent == 3);
  407. int pcie_configured = io_sel >= 1;
  408. if (pcie_configured && !(gur->devdisr & MPC85xx_DEVDISR_PCIE)){
  409. printf ("\n PCIE connected to slot as %s (base address %x)",
  410. pcie_ep ? "End Point" : "Root Complex",
  411. (uint)pci);
  412. if (pci->pme_msg_det) {
  413. pci->pme_msg_det = 0xffffffff;
  414. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  415. }
  416. printf ("\n");
  417. /* inbound */
  418. pci_set_region(hose->regions + 0,
  419. CFG_PCI_MEMORY_BUS,
  420. CFG_PCI_MEMORY_PHYS,
  421. CFG_PCI_MEMORY_SIZE,
  422. PCI_REGION_MEM | PCI_REGION_MEMORY);
  423. /* outbound memory */
  424. pci_set_region(hose->regions + 1,
  425. CFG_PCIE1_MEM_BASE,
  426. CFG_PCIE1_MEM_PHYS,
  427. CFG_PCIE1_MEM_SIZE,
  428. PCI_REGION_MEM);
  429. /* outbound io */
  430. pci_set_region(hose->regions + 2,
  431. CFG_PCIE1_IO_BASE,
  432. CFG_PCIE1_IO_PHYS,
  433. CFG_PCIE1_IO_SIZE,
  434. PCI_REGION_IO);
  435. hose->region_count = 3;
  436. hose->first_busno=first_free_busno;
  437. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  438. fsl_pci_init(hose);
  439. printf ("PCIE on bus %02x - %02x\n",hose->first_busno,hose->last_busno);
  440. first_free_busno=hose->last_busno+1;
  441. } else {
  442. printf (" PCIE: disabled\n");
  443. }
  444. }
  445. #else
  446. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  447. #endif
  448. }
  449. #endif /* CONFIG_PCI */
  450. #if defined(CONFIG_OF_BOARD_SETUP)
  451. void
  452. ft_board_setup(void *blob, bd_t *bd)
  453. {
  454. int node, tmp[2];
  455. const char *path;
  456. ft_cpu_setup(blob, bd);
  457. node = fdt_path_offset(blob, "/aliases");
  458. tmp[0] = 0;
  459. if (node >= 0) {
  460. #ifdef CONFIG_PCI1
  461. path = fdt_getprop(blob, node, "pci0", NULL);
  462. if (path) {
  463. tmp[1] = pci1_hose.last_busno - pci1_hose.first_busno;
  464. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  465. }
  466. #endif
  467. #ifdef CONFIG_PCIE1
  468. path = fdt_getprop(blob, node, "pci1", NULL);
  469. if (path) {
  470. tmp[1] = pcie1_hose.last_busno - pcie1_hose.first_busno;
  471. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  472. }
  473. #endif
  474. }
  475. }
  476. #endif