sbc8349.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * sbc8349.c -- WindRiver SBC8349 board support.
  3. * Copyright (c) 2006-2007 Wind River Systems, Inc.
  4. *
  5. * Paul Gortmaker <paul.gortmaker@windriver.com>
  6. * Based on board/mpc8349emds/mpc8349emds.c (and previous 834x releases.)
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. *
  26. */
  27. #include <common.h>
  28. #include <ioports.h>
  29. #include <mpc83xx.h>
  30. #include <asm/mpc8349_pci.h>
  31. #include <i2c.h>
  32. #include <spd_sdram.h>
  33. #include <miiphy.h>
  34. #if defined(CONFIG_OF_LIBFDT)
  35. #include <libfdt.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. #ifdef CONFIG_BOARD_EARLY_INIT_F
  43. int board_early_init_f (void)
  44. {
  45. return 0;
  46. }
  47. #endif
  48. #define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
  49. phys_size_t initdram (int board_type)
  50. {
  51. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  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 = CONFIG_SYS_DDR_BASE & LAWBAR_BAR;
  57. #if defined(CONFIG_SPD_EEPROM)
  58. msize = spd_sdram();
  59. #else
  60. msize = fixed_sdram();
  61. #endif
  62. /*
  63. * Initialize SDRAM if it is on local bus.
  64. */
  65. sdram_init();
  66. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  67. /*
  68. * Initialize and enable DDR ECC.
  69. */
  70. ddr_enable_ecc(msize * 1024 * 1024);
  71. #endif
  72. /* return total bus SDRAM size(bytes) -- DDR */
  73. return (msize * 1024 * 1024);
  74. }
  75. #if !defined(CONFIG_SPD_EEPROM)
  76. /*************************************************************************
  77. * fixed sdram init -- doesn't use serial presence detect.
  78. ************************************************************************/
  79. int fixed_sdram(void)
  80. {
  81. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  82. u32 msize = CONFIG_SYS_DDR_SIZE;
  83. u32 ddr_size = msize << 20; /* DDR size in bytes */
  84. u32 ddr_size_log2 = __ilog2(msize);
  85. im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
  86. im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
  87. #if (CONFIG_SYS_DDR_SIZE != 256)
  88. #warning Currently any ddr size other than 256 is not supported
  89. #endif
  90. #if ((CONFIG_SYS_DDR_SDRAM_BASE & 0x00FFFFFF) != 0)
  91. #warning Chip select bounds is only configurable in 16MB increments
  92. #endif
  93. im->ddr.csbnds[2].csbnds =
  94. ((CONFIG_SYS_DDR_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
  95. (((CONFIG_SYS_DDR_SDRAM_BASE + ddr_size - 1) >>
  96. CSBNDS_EA_SHIFT) & CSBNDS_EA);
  97. im->ddr.cs_config[2] = CONFIG_SYS_DDR_CS2_CONFIG;
  98. /* currently we use only one CS, so disable the other banks */
  99. im->ddr.cs_config[0] = 0;
  100. im->ddr.cs_config[1] = 0;
  101. im->ddr.cs_config[3] = 0;
  102. im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  103. im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  104. im->ddr.sdram_cfg =
  105. SDRAM_CFG_SREN
  106. #if defined(CONFIG_DDR_2T_TIMING)
  107. | SDRAM_CFG_2T_EN
  108. #endif
  109. | SDRAM_CFG_SDRAM_TYPE_DDR1;
  110. #if defined (CONFIG_DDR_32BIT)
  111. /* for 32-bit mode burst length is 8 */
  112. im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE);
  113. #endif
  114. im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
  115. im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  116. udelay(200);
  117. /* enable DDR controller */
  118. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  119. return msize;
  120. }
  121. #endif/*!CONFIG_SYS_SPD_EEPROM*/
  122. int checkboard (void)
  123. {
  124. puts("Board: Wind River SBC834x\n");
  125. return 0;
  126. }
  127. /*
  128. * if board is fitted with SDRAM
  129. */
  130. #if defined(CONFIG_SYS_BR2_PRELIM) \
  131. && defined(CONFIG_SYS_OR2_PRELIM) \
  132. && defined(CONFIG_SYS_LBLAWBAR2_PRELIM) \
  133. && defined(CONFIG_SYS_LBLAWAR2_PRELIM)
  134. /*
  135. * Initialize SDRAM memory on the Local Bus.
  136. */
  137. void sdram_init(void)
  138. {
  139. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  140. volatile fsl_lbc_t *lbc = &immap->im_lbc;
  141. uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
  142. puts("\n SDRAM on Local Bus: ");
  143. print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  144. /*
  145. * Setup SDRAM Base and Option Registers, already done in cpu_init.c
  146. */
  147. /* setup mtrpt, lsrt and lbcr for LB bus */
  148. lbc->lbcr = CONFIG_SYS_LBC_LBCR;
  149. lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
  150. lbc->lsrt = CONFIG_SYS_LBC_LSRT;
  151. asm("sync");
  152. /*
  153. * Configure the SDRAM controller Machine Mode Register.
  154. */
  155. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5; /* 0x40636733; normal operation */
  156. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1; /* 0x68636733; precharge all the banks */
  157. asm("sync");
  158. *sdram_addr = 0xff;
  159. udelay(100);
  160. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2; /* 0x48636733; auto refresh */
  161. asm("sync");
  162. /*1 times*/
  163. *sdram_addr = 0xff;
  164. udelay(100);
  165. /*2 times*/
  166. *sdram_addr = 0xff;
  167. udelay(100);
  168. /*3 times*/
  169. *sdram_addr = 0xff;
  170. udelay(100);
  171. /*4 times*/
  172. *sdram_addr = 0xff;
  173. udelay(100);
  174. /*5 times*/
  175. *sdram_addr = 0xff;
  176. udelay(100);
  177. /*6 times*/
  178. *sdram_addr = 0xff;
  179. udelay(100);
  180. /*7 times*/
  181. *sdram_addr = 0xff;
  182. udelay(100);
  183. /*8 times*/
  184. *sdram_addr = 0xff;
  185. udelay(100);
  186. /* 0x58636733; mode register write operation */
  187. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4;
  188. asm("sync");
  189. *sdram_addr = 0xff;
  190. udelay(100);
  191. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5; /* 0x40636733; normal operation */
  192. asm("sync");
  193. *sdram_addr = 0xff;
  194. udelay(100);
  195. }
  196. #else
  197. void sdram_init(void)
  198. {
  199. puts(" SDRAM on Local Bus: Disabled in config\n");
  200. }
  201. #endif
  202. #if defined(CONFIG_OF_BOARD_SETUP)
  203. void ft_board_setup(void *blob, bd_t *bd)
  204. {
  205. ft_cpu_setup(blob, bd);
  206. #ifdef CONFIG_PCI
  207. ft_pci_setup(blob, bd);
  208. #endif
  209. }
  210. #endif