mpc8540ads.c 7.2 KB

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