mpc8360emds.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. #include <libfdt_env.h>
  32. #endif
  33. const qe_iop_conf_t qe_iop_conf_tab[] = {
  34. /* GETH1 */
  35. {0, 3, 1, 0, 1}, /* TxD0 */
  36. {0, 4, 1, 0, 1}, /* TxD1 */
  37. {0, 5, 1, 0, 1}, /* TxD2 */
  38. {0, 6, 1, 0, 1}, /* TxD3 */
  39. {1, 6, 1, 0, 3}, /* TxD4 */
  40. {1, 7, 1, 0, 1}, /* TxD5 */
  41. {1, 9, 1, 0, 2}, /* TxD6 */
  42. {1, 10, 1, 0, 2}, /* TxD7 */
  43. {0, 9, 2, 0, 1}, /* RxD0 */
  44. {0, 10, 2, 0, 1}, /* RxD1 */
  45. {0, 11, 2, 0, 1}, /* RxD2 */
  46. {0, 12, 2, 0, 1}, /* RxD3 */
  47. {0, 13, 2, 0, 1}, /* RxD4 */
  48. {1, 1, 2, 0, 2}, /* RxD5 */
  49. {1, 0, 2, 0, 2}, /* RxD6 */
  50. {1, 4, 2, 0, 2}, /* RxD7 */
  51. {0, 7, 1, 0, 1}, /* TX_EN */
  52. {0, 8, 1, 0, 1}, /* TX_ER */
  53. {0, 15, 2, 0, 1}, /* RX_DV */
  54. {0, 16, 2, 0, 1}, /* RX_ER */
  55. {0, 0, 2, 0, 1}, /* RX_CLK */
  56. {2, 9, 1, 0, 3}, /* GTX_CLK - CLK10 */
  57. {2, 8, 2, 0, 1}, /* GTX125 - CLK9 */
  58. /* GETH2 */
  59. {0, 17, 1, 0, 1}, /* TxD0 */
  60. {0, 18, 1, 0, 1}, /* TxD1 */
  61. {0, 19, 1, 0, 1}, /* TxD2 */
  62. {0, 20, 1, 0, 1}, /* TxD3 */
  63. {1, 2, 1, 0, 1}, /* TxD4 */
  64. {1, 3, 1, 0, 2}, /* TxD5 */
  65. {1, 5, 1, 0, 3}, /* TxD6 */
  66. {1, 8, 1, 0, 3}, /* TxD7 */
  67. {0, 23, 2, 0, 1}, /* RxD0 */
  68. {0, 24, 2, 0, 1}, /* RxD1 */
  69. {0, 25, 2, 0, 1}, /* RxD2 */
  70. {0, 26, 2, 0, 1}, /* RxD3 */
  71. {0, 27, 2, 0, 1}, /* RxD4 */
  72. {1, 12, 2, 0, 2}, /* RxD5 */
  73. {1, 13, 2, 0, 3}, /* RxD6 */
  74. {1, 11, 2, 0, 2}, /* RxD7 */
  75. {0, 21, 1, 0, 1}, /* TX_EN */
  76. {0, 22, 1, 0, 1}, /* TX_ER */
  77. {0, 29, 2, 0, 1}, /* RX_DV */
  78. {0, 30, 2, 0, 1}, /* RX_ER */
  79. {0, 31, 2, 0, 1}, /* RX_CLK */
  80. {2, 2, 1, 0, 2}, /* GTX_CLK = CLK10 */
  81. {2, 3, 2, 0, 1}, /* GTX125 - CLK4 */
  82. {0, 1, 3, 0, 2}, /* MDIO */
  83. {0, 2, 1, 0, 1}, /* MDC */
  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 *)CFG_BCSR;
  89. const immap_t *immr = (immap_t *)CFG_IMMR;
  90. /* Enable flash write */
  91. bcsr[0xa] &= ~0x04;
  92. /* Disable G1TXCLK, G2TXCLK h/w buffers (rev.2 h/w bug workaround) */
  93. if (immr->sysconf.spridr == SPR_8360_REV20 ||
  94. immr->sysconf.spridr == SPR_8360E_REV20 ||
  95. immr->sysconf.spridr == SPR_8360_REV21 ||
  96. immr->sysconf.spridr == SPR_8360E_REV21)
  97. bcsr[0xe] = 0x30;
  98. return 0;
  99. }
  100. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  101. extern void ddr_enable_ecc(unsigned int dram_size);
  102. #endif
  103. int fixed_sdram(void);
  104. void sdram_init(void);
  105. long int initdram(int board_type)
  106. {
  107. volatile immap_t *im = (immap_t *) CFG_IMMR;
  108. u32 msize = 0;
  109. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
  110. return -1;
  111. /* DDR SDRAM - Main SODIMM */
  112. im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR;
  113. #if defined(CONFIG_SPD_EEPROM)
  114. msize = spd_sdram();
  115. #else
  116. msize = fixed_sdram();
  117. #endif
  118. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  119. /*
  120. * Initialize DDR ECC byte
  121. */
  122. ddr_enable_ecc(msize * 1024 * 1024);
  123. #endif
  124. /*
  125. * Initialize SDRAM if it is on local bus.
  126. */
  127. sdram_init();
  128. puts(" DDR RAM: ");
  129. /* return total bus SDRAM size(bytes) -- DDR */
  130. return (msize * 1024 * 1024);
  131. }
  132. #if !defined(CONFIG_SPD_EEPROM)
  133. /*************************************************************************
  134. * fixed sdram init -- doesn't use serial presence detect.
  135. ************************************************************************/
  136. int fixed_sdram(void)
  137. {
  138. volatile immap_t *im = (immap_t *) CFG_IMMR;
  139. u32 msize = 0;
  140. u32 ddr_size;
  141. u32 ddr_size_log2;
  142. msize = CFG_DDR_SIZE;
  143. for (ddr_size = msize << 20, ddr_size_log2 = 0;
  144. (ddr_size > 1); ddr_size = ddr_size >> 1, ddr_size_log2++) {
  145. if (ddr_size & 1) {
  146. return -1;
  147. }
  148. }
  149. im->sysconf.ddrlaw[0].ar =
  150. LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
  151. #if (CFG_DDR_SIZE != 256)
  152. #warning Currenly any ddr size other than 256 is not supported
  153. #endif
  154. #ifdef CONFIG_DDR_II
  155. im->ddr.csbnds[0].csbnds = CFG_DDR_CS0_BNDS;
  156. im->ddr.cs_config[0] = CFG_DDR_CS0_CONFIG;
  157. im->ddr.timing_cfg_0 = CFG_DDR_TIMING_0;
  158. im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
  159. im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
  160. im->ddr.timing_cfg_3 = CFG_DDR_TIMING_3;
  161. im->ddr.sdram_cfg = CFG_DDR_SDRAM_CFG;
  162. im->ddr.sdram_cfg2 = CFG_DDR_SDRAM_CFG2;
  163. im->ddr.sdram_mode = CFG_DDR_MODE;
  164. im->ddr.sdram_mode2 = CFG_DDR_MODE2;
  165. im->ddr.sdram_interval = CFG_DDR_INTERVAL;
  166. im->ddr.sdram_clk_cntl = CFG_DDR_CLK_CNTL;
  167. #else
  168. im->ddr.csbnds[0].csbnds = 0x00000007;
  169. im->ddr.csbnds[1].csbnds = 0x0008000f;
  170. im->ddr.cs_config[0] = CFG_DDR_CONFIG;
  171. im->ddr.cs_config[1] = CFG_DDR_CONFIG;
  172. im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
  173. im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
  174. im->ddr.sdram_cfg = CFG_DDR_CONTROL;
  175. im->ddr.sdram_mode = CFG_DDR_MODE;
  176. im->ddr.sdram_interval = CFG_DDR_INTERVAL;
  177. #endif
  178. udelay(200);
  179. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  180. return msize;
  181. }
  182. #endif /*!CFG_SPD_EEPROM */
  183. int checkboard(void)
  184. {
  185. puts("Board: Freescale MPC8360EMDS\n");
  186. return 0;
  187. }
  188. /*
  189. * if MPC8360EMDS is soldered with SDRAM
  190. */
  191. #if defined(CFG_BR2_PRELIM) \
  192. && defined(CFG_OR2_PRELIM) \
  193. && defined(CFG_LBLAWBAR2_PRELIM) \
  194. && defined(CFG_LBLAWAR2_PRELIM)
  195. /*
  196. * Initialize SDRAM memory on the Local Bus.
  197. */
  198. void sdram_init(void)
  199. {
  200. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  201. volatile lbus83xx_t *lbc = &immap->lbus;
  202. uint *sdram_addr = (uint *) CFG_LBC_SDRAM_BASE;
  203. puts("\n SDRAM on Local Bus: ");
  204. print_size(CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  205. /*
  206. * Setup SDRAM Base and Option Registers, already done in cpu_init.c
  207. */
  208. /*setup mtrpt, lsrt and lbcr for LB bus */
  209. lbc->lbcr = CFG_LBC_LBCR;
  210. lbc->mrtpr = CFG_LBC_MRTPR;
  211. lbc->lsrt = CFG_LBC_LSRT;
  212. asm("sync");
  213. /*
  214. * Configure the SDRAM controller Machine Mode Register.
  215. */
  216. lbc->lsdmr = CFG_LBC_LSDMR_5; /* Normal Operation */
  217. lbc->lsdmr = CFG_LBC_LSDMR_1; /* Precharge All Banks */
  218. asm("sync");
  219. *sdram_addr = 0xff;
  220. udelay(100);
  221. /*
  222. * We need do 8 times auto refresh operation.
  223. */
  224. lbc->lsdmr = CFG_LBC_LSDMR_2;
  225. asm("sync");
  226. *sdram_addr = 0xff; /* 1 times */
  227. udelay(100);
  228. *sdram_addr = 0xff; /* 2 times */
  229. udelay(100);
  230. *sdram_addr = 0xff; /* 3 times */
  231. udelay(100);
  232. *sdram_addr = 0xff; /* 4 times */
  233. udelay(100);
  234. *sdram_addr = 0xff; /* 5 times */
  235. udelay(100);
  236. *sdram_addr = 0xff; /* 6 times */
  237. udelay(100);
  238. *sdram_addr = 0xff; /* 7 times */
  239. udelay(100);
  240. *sdram_addr = 0xff; /* 8 times */
  241. udelay(100);
  242. /* Mode register write operation */
  243. lbc->lsdmr = CFG_LBC_LSDMR_4;
  244. asm("sync");
  245. *(sdram_addr + 0xcc) = 0xff;
  246. udelay(100);
  247. /* Normal operation */
  248. lbc->lsdmr = CFG_LBC_LSDMR_5 | 0x40000000;
  249. asm("sync");
  250. *sdram_addr = 0xff;
  251. udelay(100);
  252. }
  253. #else
  254. void sdram_init(void)
  255. {
  256. puts("SDRAM on Local Bus is NOT available!\n");
  257. }
  258. #endif
  259. #if (defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT)) \
  260. && defined(CONFIG_OF_BOARD_SETUP)
  261. /*
  262. * Prototypes of functions that we use.
  263. */
  264. void ft_cpu_setup(void *blob, bd_t *bd);
  265. #ifdef CONFIG_PCI
  266. void ft_pci_setup(void *blob, bd_t *bd);
  267. #endif
  268. void
  269. ft_board_setup(void *blob, bd_t *bd)
  270. {
  271. #if defined(CONFIG_OF_LIBFDT)
  272. int nodeoffset;
  273. int tmp[2];
  274. nodeoffset = fdt_find_node_by_path(blob, "/memory");
  275. if (nodeoffset >= 0) {
  276. tmp[0] = cpu_to_be32(bd->bi_memstart);
  277. tmp[1] = cpu_to_be32(bd->bi_memsize);
  278. fdt_setprop(blob, nodeoffset, "reg", tmp, sizeof(tmp));
  279. }
  280. #else
  281. u32 *p;
  282. int len;
  283. p = ft_get_prop(blob, "/memory/reg", &len);
  284. if (p != NULL) {
  285. *p++ = cpu_to_be32(bd->bi_memstart);
  286. *p = cpu_to_be32(bd->bi_memsize);
  287. }
  288. #endif
  289. #ifdef CONFIG_PCI
  290. ft_pci_setup(blob, bd);
  291. #endif
  292. ft_cpu_setup(blob, bd);
  293. }
  294. #endif /* CONFIG_OF_x */