mpc8360emds.c 9.4 KB

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