mpc8360emds.c 10 KB

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