mpc8349ads.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * Copyright Freescale Semiconductor, Inc.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. *
  22. * Change log:
  23. * 20050101: Eran Liberty (liberty@freescale.com)
  24. * Initial file creating (porting from 85XX & 8260)
  25. */
  26. #include <common.h>
  27. #include <ioports.h>
  28. #include <mpc83xx.h>
  29. #include <asm/mpc8349_pci.h>
  30. #include <i2c.h>
  31. #include <spd.h>
  32. #include <miiphy.h>
  33. #if defined(CONFIG_PCI)
  34. #include <pci.h>
  35. #endif
  36. #if defined(CONFIG_SPD_EEPROM)
  37. #include <spd_sdram.h>
  38. #endif
  39. int fixed_sdram(void);
  40. void sdram_init(void);
  41. int board_early_init_f (void)
  42. {
  43. volatile u8* bcsr = (volatile u8*)CFG_BCSR;
  44. /* Enable flash write */
  45. bcsr[1] &= ~0x01;
  46. return 0;
  47. }
  48. #define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
  49. long int initdram (int board_type)
  50. {
  51. volatile immap_t *im = (immap_t *)CFG_IMMRBAR;
  52. u32 msize = 0;
  53. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
  54. return -1;
  55. /* DDR SDRAM - Main SODIMM */
  56. im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR;
  57. #if defined(CONFIG_SPD_EEPROM)
  58. msize = spd_sdram(NULL);
  59. #else
  60. msize = fixed_sdram();
  61. #endif
  62. /*
  63. * Initialize SDRAM if it is on local bus.
  64. */
  65. sdram_init();
  66. puts(" DDR RAM: ");
  67. /* return total bus SDRAM size(bytes) -- DDR */
  68. return (msize * 1024 * 1024);
  69. }
  70. #if !defined(CONFIG_SPD_EEPROM)
  71. /*************************************************************************
  72. * fixed sdram init -- doesn't use serial presence detect.
  73. ************************************************************************/
  74. int fixed_sdram(void)
  75. {
  76. volatile immap_t *im = (immap_t *)CFG_IMMRBAR;
  77. u32 msize = 0;
  78. u32 ddr_size;
  79. u32 ddr_size_log2;
  80. msize = CFG_DDR_SIZE;
  81. for (ddr_size = msize << 20, ddr_size_log2 = 0;
  82. (ddr_size > 1);
  83. ddr_size = ddr_size>>1, ddr_size_log2++) {
  84. if (ddr_size & 1) {
  85. return -1;
  86. }
  87. }
  88. im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
  89. #if (CFG_DDR_SIZE != 256)
  90. #warning Currenly any ddr size other than 256 is not supported
  91. #endif
  92. im->ddr.csbnds[0].csbnds = 0x00100017;
  93. im->ddr.csbnds[1].csbnds = 0x0018001f;
  94. im->ddr.csbnds[2].csbnds = 0x00000007;
  95. im->ddr.csbnds[3].csbnds = 0x0008000f;
  96. im->ddr.cs_config[0] = CFG_DDR_CONFIG;
  97. im->ddr.cs_config[1] = CFG_DDR_CONFIG;
  98. im->ddr.cs_config[2] = CFG_DDR_CONFIG;
  99. im->ddr.cs_config[3] = CFG_DDR_CONFIG;
  100. im->ddr.timing_cfg_1 =
  101. 3 << TIMING_CFG1_PRETOACT_SHIFT |
  102. 7 << TIMING_CFG1_ACTTOPRE_SHIFT |
  103. 3 << TIMING_CFG1_ACTTORW_SHIFT |
  104. 4 << TIMING_CFG1_CASLAT_SHIFT |
  105. 3 << TIMING_CFG1_REFREC_SHIFT |
  106. 3 << TIMING_CFG1_WRREC_SHIFT |
  107. 2 << TIMING_CFG1_ACTTOACT_SHIFT |
  108. 1 << TIMING_CFG1_WRTORD_SHIFT;
  109. im->ddr.timing_cfg_2 = 2 << TIMING_CFG2_WR_DATA_DELAY_SHIFT;
  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. im->ddr.sdram_mode =
  117. 0x2000 << SDRAM_MODE_ESD_SHIFT |
  118. 0x0162 << SDRAM_MODE_SD_SHIFT;
  119. im->ddr.sdram_interval = 0x045B << SDRAM_INTERVAL_REFINT_SHIFT |
  120. 0x0100 << SDRAM_INTERVAL_BSTOPRE_SHIFT;
  121. udelay(200);
  122. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  123. return msize;
  124. }
  125. #endif/*!CFG_SPD_EEPROM*/
  126. int checkboard (void)
  127. {
  128. puts("Board: Freescale MPC8349ADS\n");
  129. return 0;
  130. }
  131. /*
  132. * if MPC8349ADS is soldered with SDRAM
  133. */
  134. #if defined(CFG_BR2_PRELIM) \
  135. && defined(CFG_OR2_PRELIM) \
  136. && defined(CFG_LBLAWBAR2_PRELIM) \
  137. && defined(CFG_LBLAWAR2_PRELIM)
  138. /*
  139. * Initialize SDRAM memory on the Local Bus.
  140. */
  141. void
  142. sdram_init(void)
  143. {
  144. volatile immap_t *immap = (immap_t *)CFG_IMMRBAR;
  145. volatile lbus8349_t *lbc= &immap->lbus;
  146. uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
  147. puts("\n SDRAM on Local Bus: ");
  148. print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  149. /*
  150. * Setup SDRAM Base and Option Registers, already done in cpu_init.c
  151. */
  152. /*setup mtrpt, lsrt and lbcr for LB bus*/
  153. lbc->lbcr = CFG_LBC_LBCR;
  154. lbc->mrtpr = CFG_LBC_MRTPR;
  155. lbc->lsrt = CFG_LBC_LSRT;
  156. asm("sync");
  157. /*
  158. * Configure the SDRAM controller Machine Mode Register.
  159. */
  160. lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation*/
  161. lbc->lsdmr = CFG_LBC_LSDMR_1; /*0x68636733;precharge all the banks*/
  162. asm("sync");
  163. *sdram_addr = 0xff;
  164. udelay(100);
  165. lbc->lsdmr = CFG_LBC_LSDMR_2;/*0x48636733;auto refresh*/
  166. asm("sync");
  167. /*1 times*/
  168. *sdram_addr = 0xff;
  169. udelay(100);
  170. /*2 times*/
  171. *sdram_addr = 0xff;
  172. udelay(100);
  173. /*3 times*/
  174. *sdram_addr = 0xff;
  175. udelay(100);
  176. /*4 times*/
  177. *sdram_addr = 0xff;
  178. udelay(100);
  179. /*5 times*/
  180. *sdram_addr = 0xff;
  181. udelay(100);
  182. /*6 times*/
  183. *sdram_addr = 0xff;
  184. udelay(100);
  185. /*7 times*/
  186. *sdram_addr = 0xff;
  187. udelay(100);
  188. /*8 times*/
  189. *sdram_addr = 0xff;
  190. udelay(100);
  191. /* 0x58636733;mode register write operation */
  192. lbc->lsdmr = CFG_LBC_LSDMR_4;
  193. asm("sync");
  194. *sdram_addr = 0xff;
  195. udelay(100);
  196. lbc->lsdmr = CFG_LBC_LSDMR_5; /*0x40636733;normal operation*/
  197. asm("sync");
  198. *sdram_addr = 0xff;
  199. udelay(100);
  200. }
  201. #else
  202. void
  203. sdram_init(void)
  204. {
  205. put("SDRAM on Local Bus is NOT available!\n");
  206. }
  207. #endif