mpc8541cds.c 7.7 KB

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