mpc8349emds.c 6.7 KB

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