sbc8349.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 = 0;
  83. u32 ddr_size;
  84. u32 ddr_size_log2;
  85. msize = CONFIG_SYS_DDR_SIZE;
  86. for (ddr_size = msize << 20, ddr_size_log2 = 0;
  87. (ddr_size > 1);
  88. ddr_size = ddr_size>>1, ddr_size_log2++) {
  89. if (ddr_size & 1) {
  90. return -1;
  91. }
  92. }
  93. im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
  94. im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
  95. #if (CONFIG_SYS_DDR_SIZE != 256)
  96. #warning Currently any ddr size other than 256 is not supported
  97. #endif
  98. im->ddr.csbnds[2].csbnds = 0x0000000f;
  99. im->ddr.cs_config[2] = CONFIG_SYS_DDR_CONFIG;
  100. /* currently we use only one CS, so disable the other banks */
  101. im->ddr.cs_config[0] = 0;
  102. im->ddr.cs_config[1] = 0;
  103. im->ddr.cs_config[3] = 0;
  104. im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  105. im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  106. im->ddr.sdram_cfg =
  107. SDRAM_CFG_SREN
  108. #if defined(CONFIG_DDR_2T_TIMING)
  109. | SDRAM_CFG_2T_EN
  110. #endif
  111. | SDRAM_CFG_SDRAM_TYPE_DDR1;
  112. #if defined (CONFIG_DDR_32BIT)
  113. /* for 32-bit mode burst length is 8 */
  114. im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE);
  115. #endif
  116. im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
  117. im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  118. udelay(200);
  119. /* enable DDR controller */
  120. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  121. return msize;
  122. }
  123. #endif/*!CONFIG_SYS_SPD_EEPROM*/
  124. int checkboard (void)
  125. {
  126. puts("Board: Wind River SBC834x\n");
  127. return 0;
  128. }
  129. /*
  130. * if board is fitted with SDRAM
  131. */
  132. #if defined(CONFIG_SYS_BR2_PRELIM) \
  133. && defined(CONFIG_SYS_OR2_PRELIM) \
  134. && defined(CONFIG_SYS_LBLAWBAR2_PRELIM) \
  135. && defined(CONFIG_SYS_LBLAWAR2_PRELIM)
  136. /*
  137. * Initialize SDRAM memory on the Local Bus.
  138. */
  139. void sdram_init(void)
  140. {
  141. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  142. volatile fsl_lbus_t *lbc = &immap->lbus;
  143. uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
  144. puts("\n SDRAM on Local Bus: ");
  145. print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  146. /*
  147. * Setup SDRAM Base and Option Registers, already done in cpu_init.c
  148. */
  149. /* setup mtrpt, lsrt and lbcr for LB bus */
  150. lbc->lbcr = CONFIG_SYS_LBC_LBCR;
  151. lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
  152. lbc->lsrt = CONFIG_SYS_LBC_LSRT;
  153. asm("sync");
  154. /*
  155. * Configure the SDRAM controller Machine Mode Register.
  156. */
  157. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5; /* 0x40636733; normal operation */
  158. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1; /* 0x68636733; precharge all the banks */
  159. asm("sync");
  160. *sdram_addr = 0xff;
  161. udelay(100);
  162. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2; /* 0x48636733; auto refresh */
  163. asm("sync");
  164. /*1 times*/
  165. *sdram_addr = 0xff;
  166. udelay(100);
  167. /*2 times*/
  168. *sdram_addr = 0xff;
  169. udelay(100);
  170. /*3 times*/
  171. *sdram_addr = 0xff;
  172. udelay(100);
  173. /*4 times*/
  174. *sdram_addr = 0xff;
  175. udelay(100);
  176. /*5 times*/
  177. *sdram_addr = 0xff;
  178. udelay(100);
  179. /*6 times*/
  180. *sdram_addr = 0xff;
  181. udelay(100);
  182. /*7 times*/
  183. *sdram_addr = 0xff;
  184. udelay(100);
  185. /*8 times*/
  186. *sdram_addr = 0xff;
  187. udelay(100);
  188. /* 0x58636733; mode register write operation */
  189. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4;
  190. asm("sync");
  191. *sdram_addr = 0xff;
  192. udelay(100);
  193. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5; /* 0x40636733; normal operation */
  194. asm("sync");
  195. *sdram_addr = 0xff;
  196. udelay(100);
  197. }
  198. #else
  199. void sdram_init(void)
  200. {
  201. puts(" SDRAM on Local Bus: Disabled in config\n");
  202. }
  203. #endif
  204. #if defined(CONFIG_OF_BOARD_SETUP)
  205. void ft_board_setup(void *blob, bd_t *bd)
  206. {
  207. ft_cpu_setup(blob, bd);
  208. #ifdef CONFIG_PCI
  209. ft_pci_setup(blob, bd);
  210. #endif
  211. }
  212. #endif