mpc8540ads.c 7.2 KB

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