mpc8540ads.c 6.7 KB

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