mpc8540ads.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. return 0;
  41. }
  42. int checkboard (void)
  43. {
  44. puts("Board: ADS\n");
  45. #ifdef CONFIG_PCI
  46. printf(" PCI1: 32 bit, %d MHz (compiled)\n",
  47. CONFIG_SYS_CLK_FREQ / 1000000);
  48. #else
  49. printf(" PCI1: disabled\n");
  50. #endif
  51. /*
  52. * Initialize local bus.
  53. */
  54. local_bus_init();
  55. return 0;
  56. }
  57. long int
  58. initdram(int board_type)
  59. {
  60. long dram_size = 0;
  61. extern long spd_sdram (void);
  62. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  63. puts("Initializing\n");
  64. #if defined(CONFIG_DDR_DLL)
  65. {
  66. volatile ccsr_gur_t *gur= &immap->im_gur;
  67. uint temp_ddrdll = 0;
  68. /*
  69. * Work around to stabilize DDR DLL
  70. */
  71. temp_ddrdll = gur->ddrdllcr;
  72. gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
  73. asm("sync;isync;msync");
  74. }
  75. #endif
  76. #if defined(CONFIG_SPD_EEPROM)
  77. dram_size = spd_sdram ();
  78. #else
  79. dram_size = fixed_sdram ();
  80. #endif
  81. #if defined(CONFIG_DDR_ECC)
  82. /*
  83. * Initialize and enable DDR ECC.
  84. */
  85. ddr_enable_ecc(dram_size);
  86. #endif
  87. /*
  88. * Initialize SDRAM.
  89. */
  90. sdram_init();
  91. puts(" DDR: ");
  92. return dram_size;
  93. }
  94. /*
  95. * Initialize Local Bus
  96. */
  97. void
  98. local_bus_init(void)
  99. {
  100. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  101. volatile ccsr_gur_t *gur = &immap->im_gur;
  102. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  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 immap_t *immap = (immap_t *)CFG_IMMR;
  150. volatile ccsr_lbc_t *lbc= &immap->im_lbc;
  151. uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
  152. puts(" SDRAM: ");
  153. print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  154. /*
  155. * Setup SDRAM Base and Option Registers
  156. */
  157. lbc->or2 = CFG_OR2_PRELIM;
  158. lbc->br2 = CFG_BR2_PRELIM;
  159. lbc->lbcr = CFG_LBC_LBCR;
  160. asm("msync");
  161. lbc->lsrt = CFG_LBC_LSRT;
  162. lbc->mrtpr = CFG_LBC_MRTPR;
  163. asm("sync");
  164. /*
  165. * Configure the SDRAM controller.
  166. */
  167. lbc->lsdmr = CFG_LBC_LSDMR_1;
  168. asm("sync");
  169. *sdram_addr = 0xff;
  170. ppcDcbf((unsigned long) sdram_addr);
  171. udelay(100);
  172. lbc->lsdmr = CFG_LBC_LSDMR_2;
  173. asm("sync");
  174. *sdram_addr = 0xff;
  175. ppcDcbf((unsigned long) sdram_addr);
  176. udelay(100);
  177. lbc->lsdmr = CFG_LBC_LSDMR_3;
  178. asm("sync");
  179. *sdram_addr = 0xff;
  180. ppcDcbf((unsigned long) sdram_addr);
  181. udelay(100);
  182. lbc->lsdmr = CFG_LBC_LSDMR_4;
  183. asm("sync");
  184. *sdram_addr = 0xff;
  185. ppcDcbf((unsigned long) sdram_addr);
  186. udelay(100);
  187. lbc->lsdmr = CFG_LBC_LSDMR_5;
  188. asm("sync");
  189. *sdram_addr = 0xff;
  190. ppcDcbf((unsigned long) sdram_addr);
  191. udelay(100);
  192. }
  193. #if defined(CFG_DRAM_TEST)
  194. int testdram (void)
  195. {
  196. uint *pstart = (uint *) CFG_MEMTEST_START;
  197. uint *pend = (uint *) CFG_MEMTEST_END;
  198. uint *p;
  199. printf("SDRAM test phase 1:\n");
  200. for (p = pstart; p < pend; p++)
  201. *p = 0xaaaaaaaa;
  202. for (p = pstart; p < pend; p++) {
  203. if (*p != 0xaaaaaaaa) {
  204. printf ("SDRAM test fails at: %08x\n", (uint) p);
  205. return 1;
  206. }
  207. }
  208. printf("SDRAM test phase 2:\n");
  209. for (p = pstart; p < pend; p++)
  210. *p = 0x55555555;
  211. for (p = pstart; p < pend; p++) {
  212. if (*p != 0x55555555) {
  213. printf ("SDRAM test fails at: %08x\n", (uint) p);
  214. return 1;
  215. }
  216. }
  217. printf("SDRAM test passed.\n");
  218. return 0;
  219. }
  220. #endif
  221. #if !defined(CONFIG_SPD_EEPROM)
  222. /*************************************************************************
  223. * fixed sdram init -- doesn't use serial presence detect.
  224. ************************************************************************/
  225. long int fixed_sdram (void)
  226. {
  227. #ifndef CFG_RAMBOOT
  228. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  229. volatile ccsr_ddr_t *ddr= &immap->im_ddr;
  230. ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
  231. ddr->cs0_config = CFG_DDR_CS0_CONFIG;
  232. ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
  233. ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
  234. ddr->sdram_mode = CFG_DDR_MODE;
  235. ddr->sdram_interval = CFG_DDR_INTERVAL;
  236. #if defined (CONFIG_DDR_ECC)
  237. ddr->err_disable = 0x0000000D;
  238. ddr->err_sbe = 0x00ff0000;
  239. #endif
  240. asm("sync;isync;msync");
  241. udelay(500);
  242. #if defined (CONFIG_DDR_ECC)
  243. /* Enable ECC checking */
  244. ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
  245. #else
  246. ddr->sdram_cfg = CFG_DDR_CONTROL;
  247. #endif
  248. asm("sync; isync; msync");
  249. udelay(500);
  250. #endif
  251. return CFG_SDRAM_SIZE * 1024 * 1024;
  252. }
  253. #endif /* !defined(CONFIG_SPD_EEPROM) */
  254. #if defined(CONFIG_PCI)
  255. /*
  256. * Initialize PCI Devices, report devices found.
  257. */
  258. #ifndef CONFIG_PCI_PNP
  259. static struct pci_config_table pci_mpc85xxads_config_table[] = {
  260. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  261. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  262. pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
  263. PCI_ENET0_MEMADDR,
  264. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
  265. } },
  266. { }
  267. };
  268. #endif
  269. static struct pci_controller hose = {
  270. #ifndef CONFIG_PCI_PNP
  271. config_table: pci_mpc85xxads_config_table,
  272. #endif
  273. };
  274. #endif /* CONFIG_PCI */
  275. void
  276. pci_init_board(void)
  277. {
  278. #ifdef CONFIG_PCI
  279. extern void pci_mpc85xx_init(struct pci_controller *hose);
  280. pci_mpc85xx_init(&hose);
  281. #endif /* CONFIG_PCI */
  282. }