mpc8548cds.c 8.4 KB

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