mpc8349emds.c 6.7 KB

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