mpc8349emds.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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 <miiphy.h>
  31. #ifdef CONFIG_FSL_DDR2
  32. #include <asm/fsl_ddr_sdram.h>
  33. #else
  34. #include <spd_sdram.h>
  35. #endif
  36. #if defined(CONFIG_OF_LIBFDT)
  37. #include <libfdt.h>
  38. #endif
  39. int fixed_sdram(void);
  40. void sdram_init(void);
  41. #if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83xx)
  42. void ddr_enable_ecc(unsigned int dram_size);
  43. #endif
  44. int board_early_init_f (void)
  45. {
  46. volatile u8* bcsr = (volatile u8*)CONFIG_SYS_BCSR;
  47. /* Enable flash write */
  48. bcsr[1] &= ~0x01;
  49. #ifdef CONFIG_SYS_USE_MPC834XSYS_USB_PHY
  50. /* Use USB PHY on SYS board */
  51. bcsr[5] |= 0x02;
  52. #endif
  53. return 0;
  54. }
  55. #define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
  56. phys_size_t initdram (int board_type)
  57. {
  58. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  59. phys_size_t msize = 0;
  60. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
  61. return -1;
  62. /* DDR SDRAM - Main SODIMM */
  63. im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_BASE & LAWBAR_BAR;
  64. #if defined(CONFIG_SPD_EEPROM)
  65. #ifndef CONFIG_FSL_DDR2
  66. msize = spd_sdram() * 1024 * 1024;
  67. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  68. ddr_enable_ecc(msize);
  69. #endif
  70. #else
  71. msize = fsl_ddr_sdram();
  72. #endif
  73. #else
  74. msize = fixed_sdram() * 1024 * 1024;
  75. #endif
  76. /*
  77. * Initialize SDRAM if it is on local bus.
  78. */
  79. sdram_init();
  80. /* return total bus SDRAM size(bytes) -- DDR */
  81. return msize;
  82. }
  83. #if !defined(CONFIG_SPD_EEPROM)
  84. /*************************************************************************
  85. * fixed sdram init -- doesn't use serial presence detect.
  86. ************************************************************************/
  87. int fixed_sdram(void)
  88. {
  89. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  90. u32 msize = CONFIG_SYS_DDR_SIZE;
  91. u32 ddr_size = msize << 20; /* DDR size in bytes */
  92. u32 ddr_size_log2 = __ilog2(ddr_size);
  93. im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
  94. im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
  95. #if (CONFIG_SYS_DDR_SIZE != 256)
  96. #warning Currenly any ddr size other than 256 is not supported
  97. #endif
  98. #ifdef CONFIG_DDR_II
  99. im->ddr.csbnds[2].csbnds = CONFIG_SYS_DDR_CS2_BNDS;
  100. im->ddr.cs_config[2] = CONFIG_SYS_DDR_CS2_CONFIG;
  101. im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
  102. im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  103. im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  104. im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
  105. im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
  106. im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
  107. im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
  108. im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
  109. im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  110. im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CNTL;
  111. #else
  112. #if ((CONFIG_SYS_DDR_SDRAM_BASE & 0x00FFFFFF) != 0)
  113. #warning Chip select bounds is only configurable in 16MB increments
  114. #endif
  115. im->ddr.csbnds[2].csbnds =
  116. ((CONFIG_SYS_DDR_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
  117. (((CONFIG_SYS_DDR_SDRAM_BASE + ddr_size - 1) >>
  118. CSBNDS_EA_SHIFT) & CSBNDS_EA);
  119. im->ddr.cs_config[2] = CONFIG_SYS_DDR_CS2_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 = CONFIG_SYS_DDR_TIMING_1;
  125. im->ddr.timing_cfg_2 = CONFIG_SYS_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 = CONFIG_SYS_DDR_MODE;
  137. im->ddr.sdram_interval = CONFIG_SYS_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/*!CONFIG_SYS_SPD_EEPROM*/
  145. int checkboard (void)
  146. {
  147. /*
  148. * Warning: do not read the BCSR registers here
  149. *
  150. * There is a timing bug in the 8349E and 8349EA BCSR code
  151. * version 1.2 (read from BCSR 11) that will cause the CFI
  152. * flash initialization code to overwrite BCSR 0, disabling
  153. * the serial ports and gigabit ethernet
  154. */
  155. puts("Board: Freescale MPC8349EMDS\n");
  156. return 0;
  157. }
  158. /*
  159. * if MPC8349EMDS is soldered with SDRAM
  160. */
  161. #if defined(CONFIG_SYS_BR2_PRELIM) \
  162. && defined(CONFIG_SYS_OR2_PRELIM) \
  163. && defined(CONFIG_SYS_LBLAWBAR2_PRELIM) \
  164. && defined(CONFIG_SYS_LBLAWAR2_PRELIM)
  165. /*
  166. * Initialize SDRAM memory on the Local Bus.
  167. */
  168. void sdram_init(void)
  169. {
  170. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  171. volatile fsl_lbc_t *lbc = &immap->im_lbc;
  172. uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
  173. /*
  174. * Setup SDRAM Base and Option Registers, already done in cpu_init.c
  175. */
  176. /* setup mtrpt, lsrt and lbcr for LB bus */
  177. lbc->lbcr = CONFIG_SYS_LBC_LBCR;
  178. lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
  179. lbc->lsrt = CONFIG_SYS_LBC_LSRT;
  180. asm("sync");
  181. /*
  182. * Configure the SDRAM controller Machine Mode Register.
  183. */
  184. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5; /* 0x40636733; normal operation */
  185. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1; /* 0x68636733; precharge all the banks */
  186. asm("sync");
  187. *sdram_addr = 0xff;
  188. udelay(100);
  189. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2; /* 0x48636733; auto refresh */
  190. asm("sync");
  191. /*1 times*/
  192. *sdram_addr = 0xff;
  193. udelay(100);
  194. /*2 times*/
  195. *sdram_addr = 0xff;
  196. udelay(100);
  197. /*3 times*/
  198. *sdram_addr = 0xff;
  199. udelay(100);
  200. /*4 times*/
  201. *sdram_addr = 0xff;
  202. udelay(100);
  203. /*5 times*/
  204. *sdram_addr = 0xff;
  205. udelay(100);
  206. /*6 times*/
  207. *sdram_addr = 0xff;
  208. udelay(100);
  209. /*7 times*/
  210. *sdram_addr = 0xff;
  211. udelay(100);
  212. /*8 times*/
  213. *sdram_addr = 0xff;
  214. udelay(100);
  215. /* 0x58636733; mode register write operation */
  216. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4;
  217. asm("sync");
  218. *sdram_addr = 0xff;
  219. udelay(100);
  220. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5; /* 0x40636733; normal operation */
  221. asm("sync");
  222. *sdram_addr = 0xff;
  223. udelay(100);
  224. }
  225. #else
  226. void sdram_init(void)
  227. {
  228. }
  229. #endif
  230. /*
  231. * The following are used to control the SPI chip selects for the SPI command.
  232. */
  233. #ifdef CONFIG_MPC8XXX_SPI
  234. #define SPI_CS_MASK 0x80000000
  235. int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  236. {
  237. return bus == 0 && cs == 0;
  238. }
  239. void spi_cs_activate(struct spi_slave *slave)
  240. {
  241. volatile gpio83xx_t *iopd = &((immap_t *)CONFIG_SYS_IMMR)->gpio[0];
  242. iopd->dat &= ~SPI_CS_MASK;
  243. }
  244. void spi_cs_deactivate(struct spi_slave *slave)
  245. {
  246. volatile gpio83xx_t *iopd = &((immap_t *)CONFIG_SYS_IMMR)->gpio[0];
  247. iopd->dat |= SPI_CS_MASK;
  248. }
  249. #endif /* CONFIG_HARD_SPI */
  250. #if defined(CONFIG_OF_BOARD_SETUP)
  251. void ft_board_setup(void *blob, bd_t *bd)
  252. {
  253. ft_cpu_setup(blob, bd);
  254. #ifdef CONFIG_PCI
  255. ft_pci_setup(blob, bd);
  256. #endif
  257. }
  258. #endif