mpc8360emds.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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 <spd.h>
  18. #include <miiphy.h>
  19. #if defined(CONFIG_PCI)
  20. #include <pci.h>
  21. #endif
  22. #if defined(CONFIG_SPD_EEPROM)
  23. #include <spd_sdram.h>
  24. #else
  25. #include <asm/mmu.h>
  26. #endif
  27. #if defined(CONFIG_OF_FLAT_TREE)
  28. #include <ft_build.h>
  29. #elif defined(CONFIG_OF_LIBFDT)
  30. #include <libfdt.h>
  31. #endif
  32. #if defined(CONFIG_PQ_MDS_PIB)
  33. #include "../common/pq-mds-pib.h"
  34. #endif
  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. int board_early_init_f(void)
  93. {
  94. u8 *bcsr = (u8 *)CFG_BCSR;
  95. const immap_t *immr = (immap_t *)CFG_IMMR;
  96. /* Enable flash write */
  97. bcsr[0xa] &= ~0x04;
  98. /* Disable G1TXCLK, G2TXCLK h/w buffers (rev.2 h/w bug workaround) */
  99. if (immr->sysconf.spridr == SPR_8360_REV20 ||
  100. immr->sysconf.spridr == SPR_8360E_REV20 ||
  101. immr->sysconf.spridr == SPR_8360_REV21 ||
  102. immr->sysconf.spridr == SPR_8360E_REV21)
  103. bcsr[0xe] = 0x30;
  104. /* Enable second UART */
  105. bcsr[0x9] &= ~0x01;
  106. return 0;
  107. }
  108. int board_early_init_r(void)
  109. {
  110. #ifdef CONFIG_PQ_MDS_PIB
  111. pib_init();
  112. #endif
  113. return 0;
  114. }
  115. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  116. extern void ddr_enable_ecc(unsigned int dram_size);
  117. #endif
  118. int fixed_sdram(void);
  119. void sdram_init(void);
  120. long int initdram(int board_type)
  121. {
  122. volatile immap_t *im = (immap_t *) CFG_IMMR;
  123. u32 msize = 0;
  124. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
  125. return -1;
  126. /* DDR SDRAM - Main SODIMM */
  127. im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR;
  128. #if defined(CONFIG_SPD_EEPROM)
  129. msize = spd_sdram();
  130. #else
  131. msize = fixed_sdram();
  132. #endif
  133. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  134. /*
  135. * Initialize DDR ECC byte
  136. */
  137. ddr_enable_ecc(msize * 1024 * 1024);
  138. #endif
  139. /*
  140. * Initialize SDRAM if it is on local bus.
  141. */
  142. sdram_init();
  143. /* return total bus SDRAM size(bytes) -- DDR */
  144. return (msize * 1024 * 1024);
  145. }
  146. #if !defined(CONFIG_SPD_EEPROM)
  147. /*************************************************************************
  148. * fixed sdram init -- doesn't use serial presence detect.
  149. ************************************************************************/
  150. int fixed_sdram(void)
  151. {
  152. volatile immap_t *im = (immap_t *) CFG_IMMR;
  153. u32 msize = 0;
  154. u32 ddr_size;
  155. u32 ddr_size_log2;
  156. msize = CFG_DDR_SIZE;
  157. for (ddr_size = msize << 20, ddr_size_log2 = 0;
  158. (ddr_size > 1); ddr_size = ddr_size >> 1, ddr_size_log2++) {
  159. if (ddr_size & 1) {
  160. return -1;
  161. }
  162. }
  163. im->sysconf.ddrlaw[0].ar =
  164. LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
  165. #if (CFG_DDR_SIZE != 256)
  166. #warning Currenly any ddr size other than 256 is not supported
  167. #endif
  168. #ifdef CONFIG_DDR_II
  169. im->ddr.csbnds[0].csbnds = CFG_DDR_CS0_BNDS;
  170. im->ddr.cs_config[0] = CFG_DDR_CS0_CONFIG;
  171. im->ddr.timing_cfg_0 = CFG_DDR_TIMING_0;
  172. im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
  173. im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
  174. im->ddr.timing_cfg_3 = CFG_DDR_TIMING_3;
  175. im->ddr.sdram_cfg = CFG_DDR_SDRAM_CFG;
  176. im->ddr.sdram_cfg2 = CFG_DDR_SDRAM_CFG2;
  177. im->ddr.sdram_mode = CFG_DDR_MODE;
  178. im->ddr.sdram_mode2 = CFG_DDR_MODE2;
  179. im->ddr.sdram_interval = CFG_DDR_INTERVAL;
  180. im->ddr.sdram_clk_cntl = CFG_DDR_CLK_CNTL;
  181. #else
  182. im->ddr.csbnds[0].csbnds = 0x00000007;
  183. im->ddr.csbnds[1].csbnds = 0x0008000f;
  184. im->ddr.cs_config[0] = CFG_DDR_CONFIG;
  185. im->ddr.cs_config[1] = CFG_DDR_CONFIG;
  186. im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
  187. im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
  188. im->ddr.sdram_cfg = CFG_DDR_CONTROL;
  189. im->ddr.sdram_mode = CFG_DDR_MODE;
  190. im->ddr.sdram_interval = CFG_DDR_INTERVAL;
  191. #endif
  192. udelay(200);
  193. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  194. return msize;
  195. }
  196. #endif /*!CFG_SPD_EEPROM */
  197. int checkboard(void)
  198. {
  199. puts("Board: Freescale MPC8360EMDS\n");
  200. return 0;
  201. }
  202. /*
  203. * if MPC8360EMDS is soldered with SDRAM
  204. */
  205. #if defined(CFG_BR2_PRELIM) \
  206. && defined(CFG_OR2_PRELIM) \
  207. && defined(CFG_LBLAWBAR2_PRELIM) \
  208. && defined(CFG_LBLAWAR2_PRELIM)
  209. /*
  210. * Initialize SDRAM memory on the Local Bus.
  211. */
  212. void sdram_init(void)
  213. {
  214. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  215. volatile lbus83xx_t *lbc = &immap->lbus;
  216. uint *sdram_addr = (uint *) CFG_LBC_SDRAM_BASE;
  217. /*
  218. * Setup SDRAM Base and Option Registers, already done in cpu_init.c
  219. */
  220. /*setup mtrpt, lsrt and lbcr for LB bus */
  221. lbc->lbcr = CFG_LBC_LBCR;
  222. lbc->mrtpr = CFG_LBC_MRTPR;
  223. lbc->lsrt = CFG_LBC_LSRT;
  224. asm("sync");
  225. /*
  226. * Configure the SDRAM controller Machine Mode Register.
  227. */
  228. lbc->lsdmr = CFG_LBC_LSDMR_5; /* Normal Operation */
  229. lbc->lsdmr = CFG_LBC_LSDMR_1; /* Precharge All Banks */
  230. asm("sync");
  231. *sdram_addr = 0xff;
  232. udelay(100);
  233. /*
  234. * We need do 8 times auto refresh operation.
  235. */
  236. lbc->lsdmr = CFG_LBC_LSDMR_2;
  237. asm("sync");
  238. *sdram_addr = 0xff; /* 1 times */
  239. udelay(100);
  240. *sdram_addr = 0xff; /* 2 times */
  241. udelay(100);
  242. *sdram_addr = 0xff; /* 3 times */
  243. udelay(100);
  244. *sdram_addr = 0xff; /* 4 times */
  245. udelay(100);
  246. *sdram_addr = 0xff; /* 5 times */
  247. udelay(100);
  248. *sdram_addr = 0xff; /* 6 times */
  249. udelay(100);
  250. *sdram_addr = 0xff; /* 7 times */
  251. udelay(100);
  252. *sdram_addr = 0xff; /* 8 times */
  253. udelay(100);
  254. /* Mode register write operation */
  255. lbc->lsdmr = CFG_LBC_LSDMR_4;
  256. asm("sync");
  257. *(sdram_addr + 0xcc) = 0xff;
  258. udelay(100);
  259. /* Normal operation */
  260. lbc->lsdmr = CFG_LBC_LSDMR_5 | 0x40000000;
  261. asm("sync");
  262. *sdram_addr = 0xff;
  263. udelay(100);
  264. }
  265. #else
  266. void sdram_init(void)
  267. {
  268. }
  269. #endif
  270. #if defined(CONFIG_OF_BOARD_SETUP)
  271. void ft_board_setup(void *blob, bd_t *bd)
  272. {
  273. const immap_t *immr = (immap_t *)CFG_IMMR;
  274. #if defined(CONFIG_OF_FLAT_TREE)
  275. u32 *p;
  276. int len;
  277. p = ft_get_prop(blob, "/memory/reg", &len);
  278. if (p != NULL) {
  279. *p++ = cpu_to_be32(bd->bi_memstart);
  280. *p = cpu_to_be32(bd->bi_memsize);
  281. }
  282. #endif
  283. ft_cpu_setup(blob, bd);
  284. #ifdef CONFIG_PCI
  285. ft_pci_setup(blob, bd);
  286. #endif
  287. /*
  288. * mpc8360ea pb mds errata 2: RGMII timing
  289. * if on mpc8360ea rev. 2.1,
  290. * change both ucc phy-connection-types from rgmii-id to rgmii-rxid
  291. */
  292. if (immr->sysconf.spridr == SPR_8360_REV21 ||
  293. immr->sysconf.spridr == SPR_8360E_REV21) {
  294. int nodeoffset;
  295. void *prop;
  296. /* fixup UCC 1 if using rgmii-id mode */
  297. nodeoffset = fdt_path_offset(blob, "/" OF_QE "/ucc@2000");
  298. if (nodeoffset >= 0) {
  299. prop = fdt_getprop(blob, nodeoffset,
  300. "phy-connection-type", 0);
  301. if (prop && (strcmp(prop, "rgmii-id") == 0))
  302. fdt_setprop(blob, nodeoffset, "phy-connection-type",
  303. "rgmii-rxid", sizeof("rgmii-rxid"));
  304. }
  305. /* fixup UCC 2 if using rgmii-id mode */
  306. nodeoffset = fdt_path_offset(blob, "/" OF_QE "/ucc@3000");
  307. if (nodeoffset >= 0) {
  308. prop = fdt_getprop(blob, nodeoffset,
  309. "phy-connection-type", 0);
  310. if (prop && (strcmp(prop, "rgmii-id") == 0))
  311. fdt_setprop(blob, nodeoffset, "phy-connection-type",
  312. "rgmii-rxid", sizeof("rgmii-rxid"));
  313. }
  314. }
  315. }
  316. #endif