sbc8349.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <ioports.h>
  12. #include <mpc83xx.h>
  13. #include <asm/mpc8349_pci.h>
  14. #include <i2c.h>
  15. #include <spd_sdram.h>
  16. #include <miiphy.h>
  17. #if defined(CONFIG_OF_LIBFDT)
  18. #include <libfdt.h>
  19. #endif
  20. int fixed_sdram(void);
  21. void sdram_init(void);
  22. #if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83xx)
  23. void ddr_enable_ecc(unsigned int dram_size);
  24. #endif
  25. #ifdef CONFIG_BOARD_EARLY_INIT_F
  26. int board_early_init_f (void)
  27. {
  28. return 0;
  29. }
  30. #endif
  31. #define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
  32. phys_size_t initdram (int board_type)
  33. {
  34. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  35. u32 msize = 0;
  36. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
  37. return -1;
  38. /* DDR SDRAM - Main SODIMM */
  39. im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_BASE & LAWBAR_BAR;
  40. #if defined(CONFIG_SPD_EEPROM)
  41. msize = spd_sdram();
  42. #else
  43. msize = fixed_sdram();
  44. #endif
  45. /*
  46. * Initialize SDRAM if it is on local bus.
  47. */
  48. sdram_init();
  49. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  50. /*
  51. * Initialize and enable DDR ECC.
  52. */
  53. ddr_enable_ecc(msize * 1024 * 1024);
  54. #endif
  55. /* return total bus SDRAM size(bytes) -- DDR */
  56. return (msize * 1024 * 1024);
  57. }
  58. #if !defined(CONFIG_SPD_EEPROM)
  59. /*************************************************************************
  60. * fixed sdram init -- doesn't use serial presence detect.
  61. ************************************************************************/
  62. int fixed_sdram(void)
  63. {
  64. volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  65. u32 msize = CONFIG_SYS_DDR_SIZE;
  66. u32 ddr_size = msize << 20; /* DDR size in bytes */
  67. u32 ddr_size_log2 = __ilog2(msize);
  68. im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
  69. im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
  70. #if (CONFIG_SYS_DDR_SIZE != 256)
  71. #warning Currently any ddr size other than 256 is not supported
  72. #endif
  73. #if ((CONFIG_SYS_DDR_SDRAM_BASE & 0x00FFFFFF) != 0)
  74. #warning Chip select bounds is only configurable in 16MB increments
  75. #endif
  76. im->ddr.csbnds[2].csbnds =
  77. ((CONFIG_SYS_DDR_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
  78. (((CONFIG_SYS_DDR_SDRAM_BASE + ddr_size - 1) >>
  79. CSBNDS_EA_SHIFT) & CSBNDS_EA);
  80. im->ddr.cs_config[2] = CONFIG_SYS_DDR_CS2_CONFIG;
  81. /* currently we use only one CS, so disable the other banks */
  82. im->ddr.cs_config[0] = 0;
  83. im->ddr.cs_config[1] = 0;
  84. im->ddr.cs_config[3] = 0;
  85. im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  86. im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  87. im->ddr.sdram_cfg =
  88. SDRAM_CFG_SREN
  89. #if defined(CONFIG_DDR_2T_TIMING)
  90. | SDRAM_CFG_2T_EN
  91. #endif
  92. | SDRAM_CFG_SDRAM_TYPE_DDR1;
  93. #if defined (CONFIG_DDR_32BIT)
  94. /* for 32-bit mode burst length is 8 */
  95. im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE);
  96. #endif
  97. im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
  98. im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  99. udelay(200);
  100. /* enable DDR controller */
  101. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  102. return msize;
  103. }
  104. #endif/*!CONFIG_SYS_SPD_EEPROM*/
  105. int checkboard (void)
  106. {
  107. puts("Board: Wind River SBC834x\n");
  108. return 0;
  109. }
  110. /*
  111. * if board is fitted with SDRAM
  112. */
  113. #if defined(CONFIG_SYS_BR2_PRELIM) \
  114. && defined(CONFIG_SYS_OR2_PRELIM) \
  115. && defined(CONFIG_SYS_LBLAWBAR2_PRELIM) \
  116. && defined(CONFIG_SYS_LBLAWAR2_PRELIM)
  117. /*
  118. * Initialize SDRAM memory on the Local Bus.
  119. */
  120. void sdram_init(void)
  121. {
  122. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  123. volatile fsl_lbc_t *lbc = &immap->im_lbc;
  124. uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
  125. puts("\n SDRAM on Local Bus: ");
  126. print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  127. /*
  128. * Setup SDRAM Base and Option Registers, already done in cpu_init.c
  129. */
  130. /* setup mtrpt, lsrt and lbcr for LB bus */
  131. lbc->lbcr = CONFIG_SYS_LBC_LBCR;
  132. lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
  133. lbc->lsrt = CONFIG_SYS_LBC_LSRT;
  134. asm("sync");
  135. /*
  136. * Configure the SDRAM controller Machine Mode Register.
  137. */
  138. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5; /* 0x40636733; normal operation */
  139. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1; /* 0x68636733; precharge all the banks */
  140. asm("sync");
  141. *sdram_addr = 0xff;
  142. udelay(100);
  143. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2; /* 0x48636733; auto refresh */
  144. asm("sync");
  145. /*1 times*/
  146. *sdram_addr = 0xff;
  147. udelay(100);
  148. /*2 times*/
  149. *sdram_addr = 0xff;
  150. udelay(100);
  151. /*3 times*/
  152. *sdram_addr = 0xff;
  153. udelay(100);
  154. /*4 times*/
  155. *sdram_addr = 0xff;
  156. udelay(100);
  157. /*5 times*/
  158. *sdram_addr = 0xff;
  159. udelay(100);
  160. /*6 times*/
  161. *sdram_addr = 0xff;
  162. udelay(100);
  163. /*7 times*/
  164. *sdram_addr = 0xff;
  165. udelay(100);
  166. /*8 times*/
  167. *sdram_addr = 0xff;
  168. udelay(100);
  169. /* 0x58636733; mode register write operation */
  170. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4;
  171. asm("sync");
  172. *sdram_addr = 0xff;
  173. udelay(100);
  174. lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5; /* 0x40636733; normal operation */
  175. asm("sync");
  176. *sdram_addr = 0xff;
  177. udelay(100);
  178. }
  179. #else
  180. void sdram_init(void)
  181. {
  182. puts(" SDRAM on Local Bus: Disabled in config\n");
  183. }
  184. #endif
  185. #if defined(CONFIG_OF_BOARD_SETUP)
  186. int ft_board_setup(void *blob, bd_t *bd)
  187. {
  188. ft_cpu_setup(blob, bd);
  189. #ifdef CONFIG_PCI
  190. ft_pci_setup(blob, bd);
  191. #endif
  192. return 0;
  193. }
  194. #endif