sbc8349.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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.h>
  33. #include <miiphy.h>
  34. #if defined(CONFIG_SPD_EEPROM)
  35. #include <spd_sdram.h>
  36. #endif
  37. #if defined(CONFIG_OF_FLAT_TREE)
  38. #include <ft_build.h>
  39. #elif defined(CONFIG_OF_LIBFDT)
  40. #include <libfdt.h>
  41. #endif
  42. int fixed_sdram(void);
  43. void sdram_init(void);
  44. #if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83XX)
  45. void ddr_enable_ecc(unsigned int dram_size);
  46. #endif
  47. #ifdef CONFIG_BOARD_EARLY_INIT_F
  48. int board_early_init_f (void)
  49. {
  50. return 0;
  51. }
  52. #endif
  53. #define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
  54. long int initdram (int board_type)
  55. {
  56. volatile immap_t *im = (immap_t *)CFG_IMMR;
  57. u32 msize = 0;
  58. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
  59. return -1;
  60. /* DDR SDRAM - Main SODIMM */
  61. im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR;
  62. #if defined(CONFIG_SPD_EEPROM)
  63. msize = spd_sdram();
  64. #else
  65. msize = fixed_sdram();
  66. #endif
  67. /*
  68. * Initialize SDRAM if it is on local bus.
  69. */
  70. sdram_init();
  71. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  72. /*
  73. * Initialize and enable DDR ECC.
  74. */
  75. ddr_enable_ecc(msize * 1024 * 1024);
  76. #endif
  77. /* return total bus SDRAM size(bytes) -- DDR */
  78. return (msize * 1024 * 1024);
  79. }
  80. #if !defined(CONFIG_SPD_EEPROM)
  81. /*************************************************************************
  82. * fixed sdram init -- doesn't use serial presence detect.
  83. ************************************************************************/
  84. int fixed_sdram(void)
  85. {
  86. volatile immap_t *im = (immap_t *)CFG_IMMR;
  87. u32 msize = 0;
  88. u32 ddr_size;
  89. u32 ddr_size_log2;
  90. msize = CFG_DDR_SIZE;
  91. for (ddr_size = msize << 20, ddr_size_log2 = 0;
  92. (ddr_size > 1);
  93. ddr_size = ddr_size>>1, ddr_size_log2++) {
  94. if (ddr_size & 1) {
  95. return -1;
  96. }
  97. }
  98. im->sysconf.ddrlaw[0].bar = ((CFG_DDR_SDRAM_BASE>>12) & 0xfffff);
  99. im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
  100. #if (CFG_DDR_SIZE != 256)
  101. #warning Currently any ddr size other than 256 is not supported
  102. #endif
  103. im->ddr.csbnds[2].csbnds = 0x0000000f;
  104. im->ddr.cs_config[2] = CFG_DDR_CONFIG;
  105. /* currently we use only one CS, so disable the other banks */
  106. im->ddr.cs_config[0] = 0;
  107. im->ddr.cs_config[1] = 0;
  108. im->ddr.cs_config[3] = 0;
  109. im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
  110. im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
  111. im->ddr.sdram_cfg =
  112. SDRAM_CFG_SREN
  113. #if defined(CONFIG_DDR_2T_TIMING)
  114. | SDRAM_CFG_2T_EN
  115. #endif
  116. | SDRAM_CFG_SDRAM_TYPE_DDR1;
  117. #if defined (CONFIG_DDR_32BIT)
  118. /* for 32-bit mode burst length is 8 */
  119. im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE);
  120. #endif
  121. im->ddr.sdram_mode = CFG_DDR_MODE;
  122. im->ddr.sdram_interval = CFG_DDR_INTERVAL;
  123. udelay(200);
  124. /* enable DDR controller */
  125. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  126. return msize;
  127. }
  128. #endif/*!CFG_SPD_EEPROM*/
  129. int checkboard (void)
  130. {
  131. puts("Board: Wind River SBC834x\n");
  132. return 0;
  133. }
  134. /*
  135. * if board is fitted with SDRAM
  136. */
  137. #if defined(CFG_BR2_PRELIM) \
  138. && defined(CFG_OR2_PRELIM) \
  139. && defined(CFG_LBLAWBAR2_PRELIM) \
  140. && defined(CFG_LBLAWAR2_PRELIM)
  141. /*
  142. * Initialize SDRAM memory on the Local Bus.
  143. */
  144. void sdram_init(void)
  145. {
  146. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  147. volatile lbus83xx_t *lbc= &immap->lbus;
  148. uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
  149. puts("\n SDRAM on Local Bus: ");
  150. print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  151. /*
  152. * Setup SDRAM Base and Option Registers, already done in cpu_init.c
  153. */
  154. /* setup mtrpt, lsrt and lbcr for LB bus */
  155. lbc->lbcr = CFG_LBC_LBCR;
  156. lbc->mrtpr = CFG_LBC_MRTPR;
  157. lbc->lsrt = CFG_LBC_LSRT;
  158. asm("sync");
  159. /*
  160. * Configure the SDRAM controller Machine Mode Register.
  161. */
  162. lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation */
  163. lbc->lsdmr = CFG_LBC_LSDMR_1; /* 0x68636733; precharge all the banks */
  164. asm("sync");
  165. *sdram_addr = 0xff;
  166. udelay(100);
  167. lbc->lsdmr = CFG_LBC_LSDMR_2; /* 0x48636733; auto refresh */
  168. asm("sync");
  169. /*1 times*/
  170. *sdram_addr = 0xff;
  171. udelay(100);
  172. /*2 times*/
  173. *sdram_addr = 0xff;
  174. udelay(100);
  175. /*3 times*/
  176. *sdram_addr = 0xff;
  177. udelay(100);
  178. /*4 times*/
  179. *sdram_addr = 0xff;
  180. udelay(100);
  181. /*5 times*/
  182. *sdram_addr = 0xff;
  183. udelay(100);
  184. /*6 times*/
  185. *sdram_addr = 0xff;
  186. udelay(100);
  187. /*7 times*/
  188. *sdram_addr = 0xff;
  189. udelay(100);
  190. /*8 times*/
  191. *sdram_addr = 0xff;
  192. udelay(100);
  193. /* 0x58636733; mode register write operation */
  194. lbc->lsdmr = CFG_LBC_LSDMR_4;
  195. asm("sync");
  196. *sdram_addr = 0xff;
  197. udelay(100);
  198. lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation */
  199. asm("sync");
  200. *sdram_addr = 0xff;
  201. udelay(100);
  202. }
  203. #else
  204. void sdram_init(void)
  205. {
  206. puts(" SDRAM on Local Bus: Disabled in config\n");
  207. }
  208. #endif
  209. #if defined(CONFIG_OF_BOARD_SETUP)
  210. void ft_board_setup(void *blob, bd_t *bd)
  211. {
  212. #if defined(CONFIG_OF_FLAT_TREE)
  213. u32 *p;
  214. int len;
  215. p = ft_get_prop(blob, "/memory/reg", &len);
  216. if (p != NULL) {
  217. *p++ = cpu_to_be32(bd->bi_memstart);
  218. *p = cpu_to_be32(bd->bi_memsize);
  219. }
  220. #endif
  221. ft_cpu_setup(blob, bd);
  222. #ifdef CONFIG_PCI
  223. ft_pci_setup(blob, bd);
  224. #endif
  225. }
  226. #endif