mpc8548cds.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  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. /*
  74. * Hack TSEC 3 and 4 IO voltages.
  75. */
  76. gur->tsec34ioovcr = 0xe7e0; /* 1110 0111 1110 0xxx */
  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) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  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. get_sys_info(&sysinfo);
  126. clkdiv = (lbc->lcrr & 0x0f) * 2;
  127. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  128. gur->lbiuiplldcr1 = 0x00078080;
  129. if (clkdiv == 16) {
  130. gur->lbiuiplldcr0 = 0x7c0f1bf0;
  131. } else if (clkdiv == 8) {
  132. gur->lbiuiplldcr0 = 0x6c0f1bf0;
  133. } else if (clkdiv == 4) {
  134. gur->lbiuiplldcr0 = 0x5c0f1bf0;
  135. }
  136. lbc->lcrr |= 0x00030000;
  137. asm("sync;isync;msync");
  138. }
  139. /*
  140. * Initialize SDRAM memory on the Local Bus.
  141. */
  142. void
  143. sdram_init(void)
  144. {
  145. #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
  146. uint idx;
  147. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  148. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  149. uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
  150. uint cpu_board_rev;
  151. uint lsdmr_common;
  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. asm("msync");
  159. lbc->br2 = CFG_BR2_PRELIM;
  160. asm("msync");
  161. lbc->lbcr = CFG_LBC_LBCR;
  162. asm("msync");
  163. lbc->lsrt = CFG_LBC_LSRT;
  164. lbc->mrtpr = CFG_LBC_MRTPR;
  165. asm("msync");
  166. /*
  167. * MPC8548 uses "new" 15-16 style addressing.
  168. */
  169. cpu_board_rev = get_cpu_board_revision();
  170. lsdmr_common = CFG_LBC_LSDMR_COMMON;
  171. lsdmr_common |= CFG_LBC_LSDMR_BSMA1516;
  172. /*
  173. * Issue PRECHARGE ALL command.
  174. */
  175. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL;
  176. asm("sync;msync");
  177. *sdram_addr = 0xff;
  178. ppcDcbf((unsigned long) sdram_addr);
  179. udelay(100);
  180. /*
  181. * Issue 8 AUTO REFRESH commands.
  182. */
  183. for (idx = 0; idx < 8; idx++) {
  184. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH;
  185. asm("sync;msync");
  186. *sdram_addr = 0xff;
  187. ppcDcbf((unsigned long) sdram_addr);
  188. udelay(100);
  189. }
  190. /*
  191. * Issue 8 MODE-set command.
  192. */
  193. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW;
  194. asm("sync;msync");
  195. *sdram_addr = 0xff;
  196. ppcDcbf((unsigned long) sdram_addr);
  197. udelay(100);
  198. /*
  199. * Issue NORMAL OP command.
  200. */
  201. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL;
  202. asm("sync;msync");
  203. *sdram_addr = 0xff;
  204. ppcDcbf((unsigned long) sdram_addr);
  205. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  206. #endif /* enable SDRAM init */
  207. }
  208. #if defined(CFG_DRAM_TEST)
  209. int
  210. testdram(void)
  211. {
  212. uint *pstart = (uint *) CFG_MEMTEST_START;
  213. uint *pend = (uint *) CFG_MEMTEST_END;
  214. uint *p;
  215. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  216. CFG_MEMTEST_START,
  217. CFG_MEMTEST_END);
  218. printf("DRAM test phase 1:\n");
  219. for (p = pstart; p < pend; p++)
  220. *p = 0xaaaaaaaa;
  221. for (p = pstart; p < pend; p++) {
  222. if (*p != 0xaaaaaaaa) {
  223. printf ("DRAM test fails at: %08x\n", (uint) p);
  224. return 1;
  225. }
  226. }
  227. printf("DRAM test phase 2:\n");
  228. for (p = pstart; p < pend; p++)
  229. *p = 0x55555555;
  230. for (p = pstart; p < pend; p++) {
  231. if (*p != 0x55555555) {
  232. printf ("DRAM test fails at: %08x\n", (uint) p);
  233. return 1;
  234. }
  235. }
  236. printf("DRAM test passed.\n");
  237. return 0;
  238. }
  239. #endif
  240. #if defined(CONFIG_PCI)
  241. /*
  242. * Initialize PCI Devices, report devices found.
  243. */
  244. #ifndef CONFIG_PCI_PNP
  245. static struct pci_config_table pci_mpc85xxcds_config_table[] = {
  246. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  247. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  248. pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
  249. PCI_ENET0_MEMADDR,
  250. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
  251. } },
  252. { }
  253. };
  254. #endif
  255. static struct pci_controller hose = {
  256. #ifndef CONFIG_PCI_PNP
  257. config_table: pci_mpc85xxcds_config_table,
  258. #endif
  259. };
  260. #endif /* CONFIG_PCI */
  261. void
  262. pci_init_board(void)
  263. {
  264. #ifdef CONFIG_PCI
  265. extern void pci_mpc85xx_init(struct pci_controller *hose);
  266. pci_mpc85xx_init(&hose);
  267. #endif
  268. }