mpc8555cds.c 7.6 KB

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