mpc8540ads.c 7.1 KB

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