mpc8555cds.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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
  36. board_early_init_f(void)
  37. {
  38. return 0;
  39. }
  40. int
  41. 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(),
  55. pci_slot);
  56. printf("CPU Board Revision %d.%d (0x%04x)\n",
  57. MPC85XX_CPU_BOARD_MAJOR(cpu_board_rev),
  58. MPC85XX_CPU_BOARD_MINOR(cpu_board_rev),
  59. cpu_board_rev);
  60. printf(" PCI1: %d bit, %s MHz, %s\n",
  61. (pci1_32) ? 32 : 64,
  62. (pci1_speed == 33000000) ? "33" :
  63. (pci1_speed == 66000000) ? "66" : "unknown",
  64. pci1_clk_sel ? "sync" : "async"
  65. );
  66. if (pci_dual) {
  67. printf(" PCI2: 32 bit, 66 MHz, %s\n",
  68. pci2_clk_sel ? "sync" : "async"
  69. );
  70. } else {
  71. printf(" PCI2: disabled\n");
  72. }
  73. /*
  74. * Initialize local bus.
  75. */
  76. local_bus_init();
  77. return 0;
  78. }
  79. long int
  80. initdram(int board_type)
  81. {
  82. long dram_size = 0;
  83. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  84. puts("Initializing\n");
  85. #if defined(CONFIG_DDR_DLL)
  86. {
  87. /*
  88. * Work around to stabilize DDR DLL MSYNC_IN.
  89. * Errata DDR9 seems to have been fixed.
  90. * This is now the workaround for Errata DDR11:
  91. * Override DLL = 1, Course Adj = 1, Tap Select = 0
  92. */
  93. volatile ccsr_gur_t *gur= &immap->im_gur;
  94. gur->ddrdllcr = 0x81000000;
  95. asm("sync;isync;msync");
  96. udelay(200);
  97. }
  98. #endif
  99. dram_size = spd_sdram();
  100. #if defined(CONFIG_DDR_ECC)
  101. /*
  102. * Initialize and enable DDR ECC.
  103. */
  104. ddr_enable_ecc(dram_size);
  105. #endif
  106. /*
  107. * SDRAM Initialization
  108. */
  109. sdram_init();
  110. puts(" DDR: ");
  111. return dram_size;
  112. }
  113. /*
  114. * Initialize Local Bus
  115. */
  116. void
  117. local_bus_init(void)
  118. {
  119. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  120. volatile ccsr_gur_t *gur = &immap->im_gur;
  121. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  122. uint clkdiv;
  123. uint lbc_hz;
  124. sys_info_t sysinfo;
  125. uint temp_lbcdll;
  126. /*
  127. * Errata LBC11.
  128. * Fix Local Bus clock glitch when DLL is enabled.
  129. *
  130. * If localbus freq is < 66Mhz, DLL bypass mode must be used.
  131. * If localbus freq is > 133Mhz, DLL can be safely enabled.
  132. * Between 66 and 133, the DLL is enabled with an override workaround.
  133. */
  134. get_sys_info(&sysinfo);
  135. clkdiv = lbc->lcrr & 0x0f;
  136. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  137. if (lbc_hz < 66) {
  138. lbc->lcrr |= 0x80000000; /* DLL Bypass */
  139. } else if (lbc_hz >= 133) {
  140. lbc->lcrr &= (~0x80000000); /* DLL Enabled */
  141. } else {
  142. lbc->lcrr &= (~0x8000000); /* DLL Enabled */
  143. udelay(200);
  144. /*
  145. * Sample LBC DLL ctrl reg, upshift it to set the
  146. * override bits.
  147. */
  148. temp_lbcdll = gur->lbcdllcr;
  149. gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
  150. asm("sync;isync;msync");
  151. }
  152. }
  153. /*
  154. * Initialize SDRAM memory on the Local Bus.
  155. */
  156. void
  157. sdram_init(void)
  158. {
  159. #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
  160. uint idx;
  161. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  162. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  163. uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
  164. uint cpu_board_rev;
  165. uint lsdmr_common;
  166. puts(" SDRAM: ");
  167. print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  168. /*
  169. * Setup SDRAM Base and Option Registers
  170. */
  171. lbc->or2 = CFG_OR2_PRELIM;
  172. asm("msync");
  173. lbc->br2 = CFG_BR2_PRELIM;
  174. asm("msync");
  175. lbc->lbcr = CFG_LBC_LBCR;
  176. asm("msync");
  177. lbc->lsrt = CFG_LBC_LSRT;
  178. lbc->mrtpr = CFG_LBC_MRTPR;
  179. asm("msync");
  180. /*
  181. * Determine which address lines to use baed on CPU board rev.
  182. */
  183. cpu_board_rev = get_cpu_board_revision();
  184. lsdmr_common = CFG_LBC_LSDMR_COMMON;
  185. if (cpu_board_rev == MPC85XX_CPU_BOARD_REV_1_0) {
  186. lsdmr_common |= CFG_LBC_LSDMR_BSMA1617;
  187. } else if (cpu_board_rev == MPC85XX_CPU_BOARD_REV_1_1) {
  188. lsdmr_common |= CFG_LBC_LSDMR_BSMA1516;
  189. } else {
  190. /*
  191. * Assume something unable to identify itself is
  192. * really old, and likely has lines 16/17 mapped.
  193. */
  194. lsdmr_common |= CFG_LBC_LSDMR_BSMA1617;
  195. }
  196. /*
  197. * Issue PRECHARGE ALL command.
  198. */
  199. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL;
  200. asm("sync;msync");
  201. *sdram_addr = 0xff;
  202. ppcDcbf((unsigned long) sdram_addr);
  203. udelay(100);
  204. /*
  205. * Issue 8 AUTO REFRESH commands.
  206. */
  207. for (idx = 0; idx < 8; idx++) {
  208. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH;
  209. asm("sync;msync");
  210. *sdram_addr = 0xff;
  211. ppcDcbf((unsigned long) sdram_addr);
  212. udelay(100);
  213. }
  214. /*
  215. * Issue 8 MODE-set command.
  216. */
  217. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW;
  218. asm("sync;msync");
  219. *sdram_addr = 0xff;
  220. ppcDcbf((unsigned long) sdram_addr);
  221. udelay(100);
  222. /*
  223. * Issue NORMAL OP command.
  224. */
  225. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL;
  226. asm("sync;msync");
  227. *sdram_addr = 0xff;
  228. ppcDcbf((unsigned long) sdram_addr);
  229. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  230. #endif /* enable SDRAM init */
  231. }
  232. #if defined(CFG_DRAM_TEST)
  233. int
  234. testdram(void)
  235. {
  236. uint *pstart = (uint *) CFG_MEMTEST_START;
  237. uint *pend = (uint *) CFG_MEMTEST_END;
  238. uint *p;
  239. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  240. CFG_MEMTEST_START,
  241. CFG_MEMTEST_END);
  242. printf("DRAM test phase 1:\n");
  243. for (p = pstart; p < pend; p++)
  244. *p = 0xaaaaaaaa;
  245. for (p = pstart; p < pend; p++) {
  246. if (*p != 0xaaaaaaaa) {
  247. printf ("DRAM test fails at: %08x\n", (uint) p);
  248. return 1;
  249. }
  250. }
  251. printf("DRAM test phase 2:\n");
  252. for (p = pstart; p < pend; p++)
  253. *p = 0x55555555;
  254. for (p = pstart; p < pend; p++) {
  255. if (*p != 0x55555555) {
  256. printf ("DRAM test fails at: %08x\n", (uint) p);
  257. return 1;
  258. }
  259. }
  260. printf("DRAM test passed.\n");
  261. return 0;
  262. }
  263. #endif
  264. #if defined(CONFIG_PCI)
  265. /*
  266. * Initialize PCI Devices, report devices found.
  267. */
  268. #ifndef CONFIG_PCI_PNP
  269. static struct pci_config_table pci_mpc85xxcds_config_table[] = {
  270. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  271. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  272. pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
  273. PCI_ENET0_MEMADDR,
  274. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
  275. } },
  276. { }
  277. };
  278. #endif
  279. static struct pci_controller hose = {
  280. #ifndef CONFIG_PCI_PNP
  281. config_table: pci_mpc85xxcds_config_table,
  282. #endif
  283. };
  284. #endif /* CONFIG_PCI */
  285. void
  286. pci_init_board(void)
  287. {
  288. #ifdef CONFIG_PCI
  289. extern void pci_mpc85xx_init(struct pci_controller *hose);
  290. pci_mpc85xx_init(&hose);
  291. #endif
  292. }