mpc8349emds.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 <spi.h>
  30. #include <spd.h>
  31. #include <miiphy.h>
  32. #if defined(CONFIG_SPD_EEPROM)
  33. #include <spd_sdram.h>
  34. #endif
  35. #if defined(CONFIG_OF_LIBFDT)
  36. #include <libfdt.h>
  37. #endif
  38. int fixed_sdram(void);
  39. void sdram_init(void);
  40. #if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83XX)
  41. void ddr_enable_ecc(unsigned int dram_size);
  42. #endif
  43. int board_early_init_f (void)
  44. {
  45. volatile u8* bcsr = (volatile u8*)CFG_BCSR;
  46. /* Enable flash write */
  47. bcsr[1] &= ~0x01;
  48. #ifdef CFG_USE_MPC834XSYS_USB_PHY
  49. /* Use USB PHY on SYS board */
  50. bcsr[5] |= 0x02;
  51. #endif
  52. return 0;
  53. }
  54. #define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
  55. long int initdram (int board_type)
  56. {
  57. volatile immap_t *im = (immap_t *)CFG_IMMR;
  58. u32 msize = 0;
  59. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
  60. return -1;
  61. /* DDR SDRAM - Main SODIMM */
  62. im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR;
  63. #if defined(CONFIG_SPD_EEPROM)
  64. msize = spd_sdram();
  65. #else
  66. msize = fixed_sdram();
  67. #endif
  68. /*
  69. * Initialize SDRAM if it is on local bus.
  70. */
  71. sdram_init();
  72. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  73. /*
  74. * Initialize and enable DDR ECC.
  75. */
  76. ddr_enable_ecc(msize * 1024 * 1024);
  77. #endif
  78. /* return total bus SDRAM size(bytes) -- DDR */
  79. return (msize * 1024 * 1024);
  80. }
  81. #if !defined(CONFIG_SPD_EEPROM)
  82. /*************************************************************************
  83. * fixed sdram init -- doesn't use serial presence detect.
  84. ************************************************************************/
  85. int fixed_sdram(void)
  86. {
  87. volatile immap_t *im = (immap_t *)CFG_IMMR;
  88. u32 msize = 0;
  89. u32 ddr_size;
  90. u32 ddr_size_log2;
  91. msize = CFG_DDR_SIZE;
  92. for (ddr_size = msize << 20, ddr_size_log2 = 0;
  93. (ddr_size > 1);
  94. ddr_size = ddr_size>>1, ddr_size_log2++) {
  95. if (ddr_size & 1) {
  96. return -1;
  97. }
  98. }
  99. im->sysconf.ddrlaw[0].bar = ((CFG_DDR_SDRAM_BASE>>12) & 0xfffff);
  100. im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
  101. #if (CFG_DDR_SIZE != 256)
  102. #warning Currenly any ddr size other than 256 is not supported
  103. #endif
  104. #ifdef CONFIG_DDR_II
  105. im->ddr.csbnds[2].csbnds = CFG_DDR_CS2_BNDS;
  106. im->ddr.cs_config[2] = CFG_DDR_CS2_CONFIG;
  107. im->ddr.timing_cfg_0 = CFG_DDR_TIMING_0;
  108. im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
  109. im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
  110. im->ddr.timing_cfg_3 = CFG_DDR_TIMING_3;
  111. im->ddr.sdram_cfg = CFG_DDR_SDRAM_CFG;
  112. im->ddr.sdram_cfg2 = CFG_DDR_SDRAM_CFG2;
  113. im->ddr.sdram_mode = CFG_DDR_MODE;
  114. im->ddr.sdram_mode2 = CFG_DDR_MODE2;
  115. im->ddr.sdram_interval = CFG_DDR_INTERVAL;
  116. im->ddr.sdram_clk_cntl = CFG_DDR_CLK_CNTL;
  117. #else
  118. im->ddr.csbnds[2].csbnds = 0x0000000f;
  119. im->ddr.cs_config[2] = CFG_DDR_CONFIG;
  120. /* currently we use only one CS, so disable the other banks */
  121. im->ddr.cs_config[0] = 0;
  122. im->ddr.cs_config[1] = 0;
  123. im->ddr.cs_config[3] = 0;
  124. im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
  125. im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
  126. im->ddr.sdram_cfg =
  127. SDRAM_CFG_SREN
  128. #if defined(CONFIG_DDR_2T_TIMING)
  129. | SDRAM_CFG_2T_EN
  130. #endif
  131. | 2 << SDRAM_CFG_SDRAM_TYPE_SHIFT;
  132. #if defined (CONFIG_DDR_32BIT)
  133. /* for 32-bit mode burst length is 8 */
  134. im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE);
  135. #endif
  136. im->ddr.sdram_mode = CFG_DDR_MODE;
  137. im->ddr.sdram_interval = CFG_DDR_INTERVAL;
  138. #endif
  139. udelay(200);
  140. /* enable DDR controller */
  141. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  142. return msize;
  143. }
  144. #endif/*!CFG_SPD_EEPROM*/
  145. int checkboard (void)
  146. {
  147. puts("Board: Freescale MPC8349EMDS\n");
  148. return 0;
  149. }
  150. /*
  151. * if MPC8349EMDS is soldered with SDRAM
  152. */
  153. #if defined(CFG_BR2_PRELIM) \
  154. && defined(CFG_OR2_PRELIM) \
  155. && defined(CFG_LBLAWBAR2_PRELIM) \
  156. && defined(CFG_LBLAWAR2_PRELIM)
  157. /*
  158. * Initialize SDRAM memory on the Local Bus.
  159. */
  160. void sdram_init(void)
  161. {
  162. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  163. volatile lbus83xx_t *lbc= &immap->lbus;
  164. uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
  165. /*
  166. * Setup SDRAM Base and Option Registers, already done in cpu_init.c
  167. */
  168. /* setup mtrpt, lsrt and lbcr for LB bus */
  169. lbc->lbcr = CFG_LBC_LBCR;
  170. lbc->mrtpr = CFG_LBC_MRTPR;
  171. lbc->lsrt = CFG_LBC_LSRT;
  172. asm("sync");
  173. /*
  174. * Configure the SDRAM controller Machine Mode Register.
  175. */
  176. lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation */
  177. lbc->lsdmr = CFG_LBC_LSDMR_1; /* 0x68636733; precharge all the banks */
  178. asm("sync");
  179. *sdram_addr = 0xff;
  180. udelay(100);
  181. lbc->lsdmr = CFG_LBC_LSDMR_2; /* 0x48636733; auto refresh */
  182. asm("sync");
  183. /*1 times*/
  184. *sdram_addr = 0xff;
  185. udelay(100);
  186. /*2 times*/
  187. *sdram_addr = 0xff;
  188. udelay(100);
  189. /*3 times*/
  190. *sdram_addr = 0xff;
  191. udelay(100);
  192. /*4 times*/
  193. *sdram_addr = 0xff;
  194. udelay(100);
  195. /*5 times*/
  196. *sdram_addr = 0xff;
  197. udelay(100);
  198. /*6 times*/
  199. *sdram_addr = 0xff;
  200. udelay(100);
  201. /*7 times*/
  202. *sdram_addr = 0xff;
  203. udelay(100);
  204. /*8 times*/
  205. *sdram_addr = 0xff;
  206. udelay(100);
  207. /* 0x58636733; mode register write operation */
  208. lbc->lsdmr = CFG_LBC_LSDMR_4;
  209. asm("sync");
  210. *sdram_addr = 0xff;
  211. udelay(100);
  212. lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation */
  213. asm("sync");
  214. *sdram_addr = 0xff;
  215. udelay(100);
  216. }
  217. #else
  218. void sdram_init(void)
  219. {
  220. }
  221. #endif
  222. /*
  223. * The following are used to control the SPI chip selects for the SPI command.
  224. */
  225. #ifdef CONFIG_HARD_SPI
  226. #define SPI_CS_MASK 0x80000000
  227. void spi_eeprom_chipsel(int cs)
  228. {
  229. volatile gpio83xx_t *iopd = &((immap_t *)CFG_IMMR)->gpio[0];
  230. if(cs)
  231. iopd->dat &= ~SPI_CS_MASK;
  232. else
  233. iopd->dat |= SPI_CS_MASK;
  234. }
  235. /*
  236. * The SPI command uses this table of functions for controlling the SPI
  237. * chip selects.
  238. */
  239. spi_chipsel_type spi_chipsel[] = {
  240. spi_eeprom_chipsel,
  241. };
  242. int spi_chipsel_cnt = sizeof(spi_chipsel) / sizeof(spi_chipsel[0]);
  243. #endif /* CONFIG_HARD_SPI */
  244. #if defined(CONFIG_OF_BOARD_SETUP)
  245. void ft_board_setup(void *blob, bd_t *bd)
  246. {
  247. ft_cpu_setup(blob, bd);
  248. #ifdef CONFIG_PCI
  249. ft_pci_setup(blob, bd);
  250. #endif
  251. }
  252. #endif