mpc8349emds.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*
  2. * (C) Copyright 2006
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  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. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. *
  23. */
  24. #include <common.h>
  25. #include <ioports.h>
  26. #include <mpc83xx.h>
  27. #include <asm/mpc8349_pci.h>
  28. #include <i2c.h>
  29. #include <spd.h>
  30. #include <miiphy.h>
  31. #if defined(CONFIG_SPD_EEPROM)
  32. #include <spd_sdram.h>
  33. #endif
  34. #if defined(CONFIG_OF_LIBFDT)
  35. #include <libfdt.h>
  36. #endif
  37. int fixed_sdram(void);
  38. void sdram_init(void);
  39. #if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83XX)
  40. void ddr_enable_ecc(unsigned int dram_size);
  41. #endif
  42. int board_early_init_f (void)
  43. {
  44. volatile u8* bcsr = (volatile u8*)CFG_BCSR;
  45. /* Enable flash write */
  46. bcsr[1] &= ~0x01;
  47. #ifdef CFG_USE_MPC834XSYS_USB_PHY
  48. /* Use USB PHY on SYS board */
  49. bcsr[5] |= 0x02;
  50. #endif
  51. return 0;
  52. }
  53. #define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
  54. long int initdram (int board_type)
  55. {
  56. volatile immap_t *im = (immap_t *)CFG_IMMR;
  57. u32 msize = 0;
  58. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
  59. return -1;
  60. /* DDR SDRAM - Main SODIMM */
  61. im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR;
  62. #if defined(CONFIG_SPD_EEPROM)
  63. msize = spd_sdram();
  64. #else
  65. msize = fixed_sdram();
  66. #endif
  67. /*
  68. * Initialize SDRAM if it is on local bus.
  69. */
  70. sdram_init();
  71. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  72. /*
  73. * Initialize and enable DDR ECC.
  74. */
  75. ddr_enable_ecc(msize * 1024 * 1024);
  76. #endif
  77. /* return total bus SDRAM size(bytes) -- DDR */
  78. return (msize * 1024 * 1024);
  79. }
  80. #if !defined(CONFIG_SPD_EEPROM)
  81. /*************************************************************************
  82. * fixed sdram init -- doesn't use serial presence detect.
  83. ************************************************************************/
  84. int fixed_sdram(void)
  85. {
  86. volatile immap_t *im = (immap_t *)CFG_IMMR;
  87. u32 msize = 0;
  88. u32 ddr_size;
  89. u32 ddr_size_log2;
  90. msize = CFG_DDR_SIZE;
  91. for (ddr_size = msize << 20, ddr_size_log2 = 0;
  92. (ddr_size > 1);
  93. ddr_size = ddr_size>>1, ddr_size_log2++) {
  94. if (ddr_size & 1) {
  95. return -1;
  96. }
  97. }
  98. im->sysconf.ddrlaw[0].bar = ((CFG_DDR_SDRAM_BASE>>12) & 0xfffff);
  99. im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
  100. #if (CFG_DDR_SIZE != 256)
  101. #warning Currenly any ddr size other than 256 is not supported
  102. #endif
  103. #ifdef CONFIG_DDR_II
  104. im->ddr.csbnds[2].csbnds = CFG_DDR_CS2_BNDS;
  105. im->ddr.cs_config[2] = CFG_DDR_CS2_CONFIG;
  106. im->ddr.timing_cfg_0 = CFG_DDR_TIMING_0;
  107. im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
  108. im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
  109. im->ddr.timing_cfg_3 = CFG_DDR_TIMING_3;
  110. im->ddr.sdram_cfg = CFG_DDR_SDRAM_CFG;
  111. im->ddr.sdram_cfg2 = CFG_DDR_SDRAM_CFG2;
  112. im->ddr.sdram_mode = CFG_DDR_MODE;
  113. im->ddr.sdram_mode2 = CFG_DDR_MODE2;
  114. im->ddr.sdram_interval = CFG_DDR_INTERVAL;
  115. im->ddr.sdram_clk_cntl = CFG_DDR_CLK_CNTL;
  116. #else
  117. im->ddr.csbnds[2].csbnds = 0x0000000f;
  118. im->ddr.cs_config[2] = CFG_DDR_CONFIG;
  119. /* currently we use only one CS, so disable the other banks */
  120. im->ddr.cs_config[0] = 0;
  121. im->ddr.cs_config[1] = 0;
  122. im->ddr.cs_config[3] = 0;
  123. im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
  124. im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
  125. im->ddr.sdram_cfg =
  126. SDRAM_CFG_SREN
  127. #if defined(CONFIG_DDR_2T_TIMING)
  128. | SDRAM_CFG_2T_EN
  129. #endif
  130. | 2 << SDRAM_CFG_SDRAM_TYPE_SHIFT;
  131. #if defined (CONFIG_DDR_32BIT)
  132. /* for 32-bit mode burst length is 8 */
  133. im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE);
  134. #endif
  135. im->ddr.sdram_mode = CFG_DDR_MODE;
  136. im->ddr.sdram_interval = CFG_DDR_INTERVAL;
  137. #endif
  138. udelay(200);
  139. /* enable DDR controller */
  140. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  141. return msize;
  142. }
  143. #endif/*!CFG_SPD_EEPROM*/
  144. int checkboard (void)
  145. {
  146. puts("Board: Freescale MPC8349EMDS\n");
  147. return 0;
  148. }
  149. /*
  150. * if MPC8349EMDS is soldered with SDRAM
  151. */
  152. #if defined(CFG_BR2_PRELIM) \
  153. && defined(CFG_OR2_PRELIM) \
  154. && defined(CFG_LBLAWBAR2_PRELIM) \
  155. && defined(CFG_LBLAWAR2_PRELIM)
  156. /*
  157. * Initialize SDRAM memory on the Local Bus.
  158. */
  159. void sdram_init(void)
  160. {
  161. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  162. volatile lbus83xx_t *lbc= &immap->lbus;
  163. uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
  164. /*
  165. * Setup SDRAM Base and Option Registers, already done in cpu_init.c
  166. */
  167. /* setup mtrpt, lsrt and lbcr for LB bus */
  168. lbc->lbcr = CFG_LBC_LBCR;
  169. lbc->mrtpr = CFG_LBC_MRTPR;
  170. lbc->lsrt = CFG_LBC_LSRT;
  171. asm("sync");
  172. /*
  173. * Configure the SDRAM controller Machine Mode Register.
  174. */
  175. lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation */
  176. lbc->lsdmr = CFG_LBC_LSDMR_1; /* 0x68636733; precharge all the banks */
  177. asm("sync");
  178. *sdram_addr = 0xff;
  179. udelay(100);
  180. lbc->lsdmr = CFG_LBC_LSDMR_2; /* 0x48636733; auto refresh */
  181. asm("sync");
  182. /*1 times*/
  183. *sdram_addr = 0xff;
  184. udelay(100);
  185. /*2 times*/
  186. *sdram_addr = 0xff;
  187. udelay(100);
  188. /*3 times*/
  189. *sdram_addr = 0xff;
  190. udelay(100);
  191. /*4 times*/
  192. *sdram_addr = 0xff;
  193. udelay(100);
  194. /*5 times*/
  195. *sdram_addr = 0xff;
  196. udelay(100);
  197. /*6 times*/
  198. *sdram_addr = 0xff;
  199. udelay(100);
  200. /*7 times*/
  201. *sdram_addr = 0xff;
  202. udelay(100);
  203. /*8 times*/
  204. *sdram_addr = 0xff;
  205. udelay(100);
  206. /* 0x58636733; mode register write operation */
  207. lbc->lsdmr = CFG_LBC_LSDMR_4;
  208. asm("sync");
  209. *sdram_addr = 0xff;
  210. udelay(100);
  211. lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation */
  212. asm("sync");
  213. *sdram_addr = 0xff;
  214. udelay(100);
  215. }
  216. #else
  217. void sdram_init(void)
  218. {
  219. }
  220. #endif
  221. #if defined(CONFIG_OF_BOARD_SETUP)
  222. void ft_board_setup(void *blob, bd_t *bd)
  223. {
  224. ft_cpu_setup(blob, bd);
  225. #ifdef CONFIG_PCI
  226. ft_pci_setup(blob, bd);
  227. #endif
  228. }
  229. #endif