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