mpc8360emds.c 11 KB

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