mpc8540ads.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /*
  2. * Copyright 2004 Freescale Semiconductor.
  3. * (C) Copyright 2002,2003, Motorola Inc.
  4. * Xianghua Xiao, (X.Xiao@motorola.com)
  5. *
  6. * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
  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. #include <common.h>
  27. #include <pci.h>
  28. #include <asm/processor.h>
  29. #include <asm/immap_85xx.h>
  30. #include <spd_sdram.h>
  31. #include <libfdt.h>
  32. #include <fdt_support.h>
  33. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  34. extern void ddr_enable_ecc(unsigned int dram_size);
  35. #endif
  36. void local_bus_init(void);
  37. void sdram_init(void);
  38. long int fixed_sdram(void);
  39. int checkboard (void)
  40. {
  41. puts("Board: ADS\n");
  42. #ifdef CONFIG_PCI
  43. printf(" PCI1: 32 bit, %d MHz (compiled)\n",
  44. CONFIG_SYS_CLK_FREQ / 1000000);
  45. #else
  46. printf(" PCI1: disabled\n");
  47. #endif
  48. /*
  49. * Initialize local bus.
  50. */
  51. local_bus_init();
  52. return 0;
  53. }
  54. long int
  55. initdram(int board_type)
  56. {
  57. long dram_size = 0;
  58. puts("Initializing\n");
  59. #if defined(CONFIG_DDR_DLL)
  60. {
  61. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  62. uint temp_ddrdll = 0;
  63. /*
  64. * Work around to stabilize DDR DLL
  65. */
  66. temp_ddrdll = gur->ddrdllcr;
  67. gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
  68. asm("sync;isync;msync");
  69. }
  70. #endif
  71. #if defined(CONFIG_SPD_EEPROM)
  72. dram_size = spd_sdram ();
  73. #else
  74. dram_size = fixed_sdram ();
  75. #endif
  76. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  77. /*
  78. * Initialize and enable DDR ECC.
  79. */
  80. ddr_enable_ecc(dram_size);
  81. #endif
  82. /*
  83. * Initialize SDRAM.
  84. */
  85. sdram_init();
  86. puts(" DDR: ");
  87. return dram_size;
  88. }
  89. /*
  90. * Initialize Local Bus
  91. */
  92. void
  93. local_bus_init(void)
  94. {
  95. volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
  96. volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
  97. uint clkdiv;
  98. uint lbc_hz;
  99. sys_info_t sysinfo;
  100. /*
  101. * Errata LBC11.
  102. * Fix Local Bus clock glitch when DLL is enabled.
  103. *
  104. * If localbus freq is < 66Mhz, DLL bypass mode must be used.
  105. * If localbus freq is > 133Mhz, DLL can be safely enabled.
  106. * Between 66 and 133, the DLL is enabled with an override workaround.
  107. */
  108. get_sys_info(&sysinfo);
  109. clkdiv = lbc->lcrr & 0x0f;
  110. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  111. if (lbc_hz < 66) {
  112. lbc->lcrr = CFG_LBC_LCRR | 0x80000000; /* DLL Bypass */
  113. } else if (lbc_hz >= 133) {
  114. lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
  115. } else {
  116. /*
  117. * On REV1 boards, need to change CLKDIV before enable DLL.
  118. * Default CLKDIV is 8, change it to 4 temporarily.
  119. */
  120. uint pvr = get_pvr();
  121. uint temp_lbcdll = 0;
  122. if (pvr == PVR_85xx_REV1) {
  123. /* FIXME: Justify the high bit here. */
  124. lbc->lcrr = 0x10000004;
  125. }
  126. lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
  127. udelay(200);
  128. /*
  129. * Sample LBC DLL ctrl reg, upshift it to set the
  130. * override bits.
  131. */
  132. temp_lbcdll = gur->lbcdllcr;
  133. gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
  134. asm("sync;isync;msync");
  135. }
  136. }
  137. /*
  138. * Initialize SDRAM memory on the Local Bus.
  139. */
  140. void
  141. sdram_init(void)
  142. {
  143. volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
  144. uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
  145. puts(" SDRAM: ");
  146. print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  147. /*
  148. * Setup SDRAM Base and Option Registers
  149. */
  150. lbc->or2 = CFG_OR2_PRELIM;
  151. lbc->br2 = CFG_BR2_PRELIM;
  152. lbc->lbcr = CFG_LBC_LBCR;
  153. asm("msync");
  154. lbc->lsrt = CFG_LBC_LSRT;
  155. lbc->mrtpr = CFG_LBC_MRTPR;
  156. asm("sync");
  157. /*
  158. * Configure the SDRAM controller.
  159. */
  160. lbc->lsdmr = CFG_LBC_LSDMR_1;
  161. asm("sync");
  162. *sdram_addr = 0xff;
  163. ppcDcbf((unsigned long) sdram_addr);
  164. udelay(100);
  165. lbc->lsdmr = CFG_LBC_LSDMR_2;
  166. asm("sync");
  167. *sdram_addr = 0xff;
  168. ppcDcbf((unsigned long) sdram_addr);
  169. udelay(100);
  170. lbc->lsdmr = CFG_LBC_LSDMR_3;
  171. asm("sync");
  172. *sdram_addr = 0xff;
  173. ppcDcbf((unsigned long) sdram_addr);
  174. udelay(100);
  175. lbc->lsdmr = CFG_LBC_LSDMR_4;
  176. asm("sync");
  177. *sdram_addr = 0xff;
  178. ppcDcbf((unsigned long) sdram_addr);
  179. udelay(100);
  180. lbc->lsdmr = CFG_LBC_LSDMR_5;
  181. asm("sync");
  182. *sdram_addr = 0xff;
  183. ppcDcbf((unsigned long) sdram_addr);
  184. udelay(100);
  185. }
  186. #if !defined(CONFIG_SPD_EEPROM)
  187. /*************************************************************************
  188. * fixed sdram init -- doesn't use serial presence detect.
  189. ************************************************************************/
  190. long int fixed_sdram (void)
  191. {
  192. #ifndef CFG_RAMBOOT
  193. volatile ccsr_ddr_t *ddr= (void *)(CFG_MPC85xx_DDR_ADDR);
  194. ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
  195. ddr->cs0_config = CFG_DDR_CS0_CONFIG;
  196. ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
  197. ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
  198. ddr->sdram_mode = CFG_DDR_MODE;
  199. ddr->sdram_interval = CFG_DDR_INTERVAL;
  200. #if defined (CONFIG_DDR_ECC)
  201. ddr->err_disable = 0x0000000D;
  202. ddr->err_sbe = 0x00ff0000;
  203. #endif
  204. asm("sync;isync;msync");
  205. udelay(500);
  206. #if defined (CONFIG_DDR_ECC)
  207. /* Enable ECC checking */
  208. ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
  209. #else
  210. ddr->sdram_cfg = CFG_DDR_CONTROL;
  211. #endif
  212. asm("sync; isync; msync");
  213. udelay(500);
  214. #endif
  215. return CFG_SDRAM_SIZE * 1024 * 1024;
  216. }
  217. #endif /* !defined(CONFIG_SPD_EEPROM) */
  218. #if defined(CONFIG_PCI)
  219. /*
  220. * Initialize PCI Devices, report devices found.
  221. */
  222. static struct pci_controller hose;
  223. #endif /* CONFIG_PCI */
  224. void
  225. pci_init_board(void)
  226. {
  227. #ifdef CONFIG_PCI
  228. pci_mpc85xx_init(&hose);
  229. #endif /* CONFIG_PCI */
  230. }
  231. #if defined(CONFIG_OF_BOARD_SETUP)
  232. void
  233. ft_board_setup(void *blob, bd_t *bd)
  234. {
  235. int node, tmp[2];
  236. const char *path;
  237. ft_cpu_setup(blob, bd);
  238. node = fdt_path_offset(blob, "/aliases");
  239. tmp[0] = 0;
  240. if (node >= 0) {
  241. #ifdef CONFIG_PCI
  242. path = fdt_getprop(blob, node, "pci0", NULL);
  243. if (path) {
  244. tmp[1] = hose.last_busno - hose.first_busno;
  245. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  246. }
  247. #endif
  248. }
  249. }
  250. #endif