mpc8568mds.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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 <spd.h>
  29. #include <i2c.h>
  30. #include <ioports.h>
  31. #include "bcsr.h"
  32. const qe_iop_conf_t qe_iop_conf_tab[] = {
  33. /* GETH1 */
  34. {4, 10, 1, 0, 2}, /* TxD0 */
  35. {4, 9, 1, 0, 2}, /* TxD1 */
  36. {4, 8, 1, 0, 2}, /* TxD2 */
  37. {4, 7, 1, 0, 2}, /* TxD3 */
  38. {4, 23, 1, 0, 2}, /* TxD4 */
  39. {4, 22, 1, 0, 2}, /* TxD5 */
  40. {4, 21, 1, 0, 2}, /* TxD6 */
  41. {4, 20, 1, 0, 2}, /* TxD7 */
  42. {4, 15, 2, 0, 2}, /* RxD0 */
  43. {4, 14, 2, 0, 2}, /* RxD1 */
  44. {4, 13, 2, 0, 2}, /* RxD2 */
  45. {4, 12, 2, 0, 2}, /* RxD3 */
  46. {4, 29, 2, 0, 2}, /* RxD4 */
  47. {4, 28, 2, 0, 2}, /* RxD5 */
  48. {4, 27, 2, 0, 2}, /* RxD6 */
  49. {4, 26, 2, 0, 2}, /* RxD7 */
  50. {4, 11, 1, 0, 2}, /* TX_EN */
  51. {4, 24, 1, 0, 2}, /* TX_ER */
  52. {4, 16, 2, 0, 2}, /* RX_DV */
  53. {4, 30, 2, 0, 2}, /* RX_ER */
  54. {4, 17, 2, 0, 2}, /* RX_CLK */
  55. {4, 19, 1, 0, 2}, /* GTX_CLK */
  56. {1, 31, 2, 0, 3}, /* GTX125 */
  57. /* GETH2 */
  58. {5, 10, 1, 0, 2}, /* TxD0 */
  59. {5, 9, 1, 0, 2}, /* TxD1 */
  60. {5, 8, 1, 0, 2}, /* TxD2 */
  61. {5, 7, 1, 0, 2}, /* TxD3 */
  62. {5, 23, 1, 0, 2}, /* TxD4 */
  63. {5, 22, 1, 0, 2}, /* TxD5 */
  64. {5, 21, 1, 0, 2}, /* TxD6 */
  65. {5, 20, 1, 0, 2}, /* TxD7 */
  66. {5, 15, 2, 0, 2}, /* RxD0 */
  67. {5, 14, 2, 0, 2}, /* RxD1 */
  68. {5, 13, 2, 0, 2}, /* RxD2 */
  69. {5, 12, 2, 0, 2}, /* RxD3 */
  70. {5, 29, 2, 0, 2}, /* RxD4 */
  71. {5, 28, 2, 0, 2}, /* RxD5 */
  72. {5, 27, 2, 0, 3}, /* RxD6 */
  73. {5, 26, 2, 0, 2}, /* RxD7 */
  74. {5, 11, 1, 0, 2}, /* TX_EN */
  75. {5, 24, 1, 0, 2}, /* TX_ER */
  76. {5, 16, 2, 0, 2}, /* RX_DV */
  77. {5, 30, 2, 0, 2}, /* RX_ER */
  78. {5, 17, 2, 0, 2}, /* RX_CLK */
  79. {5, 19, 1, 0, 2}, /* GTX_CLK */
  80. {1, 31, 2, 0, 3}, /* GTX125 */
  81. {4, 6, 3, 0, 2}, /* MDIO */
  82. {4, 5, 1, 0, 2}, /* MDC */
  83. {0, 0, 0, 0, QE_IOP_TAB_END}, /* END of table */
  84. };
  85. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  86. extern void ddr_enable_ecc(unsigned int dram_size);
  87. #endif
  88. extern long int spd_sdram(void);
  89. void local_bus_init(void);
  90. void sdram_init(void);
  91. int board_early_init_f (void)
  92. {
  93. /*
  94. * Initialize local bus.
  95. */
  96. local_bus_init ();
  97. enable_8568mds_duart();
  98. enable_8568mds_flash_write();
  99. #if defined(CONFIG_QE) && !defined(CONFIG_eTSEC_MDIO_BUS)
  100. enable_8568mds_qe_mdio();
  101. #endif
  102. #ifdef CFG_I2C2_OFFSET
  103. /* Enable I2C2_SCL and I2C2_SDA */
  104. volatile struct par_io *port_c;
  105. port_c = (struct par_io*)(CFG_IMMR + 0xe0140);
  106. port_c->cpdir2 |= 0x0f000000;
  107. port_c->cppar2 &= ~0x0f000000;
  108. port_c->cppar2 |= 0x0a000000;
  109. #endif
  110. return 0;
  111. }
  112. int checkboard (void)
  113. {
  114. printf ("Board: 8568 MDS\n");
  115. return 0;
  116. }
  117. long int
  118. initdram(int board_type)
  119. {
  120. long dram_size = 0;
  121. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  122. puts("Initializing\n");
  123. #if defined(CONFIG_DDR_DLL)
  124. {
  125. /*
  126. * Work around to stabilize DDR DLL MSYNC_IN.
  127. * Errata DDR9 seems to have been fixed.
  128. * This is now the workaround for Errata DDR11:
  129. * Override DLL = 1, Course Adj = 1, Tap Select = 0
  130. */
  131. volatile ccsr_gur_t *gur= &immap->im_gur;
  132. gur->ddrdllcr = 0x81000000;
  133. asm("sync;isync;msync");
  134. udelay(200);
  135. }
  136. #endif
  137. dram_size = spd_sdram();
  138. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  139. /*
  140. * Initialize and enable DDR ECC.
  141. */
  142. ddr_enable_ecc(dram_size);
  143. #endif
  144. /*
  145. * SDRAM Initialization
  146. */
  147. sdram_init();
  148. puts(" DDR: ");
  149. return dram_size;
  150. }
  151. /*
  152. * Initialize Local Bus
  153. */
  154. void
  155. local_bus_init(void)
  156. {
  157. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  158. volatile ccsr_gur_t *gur = &immap->im_gur;
  159. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  160. uint clkdiv;
  161. uint lbc_hz;
  162. sys_info_t sysinfo;
  163. get_sys_info(&sysinfo);
  164. clkdiv = (lbc->lcrr & 0x0f) * 2;
  165. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  166. gur->lbiuiplldcr1 = 0x00078080;
  167. if (clkdiv == 16) {
  168. gur->lbiuiplldcr0 = 0x7c0f1bf0;
  169. } else if (clkdiv == 8) {
  170. gur->lbiuiplldcr0 = 0x6c0f1bf0;
  171. } else if (clkdiv == 4) {
  172. gur->lbiuiplldcr0 = 0x5c0f1bf0;
  173. }
  174. lbc->lcrr |= 0x00030000;
  175. asm("sync;isync;msync");
  176. }
  177. /*
  178. * Initialize SDRAM memory on the Local Bus.
  179. */
  180. void
  181. sdram_init(void)
  182. {
  183. #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
  184. uint idx;
  185. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  186. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  187. uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
  188. uint lsdmr_common;
  189. puts(" SDRAM: ");
  190. print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  191. /*
  192. * Setup SDRAM Base and Option Registers
  193. */
  194. lbc->or2 = CFG_OR2_PRELIM;
  195. asm("msync");
  196. lbc->br2 = CFG_BR2_PRELIM;
  197. asm("msync");
  198. lbc->lbcr = CFG_LBC_LBCR;
  199. asm("msync");
  200. lbc->lsrt = CFG_LBC_LSRT;
  201. lbc->mrtpr = CFG_LBC_MRTPR;
  202. asm("msync");
  203. /*
  204. * MPC8568 uses "new" 15-16 style addressing.
  205. */
  206. lsdmr_common = CFG_LBC_LSDMR_COMMON;
  207. lsdmr_common |= CFG_LBC_LSDMR_BSMA1516;
  208. /*
  209. * Issue PRECHARGE ALL command.
  210. */
  211. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL;
  212. asm("sync;msync");
  213. *sdram_addr = 0xff;
  214. ppcDcbf((unsigned long) sdram_addr);
  215. udelay(100);
  216. /*
  217. * Issue 8 AUTO REFRESH commands.
  218. */
  219. for (idx = 0; idx < 8; idx++) {
  220. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH;
  221. asm("sync;msync");
  222. *sdram_addr = 0xff;
  223. ppcDcbf((unsigned long) sdram_addr);
  224. udelay(100);
  225. }
  226. /*
  227. * Issue 8 MODE-set command.
  228. */
  229. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW;
  230. asm("sync;msync");
  231. *sdram_addr = 0xff;
  232. ppcDcbf((unsigned long) sdram_addr);
  233. udelay(100);
  234. /*
  235. * Issue NORMAL OP command.
  236. */
  237. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL;
  238. asm("sync;msync");
  239. *sdram_addr = 0xff;
  240. ppcDcbf((unsigned long) sdram_addr);
  241. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  242. #endif /* enable SDRAM init */
  243. }
  244. #if defined(CFG_DRAM_TEST)
  245. int
  246. testdram(void)
  247. {
  248. uint *pstart = (uint *) CFG_MEMTEST_START;
  249. uint *pend = (uint *) CFG_MEMTEST_END;
  250. uint *p;
  251. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  252. CFG_MEMTEST_START,
  253. CFG_MEMTEST_END);
  254. printf("DRAM test phase 1:\n");
  255. for (p = pstart; p < pend; p++)
  256. *p = 0xaaaaaaaa;
  257. for (p = pstart; p < pend; p++) {
  258. if (*p != 0xaaaaaaaa) {
  259. printf ("DRAM test fails at: %08x\n", (uint) p);
  260. return 1;
  261. }
  262. }
  263. printf("DRAM test phase 2:\n");
  264. for (p = pstart; p < pend; p++)
  265. *p = 0x55555555;
  266. for (p = pstart; p < pend; p++) {
  267. if (*p != 0x55555555) {
  268. printf ("DRAM test fails at: %08x\n", (uint) p);
  269. return 1;
  270. }
  271. }
  272. printf("DRAM test passed.\n");
  273. return 0;
  274. }
  275. #endif
  276. #if defined(CONFIG_PCI)
  277. #ifndef CONFIG_PCI_PNP
  278. static struct pci_config_table pci_mpc8568mds_config_table[] = {
  279. {
  280. PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  281. pci_cfgfunc_config_device,
  282. {PCI_ENET0_IOADDR,
  283. PCI_ENET0_MEMADDR,
  284. PCI_COMMON_MEMORY | PCI_COMMAND_MASTER}
  285. },
  286. {}
  287. };
  288. #endif
  289. static struct pci_controller hose[] = {
  290. {
  291. #ifndef CONFIG_PCI_PNP
  292. config_table: pci_mpc8568mds_config_table,
  293. #endif
  294. }
  295. };
  296. #endif /* CONFIG_PCI */
  297. /*
  298. * pib_init() -- Initialize the PCA9555 IO expander on the PIB board
  299. */
  300. void
  301. pib_init(void)
  302. {
  303. u8 val8, orig_i2c_bus;
  304. /*
  305. * Assign PIB PMC2/3 to PCI bus
  306. */
  307. /*switch temporarily to I2C bus #2 */
  308. orig_i2c_bus = i2c_get_bus_num();
  309. i2c_set_bus_num(1);
  310. val8 = 0x00;
  311. i2c_write(0x23, 0x6, 1, &val8, 1);
  312. i2c_write(0x23, 0x7, 1, &val8, 1);
  313. val8 = 0xff;
  314. i2c_write(0x23, 0x2, 1, &val8, 1);
  315. i2c_write(0x23, 0x3, 1, &val8, 1);
  316. val8 = 0x00;
  317. i2c_write(0x26, 0x6, 1, &val8, 1);
  318. val8 = 0x34;
  319. i2c_write(0x26, 0x7, 1, &val8, 1);
  320. val8 = 0xf9;
  321. i2c_write(0x26, 0x2, 1, &val8, 1);
  322. val8 = 0xff;
  323. i2c_write(0x26, 0x3, 1, &val8, 1);
  324. val8 = 0x00;
  325. i2c_write(0x27, 0x6, 1, &val8, 1);
  326. i2c_write(0x27, 0x7, 1, &val8, 1);
  327. val8 = 0xff;
  328. i2c_write(0x27, 0x2, 1, &val8, 1);
  329. val8 = 0xef;
  330. i2c_write(0x27, 0x3, 1, &val8, 1);
  331. asm("eieio");
  332. }
  333. void
  334. pci_init_board(void)
  335. {
  336. #ifdef CONFIG_PCI
  337. pib_init();
  338. pci_mpc85xx_init(hose);
  339. #endif
  340. }