mpc8349ads.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. #if defined(CONFIG_PCI) //copy from mpc85xx
  132. /*
  133. * Initialize PCI Devices, report devices found
  134. */
  135. #ifndef CONFIG_PCI_PNP
  136. static struct pci_config_table pci_mpc83xxads_config_table[] = {
  137. {PCI_ANY_ID,PCI_ANY_ID,PCI_ANY_ID,PCI_ANY_ID,
  138. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  139. PCI_ENET0_MEMADDR,
  140. PCI_COMMON_MEMORY | PCI_COMMAND_MASTER
  141. } },
  142. {}
  143. }
  144. #endif
  145. volatile static struct pci_controller hose[] = {
  146. {
  147. #ifndef CONFIG_PCI_PNP
  148. config_table:pci_mpc83xxads_config_table,
  149. #endif
  150. },
  151. {
  152. #ifndef CONFIG_PCI_PNP
  153. config_table:pci_mpc83xxads_config_table,
  154. #endif
  155. }
  156. };
  157. #endif /* CONFIG_PCI */
  158. void
  159. pci_init_board(void)
  160. {
  161. #ifdef CONFIG_PCI
  162. extern void pci_mpc83xx_init(volatile struct pci_controller *hose);
  163. pci_mpc83xx_init(hose);
  164. #endif /* CONFIG_PCI */
  165. }
  166. /*
  167. if MPC8349ADS is soldered with SDRAM
  168. */
  169. #if defined(CFG_BR2_PRELIM) \
  170. && defined(CFG_OR2_PRELIM) \
  171. && defined(CFG_LBLAWBAR2_PRELIM) \
  172. && defined(CFG_LBLAWAR2_PRELIM)
  173. /*
  174. * Initialize SDRAM memory on the Local Bus.
  175. */
  176. void
  177. sdram_init(void)
  178. {
  179. volatile immap_t *immap = (immap_t *)CFG_IMMRBAR;
  180. volatile lbus8349_t *lbc= &immap->lbus;
  181. uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
  182. puts("\n SDRAM on Local Bus: ");
  183. print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  184. /*
  185. * Setup SDRAM Base and Option Registers, already done in cpu_init.c
  186. */
  187. /*setup mtrpt, lsrt and lbcr for LB bus*/
  188. lbc->lbcr = CFG_LBC_LBCR;
  189. lbc->mrtpr = CFG_LBC_MRTPR;
  190. lbc->lsrt = CFG_LBC_LSRT;
  191. asm("sync");
  192. /*
  193. * Configure the SDRAM controller Machine Mode Register.
  194. */
  195. lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation*/
  196. lbc->lsdmr = CFG_LBC_LSDMR_1; /*0x68636733;precharge all the banks*/
  197. asm("sync");
  198. *sdram_addr = 0xff;
  199. udelay(100);
  200. lbc->lsdmr = CFG_LBC_LSDMR_2;/*0x48636733;auto refresh*/
  201. asm("sync");
  202. /*1 times*/
  203. *sdram_addr = 0xff;
  204. udelay(100);
  205. /*2 times*/
  206. *sdram_addr = 0xff;
  207. udelay(100);
  208. /*3 times*/
  209. *sdram_addr = 0xff;
  210. udelay(100);
  211. /*4 times*/
  212. *sdram_addr = 0xff;
  213. udelay(100);
  214. /*5 times*/
  215. *sdram_addr = 0xff;
  216. udelay(100);
  217. /*6 times*/
  218. *sdram_addr = 0xff;
  219. udelay(100);
  220. /*7 times*/
  221. *sdram_addr = 0xff;
  222. udelay(100);
  223. /*8 times*/
  224. *sdram_addr = 0xff;
  225. udelay(100);
  226. lbc->lsdmr = CFG_LBC_LSDMR_4; /*0x58636733;mode register write operation*/
  227. asm("sync");
  228. *sdram_addr = 0xff;
  229. udelay(100);
  230. lbc->lsdmr = CFG_LBC_LSDMR_5; /*0x40636733;normal operation*/
  231. asm("sync");
  232. *sdram_addr = 0xff;
  233. udelay(100);
  234. }
  235. #else
  236. void
  237. sdram_init(void)
  238. {
  239. put("SDRAM on Local Bus is NOT available!\n");
  240. }
  241. #endif