mpc8360emds.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. /*
  2. * Copyright (C) 2006,2010-2011 Freescale Semiconductor, Inc.
  3. * Dave Liu <daveliu@freescale.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. */
  13. #include <common.h>
  14. #include <ioports.h>
  15. #include <mpc83xx.h>
  16. #include <i2c.h>
  17. #include <miiphy.h>
  18. #include <phy.h>
  19. #if defined(CONFIG_PCI)
  20. #include <pci.h>
  21. #endif
  22. #include <spd_sdram.h>
  23. #include <asm/mmu.h>
  24. #include <asm/io.h>
  25. #include <asm/fsl_enet.h>
  26. #include <asm/mmu.h>
  27. #if defined(CONFIG_OF_LIBFDT)
  28. #include <libfdt.h>
  29. #endif
  30. #include <hwconfig.h>
  31. #include <fdt_support.h>
  32. #if defined(CONFIG_PQ_MDS_PIB)
  33. #include "../common/pq-mds-pib.h"
  34. #endif
  35. #include "../../../drivers/qe/uec.h"
  36. const qe_iop_conf_t qe_iop_conf_tab[] = {
  37. /* GETH1 */
  38. {0, 3, 1, 0, 1}, /* TxD0 */
  39. {0, 4, 1, 0, 1}, /* TxD1 */
  40. {0, 5, 1, 0, 1}, /* TxD2 */
  41. {0, 6, 1, 0, 1}, /* TxD3 */
  42. {1, 6, 1, 0, 3}, /* TxD4 */
  43. {1, 7, 1, 0, 1}, /* TxD5 */
  44. {1, 9, 1, 0, 2}, /* TxD6 */
  45. {1, 10, 1, 0, 2}, /* TxD7 */
  46. {0, 9, 2, 0, 1}, /* RxD0 */
  47. {0, 10, 2, 0, 1}, /* RxD1 */
  48. {0, 11, 2, 0, 1}, /* RxD2 */
  49. {0, 12, 2, 0, 1}, /* RxD3 */
  50. {0, 13, 2, 0, 1}, /* RxD4 */
  51. {1, 1, 2, 0, 2}, /* RxD5 */
  52. {1, 0, 2, 0, 2}, /* RxD6 */
  53. {1, 4, 2, 0, 2}, /* RxD7 */
  54. {0, 7, 1, 0, 1}, /* TX_EN */
  55. {0, 8, 1, 0, 1}, /* TX_ER */
  56. {0, 15, 2, 0, 1}, /* RX_DV */
  57. {0, 16, 2, 0, 1}, /* RX_ER */
  58. {0, 0, 2, 0, 1}, /* RX_CLK */
  59. {2, 9, 1, 0, 3}, /* GTX_CLK - CLK10 */
  60. {2, 8, 2, 0, 1}, /* GTX125 - CLK9 */
  61. /* GETH2 */
  62. {0, 17, 1, 0, 1}, /* TxD0 */
  63. {0, 18, 1, 0, 1}, /* TxD1 */
  64. {0, 19, 1, 0, 1}, /* TxD2 */
  65. {0, 20, 1, 0, 1}, /* TxD3 */
  66. {1, 2, 1, 0, 1}, /* TxD4 */
  67. {1, 3, 1, 0, 2}, /* TxD5 */
  68. {1, 5, 1, 0, 3}, /* TxD6 */
  69. {1, 8, 1, 0, 3}, /* TxD7 */
  70. {0, 23, 2, 0, 1}, /* RxD0 */
  71. {0, 24, 2, 0, 1}, /* RxD1 */
  72. {0, 25, 2, 0, 1}, /* RxD2 */
  73. {0, 26, 2, 0, 1}, /* RxD3 */
  74. {0, 27, 2, 0, 1}, /* RxD4 */
  75. {1, 12, 2, 0, 2}, /* RxD5 */
  76. {1, 13, 2, 0, 3}, /* RxD6 */
  77. {1, 11, 2, 0, 2}, /* RxD7 */
  78. {0, 21, 1, 0, 1}, /* TX_EN */
  79. {0, 22, 1, 0, 1}, /* TX_ER */
  80. {0, 29, 2, 0, 1}, /* RX_DV */
  81. {0, 30, 2, 0, 1}, /* RX_ER */
  82. {0, 31, 2, 0, 1}, /* RX_CLK */
  83. {2, 2, 1, 0, 2}, /* GTX_CLK = CLK10 */
  84. {2, 3, 2, 0, 1}, /* GTX125 - CLK4 */
  85. {0, 1, 3, 0, 2}, /* MDIO */
  86. {0, 2, 1, 0, 1}, /* MDC */
  87. {5, 0, 1, 0, 2}, /* UART2_SOUT */
  88. {5, 1, 2, 0, 3}, /* UART2_CTS */
  89. {5, 2, 1, 0, 1}, /* UART2_RTS */
  90. {5, 3, 2, 0, 2}, /* UART2_SIN */
  91. {0, 0, 0, 0, QE_IOP_TAB_END}, /* END of table */
  92. };
  93. /* Handle "mpc8360ea rev.2.1 erratum 2: RGMII Timing"? */
  94. static int board_handle_erratum2(void)
  95. {
  96. const immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
  97. return REVID_MAJOR(immr->sysconf.spridr) == 2 &&
  98. REVID_MINOR(immr->sysconf.spridr) == 1;
  99. }
  100. int board_early_init_f(void)
  101. {
  102. const immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
  103. u8 *bcsr = (u8 *)CONFIG_SYS_BCSR;
  104. /* Enable flash write */
  105. bcsr[0xa] &= ~0x04;
  106. /* Disable G1TXCLK, G2TXCLK h/w buffers (rev.2.x h/w bug workaround) */
  107. if (REVID_MAJOR(immr->sysconf.spridr) == 2)
  108. bcsr[0xe] = 0x30;
  109. /* Enable second UART */
  110. bcsr[0x9] &= ~0x01;
  111. if (board_handle_erratum2()) {
  112. void *immap = (immap_t *)(CONFIG_SYS_IMMR + 0x14a8);
  113. /*
  114. * IMMR + 0x14A8[4:5] = 11 (clk delay for UCC 2)
  115. * IMMR + 0x14A8[18:19] = 11 (clk delay for UCC 1)
  116. */
  117. setbits_be32(immap, 0x0c003000);
  118. /*
  119. * IMMR + 0x14AC[20:27] = 10101010
  120. * (data delay for both UCC's)
  121. */
  122. clrsetbits_be32(immap + 4, 0xff0, 0xaa0);
  123. }
  124. return 0;
  125. }
  126. int board_early_init_r(void)
  127. {
  128. gd_t *gd;
  129. #ifdef CONFIG_PQ_MDS_PIB
  130. pib_init();
  131. #endif
  132. /*
  133. * BAT6 is used for SDRAM when DDR size is 512MB or larger than 256MB
  134. * So re-setup PCI MEM space used BAT5 after relocated to DDR
  135. */
  136. gd = (gd_t *)(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
  137. if (gd->ram_size > CONFIG_MAX_MEM_MAPPED) {
  138. write_bat(DBAT5, CONFIG_SYS_DBAT6U, CONFIG_SYS_DBAT6L);
  139. write_bat(IBAT5, CONFIG_SYS_IBAT6U, CONFIG_SYS_IBAT6L);
  140. }
  141. return 0;
  142. }
  143. #ifdef CONFIG_UEC_ETH
  144. static uec_info_t uec_info[] = {
  145. #ifdef CONFIG_UEC_ETH1
  146. STD_UEC_INFO(1),
  147. #endif
  148. #ifdef CONFIG_UEC_ETH2
  149. STD_UEC_INFO(2),
  150. #endif
  151. };
  152. int board_eth_init(bd_t *bd)
  153. {
  154. if (board_handle_erratum2()) {
  155. int i;
  156. for (i = 0; i < ARRAY_SIZE(uec_info); i++) {
  157. uec_info[i].enet_interface_type =
  158. PHY_INTERFACE_MODE_RGMII_RXID;
  159. uec_info[i].speed = SPEED_1000;
  160. }
  161. }
  162. return uec_eth_init(bd, uec_info, ARRAY_SIZE(uec_info));
  163. }
  164. #endif /* CONFIG_UEC_ETH */
  165. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  166. extern void ddr_enable_ecc(unsigned int dram_size);
  167. #endif
  168. int fixed_sdram(void);
  169. static int sdram_init(unsigned int base);
  170. phys_size_t initdram(int board_type)
  171. {
  172. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  173. u32 msize = 0;
  174. u32 lbc_sdram_size;
  175. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
  176. return -1;
  177. /* DDR SDRAM - Main SODIMM */
  178. im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_BASE & LAWBAR_BAR;
  179. #if defined(CONFIG_SPD_EEPROM)
  180. msize = spd_sdram();
  181. #else
  182. msize = fixed_sdram();
  183. #endif
  184. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  185. /*
  186. * Initialize DDR ECC byte
  187. */
  188. ddr_enable_ecc(msize * 1024 * 1024);
  189. #endif
  190. /*
  191. * Initialize SDRAM if it is on local bus.
  192. */
  193. lbc_sdram_size = sdram_init(msize * 1024 * 1024);
  194. if (!msize)
  195. msize = lbc_sdram_size;
  196. /* return total bus SDRAM size(bytes) -- DDR */
  197. return (msize * 1024 * 1024);
  198. }
  199. #if !defined(CONFIG_SPD_EEPROM)
  200. /*************************************************************************
  201. * fixed sdram init -- doesn't use serial presence detect.
  202. ************************************************************************/
  203. int fixed_sdram(void)
  204. {
  205. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  206. u32 msize = CONFIG_SYS_DDR_SIZE;
  207. u32 ddr_size = msize << 20;
  208. u32 ddr_size_log2 = __ilog2(ddr_size);
  209. u32 half_ddr_size = ddr_size >> 1;
  210. im->sysconf.ddrlaw[0].bar =
  211. CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
  212. im->sysconf.ddrlaw[0].ar =
  213. LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
  214. #if (CONFIG_SYS_DDR_SIZE != 256)
  215. #warning Currenly any ddr size other than 256 is not supported
  216. #endif
  217. #ifdef CONFIG_DDR_II
  218. im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
  219. im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
  220. im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
  221. im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  222. im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  223. im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
  224. im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
  225. im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
  226. im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
  227. im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
  228. im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  229. im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CNTL;
  230. #else
  231. #if ((CONFIG_SYS_DDR_SDRAM_BASE & 0x00FFFFFF) != 0)
  232. #warning Chip select bounds is only configurable in 16MB increments
  233. #endif
  234. im->ddr.csbnds[0].csbnds =
  235. ((CONFIG_SYS_DDR_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
  236. (((CONFIG_SYS_DDR_SDRAM_BASE + half_ddr_size - 1) >>
  237. CSBNDS_EA_SHIFT) & CSBNDS_EA);
  238. im->ddr.csbnds[1].csbnds =
  239. (((CONFIG_SYS_DDR_SDRAM_BASE + half_ddr_size) >>
  240. CSBNDS_SA_SHIFT) & CSBNDS_SA) |
  241. (((CONFIG_SYS_DDR_SDRAM_BASE + ddr_size - 1) >>
  242. CSBNDS_EA_SHIFT) & CSBNDS_EA);
  243. im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
  244. im->ddr.cs_config[1] = CONFIG_SYS_DDR_CS1_CONFIG;
  245. im->ddr.cs_config[2] = 0;
  246. im->ddr.cs_config[3] = 0;
  247. im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  248. im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  249. im->ddr.sdram_cfg = CONFIG_SYS_DDR_CONTROL;
  250. im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
  251. im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  252. #endif
  253. udelay(200);
  254. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  255. return msize;
  256. }
  257. #endif /*!CONFIG_SYS_SPD_EEPROM */
  258. int checkboard(void)
  259. {
  260. puts("Board: Freescale MPC8360EMDS\n");
  261. return 0;
  262. }
  263. /*
  264. * if MPC8360EMDS is soldered with SDRAM
  265. */
  266. #ifdef CONFIG_SYS_LB_SDRAM
  267. /*
  268. * Initialize SDRAM memory on the Local Bus.
  269. */
  270. static int sdram_init(unsigned int base)
  271. {
  272. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  273. fsl_lbc_t *lbc = LBC_BASE_ADDR;
  274. const int sdram_size = CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024;
  275. int rem = base % sdram_size;
  276. uint *sdram_addr;
  277. /* window base address should be aligned to the window size */
  278. if (rem)
  279. base = base - rem + sdram_size;
  280. /*
  281. * Setup BAT6 for SDRAM when DDR size is 512MB or larger than 256MB
  282. * After relocated to DDR, reuse BAT5 for PCI MEM space
  283. */
  284. if (base > CONFIG_MAX_MEM_MAPPED) {
  285. unsigned long batl = base | BATL_PP_10 | BATL_MEMCOHERENCE;
  286. unsigned long batu = base | BATU_BL_64M | BATU_VS | BATU_VP;
  287. /* Setup the BAT6 for SDRAM */
  288. write_bat(DBAT6, batu, batl);
  289. write_bat(IBAT6, batu, batl);
  290. }
  291. sdram_addr = (uint *)base;
  292. /*
  293. * Setup SDRAM Base and Option Registers
  294. */
  295. set_lbc_br(2, base | CONFIG_SYS_BR2);
  296. set_lbc_or(2, CONFIG_SYS_OR2);
  297. immap->sysconf.lblaw[2].bar = base;
  298. immap->sysconf.lblaw[2].ar = CONFIG_SYS_LBLAWAR2;
  299. /*setup mtrpt, lsrt and lbcr for LB bus */
  300. lbc->lbcr = CONFIG_SYS_LBC_LBCR;
  301. lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
  302. lbc->lsrt = CONFIG_SYS_LBC_LSRT;
  303. asm("sync");
  304. /*
  305. * Configure the SDRAM controller Machine Mode Register.
  306. */
  307. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5; /* Normal Operation */
  308. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1; /* Precharge All Banks */
  309. asm("sync");
  310. *sdram_addr = 0xff;
  311. udelay(100);
  312. /*
  313. * We need do 8 times auto refresh operation.
  314. */
  315. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2;
  316. asm("sync");
  317. *sdram_addr = 0xff; /* 1 times */
  318. udelay(100);
  319. *sdram_addr = 0xff; /* 2 times */
  320. udelay(100);
  321. *sdram_addr = 0xff; /* 3 times */
  322. udelay(100);
  323. *sdram_addr = 0xff; /* 4 times */
  324. udelay(100);
  325. *sdram_addr = 0xff; /* 5 times */
  326. udelay(100);
  327. *sdram_addr = 0xff; /* 6 times */
  328. udelay(100);
  329. *sdram_addr = 0xff; /* 7 times */
  330. udelay(100);
  331. *sdram_addr = 0xff; /* 8 times */
  332. udelay(100);
  333. /* Mode register write operation */
  334. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4;
  335. asm("sync");
  336. *(sdram_addr + 0xcc) = 0xff;
  337. udelay(100);
  338. /* Normal operation */
  339. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5 | 0x40000000;
  340. asm("sync");
  341. *sdram_addr = 0xff;
  342. udelay(100);
  343. /*
  344. * In non-aligned case we don't [normally] use that memory because
  345. * there is a hole.
  346. */
  347. if (rem)
  348. return 0;
  349. return CONFIG_SYS_LBC_SDRAM_SIZE;
  350. }
  351. #else
  352. static int sdram_init(unsigned int base) { return 0; }
  353. #endif
  354. #if defined(CONFIG_OF_BOARD_SETUP)
  355. static void ft_board_fixup_qe_usb(void *blob, bd_t *bd)
  356. {
  357. if (!hwconfig_subarg_cmp("qe_usb", "mode", "peripheral"))
  358. return;
  359. do_fixup_by_compat(blob, "fsl,mpc8323-qe-usb", "mode",
  360. "peripheral", sizeof("peripheral"), 1);
  361. }
  362. void ft_board_setup(void *blob, bd_t *bd)
  363. {
  364. ft_cpu_setup(blob, bd);
  365. #ifdef CONFIG_PCI
  366. ft_pci_setup(blob, bd);
  367. #endif
  368. ft_board_fixup_qe_usb(blob, bd);
  369. /*
  370. * mpc8360ea pb mds errata 2: RGMII timing
  371. * if on mpc8360ea rev. 2.1,
  372. * change both ucc phy-connection-types from rgmii-id to rgmii-rxid
  373. */
  374. if (board_handle_erratum2()) {
  375. int nodeoffset;
  376. const char *prop;
  377. int path;
  378. nodeoffset = fdt_path_offset(blob, "/aliases");
  379. if (nodeoffset >= 0) {
  380. #if defined(CONFIG_HAS_ETH0)
  381. /* fixup UCC 1 if using rgmii-id mode */
  382. prop = fdt_getprop(blob, nodeoffset, "ethernet0", NULL);
  383. if (prop) {
  384. path = fdt_path_offset(blob, prop);
  385. prop = fdt_getprop(blob, path,
  386. "phy-connection-type", 0);
  387. if (prop && (strcmp(prop, "rgmii-id") == 0))
  388. fdt_fixup_phy_connection(blob, path,
  389. PHY_INTERFACE_MODE_RGMII_RXID);
  390. }
  391. #endif
  392. #if defined(CONFIG_HAS_ETH1)
  393. /* fixup UCC 2 if using rgmii-id mode */
  394. prop = fdt_getprop(blob, nodeoffset, "ethernet1", NULL);
  395. if (prop) {
  396. path = fdt_path_offset(blob, prop);
  397. prop = fdt_getprop(blob, path,
  398. "phy-connection-type", 0);
  399. if (prop && (strcmp(prop, "rgmii-id") == 0))
  400. fdt_fixup_phy_connection(blob, path,
  401. PHY_INTERFACE_MODE_RGMII_RXID);
  402. }
  403. #endif
  404. }
  405. }
  406. }
  407. #endif