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