mpc8349emds.c 7.2 KB

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