mpc8541cds.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /*
  2. * Copyright 2004 Freescale Semiconductor.
  3. *
  4. * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <pci.h>
  26. #include <asm/processor.h>
  27. #include <asm/immap_85xx.h>
  28. #include <spd.h>
  29. #include "../common/cadmus.h"
  30. #include "../common/eeprom.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. int board_early_init_f (void)
  38. {
  39. return 0;
  40. }
  41. int checkboard (void)
  42. {
  43. volatile immap_t *immap = (immap_t *) CFG_CCSRBAR;
  44. volatile ccsr_gur_t *gur = &immap->im_gur;
  45. /* PCI slot in USER bits CSR[6:7] by convention. */
  46. uint pci_slot = get_pci_slot ();
  47. uint pci_dual = get_pci_dual (); /* PCI DUAL in CM_PCI[3] */
  48. uint pci1_32 = gur->pordevsr & 0x10000; /* PORDEVSR[15] */
  49. uint pci1_clk_sel = gur->porpllsr & 0x8000; /* PORPLLSR[16] */
  50. uint pci2_clk_sel = gur->porpllsr & 0x4000; /* PORPLLSR[17] */
  51. uint pci1_speed = get_clock_freq (); /* PCI PSPEED in [4:5] */
  52. uint cpu_board_rev = get_cpu_board_revision ();
  53. printf ("Board: CDS Version 0x%02x, PCI Slot %d\n",
  54. get_board_version (), pci_slot);
  55. printf ("CPU Board Revision %d.%d (0x%04x)\n",
  56. MPC85XX_CPU_BOARD_MAJOR (cpu_board_rev),
  57. MPC85XX_CPU_BOARD_MINOR (cpu_board_rev), cpu_board_rev);
  58. printf (" PCI1: %d bit, %s MHz, %s\n",
  59. (pci1_32) ? 32 : 64,
  60. (pci1_speed == 33000000) ? "33" :
  61. (pci1_speed == 66000000) ? "66" : "unknown",
  62. pci1_clk_sel ? "sync" : "async");
  63. if (pci_dual) {
  64. printf (" PCI2: 32 bit, 66 MHz, %s\n",
  65. pci2_clk_sel ? "sync" : "async");
  66. } else {
  67. printf (" PCI2: disabled\n");
  68. }
  69. /*
  70. * Initialize local bus.
  71. */
  72. local_bus_init ();
  73. return 0;
  74. }
  75. long int
  76. initdram(int board_type)
  77. {
  78. long dram_size = 0;
  79. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  80. puts("Initializing\n");
  81. #if defined(CONFIG_DDR_DLL)
  82. {
  83. /*
  84. * Work around to stabilize DDR DLL MSYNC_IN.
  85. * Errata DDR9 seems to have been fixed.
  86. * This is now the workaround for Errata DDR11:
  87. * Override DLL = 1, Course Adj = 1, Tap Select = 0
  88. */
  89. volatile ccsr_gur_t *gur= &immap->im_gur;
  90. gur->ddrdllcr = 0x81000000;
  91. asm("sync;isync;msync");
  92. udelay(200);
  93. }
  94. #endif
  95. dram_size = spd_sdram();
  96. #if defined(CONFIG_DDR_ECC)
  97. /*
  98. * Initialize and enable DDR ECC.
  99. */
  100. ddr_enable_ecc(dram_size);
  101. #endif
  102. /*
  103. * SDRAM Initialization
  104. */
  105. sdram_init();
  106. puts(" DDR: ");
  107. return dram_size;
  108. }
  109. /*
  110. * Initialize Local Bus
  111. */
  112. void
  113. local_bus_init(void)
  114. {
  115. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  116. volatile ccsr_gur_t *gur = &immap->im_gur;
  117. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  118. uint clkdiv;
  119. uint lbc_hz;
  120. sys_info_t sysinfo;
  121. uint temp_lbcdll;
  122. /*
  123. * Errata LBC11.
  124. * Fix Local Bus clock glitch when DLL is enabled.
  125. *
  126. * If localbus freq is < 66Mhz, DLL bypass mode must be used.
  127. * If localbus freq is > 133Mhz, DLL can be safely enabled.
  128. * Between 66 and 133, the DLL is enabled with an override workaround.
  129. */
  130. get_sys_info(&sysinfo);
  131. clkdiv = lbc->lcrr & 0x0f;
  132. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  133. if (lbc_hz < 66) {
  134. lbc->lcrr |= 0x80000000; /* DLL Bypass */
  135. } else if (lbc_hz >= 133) {
  136. lbc->lcrr &= (~0x80000000); /* DLL Enabled */
  137. } else {
  138. lbc->lcrr &= (~0x8000000); /* DLL Enabled */
  139. udelay(200);
  140. /*
  141. * Sample LBC DLL ctrl reg, upshift it to set the
  142. * override bits.
  143. */
  144. temp_lbcdll = gur->lbcdllcr;
  145. gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
  146. asm("sync;isync;msync");
  147. }
  148. }
  149. /*
  150. * Initialize SDRAM memory on the Local Bus.
  151. */
  152. void
  153. sdram_init(void)
  154. {
  155. #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
  156. uint idx;
  157. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  158. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  159. uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
  160. uint cpu_board_rev;
  161. uint lsdmr_common;
  162. puts(" SDRAM: ");
  163. print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  164. /*
  165. * Setup SDRAM Base and Option Registers
  166. */
  167. lbc->or2 = CFG_OR2_PRELIM;
  168. asm("msync");
  169. lbc->br2 = CFG_BR2_PRELIM;
  170. asm("msync");
  171. lbc->lbcr = CFG_LBC_LBCR;
  172. asm("msync");
  173. lbc->lsrt = CFG_LBC_LSRT;
  174. lbc->mrtpr = CFG_LBC_MRTPR;
  175. asm("msync");
  176. /*
  177. * Determine which address lines to use baed on CPU board rev.
  178. */
  179. cpu_board_rev = get_cpu_board_revision();
  180. lsdmr_common = CFG_LBC_LSDMR_COMMON;
  181. if (cpu_board_rev == MPC85XX_CPU_BOARD_REV_1_0) {
  182. lsdmr_common |= CFG_LBC_LSDMR_BSMA1617;
  183. } else if (cpu_board_rev == MPC85XX_CPU_BOARD_REV_1_1) {
  184. lsdmr_common |= CFG_LBC_LSDMR_BSMA1516;
  185. } else {
  186. /*
  187. * Assume something unable to identify itself is
  188. * really old, and likely has lines 16/17 mapped.
  189. */
  190. lsdmr_common |= CFG_LBC_LSDMR_BSMA1617;
  191. }
  192. /*
  193. * Issue PRECHARGE ALL command.
  194. */
  195. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL;
  196. asm("sync;msync");
  197. *sdram_addr = 0xff;
  198. ppcDcbf((unsigned long) sdram_addr);
  199. udelay(100);
  200. /*
  201. * Issue 8 AUTO REFRESH commands.
  202. */
  203. for (idx = 0; idx < 8; idx++) {
  204. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH;
  205. asm("sync;msync");
  206. *sdram_addr = 0xff;
  207. ppcDcbf((unsigned long) sdram_addr);
  208. udelay(100);
  209. }
  210. /*
  211. * Issue 8 MODE-set command.
  212. */
  213. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW;
  214. asm("sync;msync");
  215. *sdram_addr = 0xff;
  216. ppcDcbf((unsigned long) sdram_addr);
  217. udelay(100);
  218. /*
  219. * Issue NORMAL OP command.
  220. */
  221. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL;
  222. asm("sync;msync");
  223. *sdram_addr = 0xff;
  224. ppcDcbf((unsigned long) sdram_addr);
  225. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  226. #endif /* enable SDRAM init */
  227. }
  228. #if defined(CFG_DRAM_TEST)
  229. int
  230. testdram(void)
  231. {
  232. uint *pstart = (uint *) CFG_MEMTEST_START;
  233. uint *pend = (uint *) CFG_MEMTEST_END;
  234. uint *p;
  235. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  236. CFG_MEMTEST_START,
  237. CFG_MEMTEST_END);
  238. printf("DRAM test phase 1:\n");
  239. for (p = pstart; p < pend; p++)
  240. *p = 0xaaaaaaaa;
  241. for (p = pstart; p < pend; p++) {
  242. if (*p != 0xaaaaaaaa) {
  243. printf ("DRAM test fails at: %08x\n", (uint) p);
  244. return 1;
  245. }
  246. }
  247. printf("DRAM test phase 2:\n");
  248. for (p = pstart; p < pend; p++)
  249. *p = 0x55555555;
  250. for (p = pstart; p < pend; p++) {
  251. if (*p != 0x55555555) {
  252. printf ("DRAM test fails at: %08x\n", (uint) p);
  253. return 1;
  254. }
  255. }
  256. printf("DRAM test passed.\n");
  257. return 0;
  258. }
  259. #endif
  260. #if defined(CONFIG_PCI)
  261. /*
  262. * Initialize PCI Devices, report devices found.
  263. */
  264. #ifndef CONFIG_PCI_PNP
  265. static struct pci_config_table pci_mpc85xxcds_config_table[] = {
  266. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  267. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  268. pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
  269. PCI_ENET0_MEMADDR,
  270. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
  271. } },
  272. { }
  273. };
  274. #endif
  275. static struct pci_controller hose = {
  276. #ifndef CONFIG_PCI_PNP
  277. config_table: pci_mpc85xxcds_config_table,
  278. #endif
  279. };
  280. #endif /* CONFIG_PCI */
  281. void
  282. pci_init_board(void)
  283. {
  284. #ifdef CONFIG_PCI
  285. extern void pci_mpc85xx_init(struct pci_controller *hose);
  286. pci_mpc85xx_init(&hose);
  287. #endif
  288. }