mpc8548cds.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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. #include "../common/via.h"
  32. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  33. extern void ddr_enable_ecc(unsigned int dram_size);
  34. #endif
  35. extern long int spd_sdram(void);
  36. void local_bus_init(void);
  37. void sdram_init(void);
  38. int board_early_init_f (void)
  39. {
  40. return 0;
  41. }
  42. int checkboard (void)
  43. {
  44. volatile immap_t *immap = (immap_t *) CFG_CCSRBAR;
  45. volatile ccsr_gur_t *gur = &immap->im_gur;
  46. /* PCI slot in USER bits CSR[6:7] by convention. */
  47. uint pci_slot = get_pci_slot ();
  48. uint pci_dual = get_pci_dual (); /* PCI DUAL in CM_PCI[3] */
  49. uint pci1_32 = gur->pordevsr & 0x10000; /* PORDEVSR[15] */
  50. uint pci1_clk_sel = gur->porpllsr & 0x8000; /* PORPLLSR[16] */
  51. uint pci2_clk_sel = gur->porpllsr & 0x4000; /* PORPLLSR[17] */
  52. uint pci1_speed = get_clock_freq (); /* PCI PSPEED in [4:5] */
  53. uint cpu_board_rev = get_cpu_board_revision ();
  54. printf ("Board: CDS Version 0x%02x, PCI Slot %d\n",
  55. get_board_version (), 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), cpu_board_rev);
  59. printf (" PCI1: %d bit, %s MHz, %s\n",
  60. (pci1_32) ? 32 : 64,
  61. (pci1_speed == 33000000) ? "33" :
  62. (pci1_speed == 66000000) ? "66" : "unknown",
  63. pci1_clk_sel ? "sync" : "async");
  64. if (pci_dual) {
  65. printf (" PCI2: 32 bit, 66 MHz, %s\n",
  66. pci2_clk_sel ? "sync" : "async");
  67. } else {
  68. printf (" PCI2: disabled\n");
  69. }
  70. /*
  71. * Initialize local bus.
  72. */
  73. local_bus_init ();
  74. /*
  75. * Hack TSEC 3 and 4 IO voltages.
  76. */
  77. gur->tsec34ioovcr = 0xe7e0; /* 1110 0111 1110 0xxx */
  78. return 0;
  79. }
  80. long int
  81. initdram(int board_type)
  82. {
  83. long dram_size = 0;
  84. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  85. puts("Initializing\n");
  86. #if defined(CONFIG_DDR_DLL)
  87. {
  88. /*
  89. * Work around to stabilize DDR DLL MSYNC_IN.
  90. * Errata DDR9 seems to have been fixed.
  91. * This is now the workaround for Errata DDR11:
  92. * Override DLL = 1, Course Adj = 1, Tap Select = 0
  93. */
  94. volatile ccsr_gur_t *gur= &immap->im_gur;
  95. gur->ddrdllcr = 0x81000000;
  96. asm("sync;isync;msync");
  97. udelay(200);
  98. }
  99. #endif
  100. dram_size = spd_sdram();
  101. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  102. /*
  103. * Initialize and enable DDR ECC.
  104. */
  105. ddr_enable_ecc(dram_size);
  106. #endif
  107. /*
  108. * SDRAM Initialization
  109. */
  110. sdram_init();
  111. puts(" DDR: ");
  112. return dram_size;
  113. }
  114. /*
  115. * Initialize Local Bus
  116. */
  117. void
  118. local_bus_init(void)
  119. {
  120. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  121. volatile ccsr_gur_t *gur = &immap->im_gur;
  122. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  123. uint clkdiv;
  124. uint lbc_hz;
  125. sys_info_t sysinfo;
  126. get_sys_info(&sysinfo);
  127. clkdiv = (lbc->lcrr & 0x0f) * 2;
  128. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  129. gur->lbiuiplldcr1 = 0x00078080;
  130. if (clkdiv == 16) {
  131. gur->lbiuiplldcr0 = 0x7c0f1bf0;
  132. } else if (clkdiv == 8) {
  133. gur->lbiuiplldcr0 = 0x6c0f1bf0;
  134. } else if (clkdiv == 4) {
  135. gur->lbiuiplldcr0 = 0x5c0f1bf0;
  136. }
  137. lbc->lcrr |= 0x00030000;
  138. asm("sync;isync;msync");
  139. }
  140. /*
  141. * Initialize SDRAM memory on the Local Bus.
  142. */
  143. void
  144. sdram_init(void)
  145. {
  146. #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
  147. uint idx;
  148. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  149. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  150. uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
  151. uint cpu_board_rev;
  152. uint lsdmr_common;
  153. puts(" SDRAM: ");
  154. print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  155. /*
  156. * Setup SDRAM Base and Option Registers
  157. */
  158. lbc->or2 = CFG_OR2_PRELIM;
  159. asm("msync");
  160. lbc->br2 = CFG_BR2_PRELIM;
  161. asm("msync");
  162. lbc->lbcr = CFG_LBC_LBCR;
  163. asm("msync");
  164. lbc->lsrt = CFG_LBC_LSRT;
  165. lbc->mrtpr = CFG_LBC_MRTPR;
  166. asm("msync");
  167. /*
  168. * MPC8548 uses "new" 15-16 style addressing.
  169. */
  170. cpu_board_rev = get_cpu_board_revision();
  171. lsdmr_common = CFG_LBC_LSDMR_COMMON;
  172. lsdmr_common |= CFG_LBC_LSDMR_BSMA1516;
  173. /*
  174. * Issue PRECHARGE ALL command.
  175. */
  176. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL;
  177. asm("sync;msync");
  178. *sdram_addr = 0xff;
  179. ppcDcbf((unsigned long) sdram_addr);
  180. udelay(100);
  181. /*
  182. * Issue 8 AUTO REFRESH commands.
  183. */
  184. for (idx = 0; idx < 8; idx++) {
  185. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH;
  186. asm("sync;msync");
  187. *sdram_addr = 0xff;
  188. ppcDcbf((unsigned long) sdram_addr);
  189. udelay(100);
  190. }
  191. /*
  192. * Issue 8 MODE-set command.
  193. */
  194. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW;
  195. asm("sync;msync");
  196. *sdram_addr = 0xff;
  197. ppcDcbf((unsigned long) sdram_addr);
  198. udelay(100);
  199. /*
  200. * Issue NORMAL OP command.
  201. */
  202. lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL;
  203. asm("sync;msync");
  204. *sdram_addr = 0xff;
  205. ppcDcbf((unsigned long) sdram_addr);
  206. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  207. #endif /* enable SDRAM init */
  208. }
  209. #if defined(CFG_DRAM_TEST)
  210. int
  211. testdram(void)
  212. {
  213. uint *pstart = (uint *) CFG_MEMTEST_START;
  214. uint *pend = (uint *) CFG_MEMTEST_END;
  215. uint *p;
  216. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  217. CFG_MEMTEST_START,
  218. CFG_MEMTEST_END);
  219. printf("DRAM test phase 1:\n");
  220. for (p = pstart; p < pend; p++)
  221. *p = 0xaaaaaaaa;
  222. for (p = pstart; p < pend; p++) {
  223. if (*p != 0xaaaaaaaa) {
  224. printf ("DRAM test fails at: %08x\n", (uint) p);
  225. return 1;
  226. }
  227. }
  228. printf("DRAM test phase 2:\n");
  229. for (p = pstart; p < pend; p++)
  230. *p = 0x55555555;
  231. for (p = pstart; p < pend; p++) {
  232. if (*p != 0x55555555) {
  233. printf ("DRAM test fails at: %08x\n", (uint) p);
  234. return 1;
  235. }
  236. }
  237. printf("DRAM test passed.\n");
  238. return 0;
  239. }
  240. #endif
  241. #if defined(CONFIG_PCI)
  242. /* For some reason the Tundra PCI bridge shows up on itself as a
  243. * different device. Work around that by refusing to configure it.
  244. */
  245. void dummy_func(struct pci_controller* hose, pci_dev_t dev, struct pci_config_table *tab) { }
  246. static struct pci_config_table pci_mpc85xxcds_config_table[] = {
  247. {0x10e3, 0x0513, PCI_ANY_ID, 1, 3, PCI_ANY_ID, dummy_func, {0,0,0}},
  248. {0x1106, 0x0686, PCI_ANY_ID, 1, 2, 0, mpc85xx_config_via, {0,0,0}},
  249. {0x1106, 0x0571, PCI_ANY_ID, 1, 2, 1, mpc85xx_config_via_usbide, {0,0,0}},
  250. {0x1105, 0x3038, PCI_ANY_ID, 1, 2, 2, mpc85xx_config_via_usb, {0,0,0}},
  251. {0x1106, 0x3038, PCI_ANY_ID, 1, 2, 3, mpc85xx_config_via_usb2, {0,0,0}},
  252. {0x1106, 0x3058, PCI_ANY_ID, 1, 2, 5, mpc85xx_config_via_power, {0,0,0}},
  253. {0x1106, 0x3068, PCI_ANY_ID, 1, 2, 6, mpc85xx_config_via_ac97, {0,0,0}}
  254. };
  255. static struct pci_controller hose[] = {
  256. { config_table: pci_mpc85xxcds_config_table,},
  257. #ifdef CONFIG_MPC85XX_PCI2
  258. {},
  259. #endif
  260. };
  261. #endif /* CONFIG_PCI */
  262. void
  263. pci_init_board(void)
  264. {
  265. #ifdef CONFIG_PCI
  266. pci_mpc85xx_init(&hose);
  267. #endif
  268. }