mpc8349emds.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 <spd.h>
  30. #include <miiphy.h>
  31. #if defined(CONFIG_PCI)
  32. #include <pci.h>
  33. #endif
  34. #if defined(CONFIG_SPD_EEPROM)
  35. #include <spd_sdram.h>
  36. #endif
  37. int fixed_sdram(void);
  38. void sdram_init(void);
  39. #if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83XX)
  40. void ddr_enable_ecc(unsigned int dram_size);
  41. #endif
  42. int board_early_init_f (void)
  43. {
  44. volatile u8* bcsr = (volatile u8*)CFG_BCSR;
  45. /* Enable flash write */
  46. bcsr[1] &= ~0x01;
  47. return 0;
  48. }
  49. #define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
  50. long int initdram (int board_type)
  51. {
  52. volatile immap_t *im = (immap_t *)CFG_IMMRBAR;
  53. u32 msize = 0;
  54. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
  55. return -1;
  56. /* DDR SDRAM - Main SODIMM */
  57. im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR;
  58. #if defined(CONFIG_SPD_EEPROM)
  59. msize = spd_sdram(0);
  60. #else
  61. msize = fixed_sdram();
  62. #endif
  63. /*
  64. * Initialize SDRAM if it is on local bus.
  65. */
  66. sdram_init();
  67. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  68. /*
  69. * Initialize and enable DDR ECC.
  70. */
  71. ddr_enable_ecc(msize * 1024 * 1024);
  72. #endif
  73. puts(" DDR RAM: ");
  74. /* return total bus SDRAM size(bytes) -- DDR */
  75. return (msize * 1024 * 1024);
  76. }
  77. #if !defined(CONFIG_SPD_EEPROM)
  78. /*************************************************************************
  79. * fixed sdram init -- doesn't use serial presence detect.
  80. ************************************************************************/
  81. int fixed_sdram(void)
  82. {
  83. volatile immap_t *im = (immap_t *)CFG_IMMRBAR;
  84. u32 msize = 0;
  85. u32 ddr_size;
  86. u32 ddr_size_log2;
  87. msize = CFG_DDR_SIZE;
  88. for (ddr_size = msize << 20, ddr_size_log2 = 0;
  89. (ddr_size > 1);
  90. ddr_size = ddr_size>>1, ddr_size_log2++) {
  91. if (ddr_size & 1) {
  92. return -1;
  93. }
  94. }
  95. im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
  96. #if (CFG_DDR_SIZE != 256)
  97. #warning Currenly any ddr size other than 256 is not supported
  98. #endif
  99. im->ddr.csbnds[0].csbnds = 0x00100017;
  100. im->ddr.csbnds[1].csbnds = 0x0018001f;
  101. im->ddr.csbnds[2].csbnds = 0x00000007;
  102. im->ddr.csbnds[3].csbnds = 0x0008000f;
  103. im->ddr.cs_config[0] = CFG_DDR_CONFIG;
  104. im->ddr.cs_config[1] = CFG_DDR_CONFIG;
  105. im->ddr.cs_config[2] = CFG_DDR_CONFIG;
  106. im->ddr.cs_config[3] = CFG_DDR_CONFIG;
  107. im->ddr.timing_cfg_1 =
  108. 3 << TIMING_CFG1_PRETOACT_SHIFT |
  109. 7 << TIMING_CFG1_ACTTOPRE_SHIFT |
  110. 3 << TIMING_CFG1_ACTTORW_SHIFT |
  111. 4 << TIMING_CFG1_CASLAT_SHIFT |
  112. 3 << TIMING_CFG1_REFREC_SHIFT |
  113. 3 << TIMING_CFG1_WRREC_SHIFT |
  114. 2 << TIMING_CFG1_ACTTOACT_SHIFT |
  115. 1 << TIMING_CFG1_WRTORD_SHIFT;
  116. im->ddr.timing_cfg_2 = 2 << TIMING_CFG2_WR_DATA_DELAY_SHIFT;
  117. im->ddr.sdram_cfg =
  118. SDRAM_CFG_SREN
  119. #if defined(CONFIG_DDR_2T_TIMING)
  120. | SDRAM_CFG_2T_EN
  121. #endif
  122. | 2 << SDRAM_CFG_SDRAM_TYPE_SHIFT;
  123. im->ddr.sdram_mode =
  124. 0x2000 << SDRAM_MODE_ESD_SHIFT |
  125. 0x0162 << SDRAM_MODE_SD_SHIFT;
  126. im->ddr.sdram_interval = 0x045B << SDRAM_INTERVAL_REFINT_SHIFT |
  127. 0x0100 << SDRAM_INTERVAL_BSTOPRE_SHIFT;
  128. udelay(200);
  129. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  130. return msize;
  131. }
  132. #endif/*!CFG_SPD_EEPROM*/
  133. int checkboard (void)
  134. {
  135. puts("Board: Freescale MPC8349EMDS\n");
  136. return 0;
  137. }
  138. #if defined(CONFIG_PCI)
  139. /*
  140. * Initialize PCI Devices, report devices found
  141. */
  142. #ifndef CONFIG_PCI_PNP
  143. static struct pci_config_table pci_mpc8349emds_config_table[] = {
  144. {PCI_ANY_ID,PCI_ANY_ID,PCI_ANY_ID,PCI_ANY_ID,
  145. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  146. PCI_ENET0_MEMADDR,
  147. PCI_COMMON_MEMORY | PCI_COMMAND_MASTER
  148. } },
  149. {}
  150. }
  151. #endif
  152. volatile static struct pci_controller hose[] = {
  153. {
  154. #ifndef CONFIG_PCI_PNP
  155. config_table:pci_mpc8349emds_config_table,
  156. #endif
  157. },
  158. {
  159. #ifndef CONFIG_PCI_PNP
  160. config_table:pci_mpc8349emds_config_table,
  161. #endif
  162. }
  163. };
  164. #endif /* CONFIG_PCI */
  165. void pci_init_board(void)
  166. {
  167. #ifdef CONFIG_PCI
  168. extern void pci_mpc83xx_init(volatile struct pci_controller *hose);
  169. pci_mpc83xx_init(hose);
  170. #endif /* CONFIG_PCI */
  171. }
  172. /*
  173. * if MPC8349EMDS is soldered with SDRAM
  174. */
  175. #if defined(CFG_BR2_PRELIM) \
  176. && defined(CFG_OR2_PRELIM) \
  177. && defined(CFG_LBLAWBAR2_PRELIM) \
  178. && defined(CFG_LBLAWAR2_PRELIM)
  179. /*
  180. * Initialize SDRAM memory on the Local Bus.
  181. */
  182. void sdram_init(void)
  183. {
  184. volatile immap_t *immap = (immap_t *)CFG_IMMRBAR;
  185. volatile lbus8349_t *lbc= &immap->lbus;
  186. uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
  187. puts("\n SDRAM on Local Bus: ");
  188. print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  189. /*
  190. * Setup SDRAM Base and Option Registers, already done in cpu_init.c
  191. */
  192. /* setup mtrpt, lsrt and lbcr for LB bus */
  193. lbc->lbcr = CFG_LBC_LBCR;
  194. lbc->mrtpr = CFG_LBC_MRTPR;
  195. lbc->lsrt = CFG_LBC_LSRT;
  196. asm("sync");
  197. /*
  198. * Configure the SDRAM controller Machine Mode Register.
  199. */
  200. lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation */
  201. lbc->lsdmr = CFG_LBC_LSDMR_1; /* 0x68636733; precharge all the banks */
  202. asm("sync");
  203. *sdram_addr = 0xff;
  204. udelay(100);
  205. lbc->lsdmr = CFG_LBC_LSDMR_2; /* 0x48636733; auto refresh */
  206. asm("sync");
  207. /*1 times*/
  208. *sdram_addr = 0xff;
  209. udelay(100);
  210. /*2 times*/
  211. *sdram_addr = 0xff;
  212. udelay(100);
  213. /*3 times*/
  214. *sdram_addr = 0xff;
  215. udelay(100);
  216. /*4 times*/
  217. *sdram_addr = 0xff;
  218. udelay(100);
  219. /*5 times*/
  220. *sdram_addr = 0xff;
  221. udelay(100);
  222. /*6 times*/
  223. *sdram_addr = 0xff;
  224. udelay(100);
  225. /*7 times*/
  226. *sdram_addr = 0xff;
  227. udelay(100);
  228. /*8 times*/
  229. *sdram_addr = 0xff;
  230. udelay(100);
  231. /* 0x58636733; mode register write operation */
  232. lbc->lsdmr = CFG_LBC_LSDMR_4;
  233. asm("sync");
  234. *sdram_addr = 0xff;
  235. udelay(100);
  236. lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation */
  237. asm("sync");
  238. *sdram_addr = 0xff;
  239. udelay(100);
  240. }
  241. #else
  242. void sdram_init(void)
  243. {
  244. put("SDRAM on Local Bus is NOT available!\n");
  245. }
  246. #endif