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