mpc8349emds.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 = 0;
  91. u32 ddr_size;
  92. u32 ddr_size_log2;
  93. msize = CONFIG_SYS_DDR_SIZE;
  94. for (ddr_size = msize << 20, ddr_size_log2 = 0;
  95. (ddr_size > 1);
  96. ddr_size = ddr_size>>1, ddr_size_log2++) {
  97. if (ddr_size & 1) {
  98. return -1;
  99. }
  100. }
  101. im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
  102. im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
  103. #if (CONFIG_SYS_DDR_SIZE != 256)
  104. #warning Currenly any ddr size other than 256 is not supported
  105. #endif
  106. #ifdef CONFIG_DDR_II
  107. im->ddr.csbnds[2].csbnds = CONFIG_SYS_DDR_CS2_BNDS;
  108. im->ddr.cs_config[2] = CONFIG_SYS_DDR_CS2_CONFIG;
  109. im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
  110. im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  111. im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  112. im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
  113. im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
  114. im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
  115. im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
  116. im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
  117. im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  118. im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CNTL;
  119. #else
  120. im->ddr.csbnds[2].csbnds = 0x0000000f;
  121. im->ddr.cs_config[2] = CONFIG_SYS_DDR_CONFIG;
  122. /* currently we use only one CS, so disable the other banks */
  123. im->ddr.cs_config[0] = 0;
  124. im->ddr.cs_config[1] = 0;
  125. im->ddr.cs_config[3] = 0;
  126. im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  127. im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  128. im->ddr.sdram_cfg =
  129. SDRAM_CFG_SREN
  130. #if defined(CONFIG_DDR_2T_TIMING)
  131. | SDRAM_CFG_2T_EN
  132. #endif
  133. | 2 << SDRAM_CFG_SDRAM_TYPE_SHIFT;
  134. #if defined (CONFIG_DDR_32BIT)
  135. /* for 32-bit mode burst length is 8 */
  136. im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE);
  137. #endif
  138. im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
  139. im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  140. #endif
  141. udelay(200);
  142. /* enable DDR controller */
  143. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  144. return msize;
  145. }
  146. #endif/*!CONFIG_SYS_SPD_EEPROM*/
  147. int checkboard (void)
  148. {
  149. /*
  150. * Warning: do not read the BCSR registers here
  151. *
  152. * There is a timing bug in the 8349E and 8349EA BCSR code
  153. * version 1.2 (read from BCSR 11) that will cause the CFI
  154. * flash initialization code to overwrite BCSR 0, disabling
  155. * the serial ports and gigabit ethernet
  156. */
  157. puts("Board: Freescale MPC8349EMDS\n");
  158. return 0;
  159. }
  160. /*
  161. * if MPC8349EMDS is soldered with SDRAM
  162. */
  163. #if defined(CONFIG_SYS_BR2_PRELIM) \
  164. && defined(CONFIG_SYS_OR2_PRELIM) \
  165. && defined(CONFIG_SYS_LBLAWBAR2_PRELIM) \
  166. && defined(CONFIG_SYS_LBLAWAR2_PRELIM)
  167. /*
  168. * Initialize SDRAM memory on the Local Bus.
  169. */
  170. void sdram_init(void)
  171. {
  172. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  173. volatile fsl_lbc_t *lbc = &immap->im_lbc;
  174. uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
  175. /*
  176. * Setup SDRAM Base and Option Registers, already done in cpu_init.c
  177. */
  178. /* setup mtrpt, lsrt and lbcr for LB bus */
  179. lbc->lbcr = CONFIG_SYS_LBC_LBCR;
  180. lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
  181. lbc->lsrt = CONFIG_SYS_LBC_LSRT;
  182. asm("sync");
  183. /*
  184. * Configure the SDRAM controller Machine Mode Register.
  185. */
  186. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5; /* 0x40636733; normal operation */
  187. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1; /* 0x68636733; precharge all the banks */
  188. asm("sync");
  189. *sdram_addr = 0xff;
  190. udelay(100);
  191. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2; /* 0x48636733; auto refresh */
  192. asm("sync");
  193. /*1 times*/
  194. *sdram_addr = 0xff;
  195. udelay(100);
  196. /*2 times*/
  197. *sdram_addr = 0xff;
  198. udelay(100);
  199. /*3 times*/
  200. *sdram_addr = 0xff;
  201. udelay(100);
  202. /*4 times*/
  203. *sdram_addr = 0xff;
  204. udelay(100);
  205. /*5 times*/
  206. *sdram_addr = 0xff;
  207. udelay(100);
  208. /*6 times*/
  209. *sdram_addr = 0xff;
  210. udelay(100);
  211. /*7 times*/
  212. *sdram_addr = 0xff;
  213. udelay(100);
  214. /*8 times*/
  215. *sdram_addr = 0xff;
  216. udelay(100);
  217. /* 0x58636733; mode register write operation */
  218. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4;
  219. asm("sync");
  220. *sdram_addr = 0xff;
  221. udelay(100);
  222. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5; /* 0x40636733; normal operation */
  223. asm("sync");
  224. *sdram_addr = 0xff;
  225. udelay(100);
  226. }
  227. #else
  228. void sdram_init(void)
  229. {
  230. }
  231. #endif
  232. /*
  233. * The following are used to control the SPI chip selects for the SPI command.
  234. */
  235. #ifdef CONFIG_MPC8XXX_SPI
  236. #define SPI_CS_MASK 0x80000000
  237. int spi_cs_is_valid(unsigned int bus, unsigned int cs)
  238. {
  239. return bus == 0 && cs == 0;
  240. }
  241. void spi_cs_activate(struct spi_slave *slave)
  242. {
  243. volatile gpio83xx_t *iopd = &((immap_t *)CONFIG_SYS_IMMR)->gpio[0];
  244. iopd->dat &= ~SPI_CS_MASK;
  245. }
  246. void spi_cs_deactivate(struct spi_slave *slave)
  247. {
  248. volatile gpio83xx_t *iopd = &((immap_t *)CONFIG_SYS_IMMR)->gpio[0];
  249. iopd->dat |= SPI_CS_MASK;
  250. }
  251. #endif /* CONFIG_HARD_SPI */
  252. #if defined(CONFIG_OF_BOARD_SETUP)
  253. void ft_board_setup(void *blob, bd_t *bd)
  254. {
  255. ft_cpu_setup(blob, bd);
  256. #ifdef CONFIG_PCI
  257. ft_pci_setup(blob, bd);
  258. #endif
  259. }
  260. #endif