mpc8548cds.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. /*
  2. * Copyright 2004, 2007 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/mmu.h>
  28. #include <asm/immap_85xx.h>
  29. #include <asm/immap_fsl_pci.h>
  30. #include <asm/fsl_ddr_sdram.h>
  31. #include <spd_sdram.h>
  32. #include <miiphy.h>
  33. #include <libfdt.h>
  34. #include <fdt_support.h>
  35. #include "../common/cadmus.h"
  36. #include "../common/eeprom.h"
  37. #include "../common/via.h"
  38. DECLARE_GLOBAL_DATA_PTR;
  39. void local_bus_init(void);
  40. void sdram_init(void);
  41. int checkboard (void)
  42. {
  43. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  44. volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
  45. /* PCI slot in USER bits CSR[6:7] by convention. */
  46. uint pci_slot = get_pci_slot ();
  47. uint cpu_board_rev = get_cpu_board_revision ();
  48. uint svr;
  49. printf ("Board: CDS Version 0x%02x, PCI Slot %d\n",
  50. get_board_version (), pci_slot);
  51. printf ("CPU Board Revision %d.%d (0x%04x)\n",
  52. MPC85XX_CPU_BOARD_MAJOR (cpu_board_rev),
  53. MPC85XX_CPU_BOARD_MINOR (cpu_board_rev), cpu_board_rev);
  54. /*
  55. * Initialize local bus.
  56. */
  57. local_bus_init ();
  58. svr = get_svr();
  59. /*
  60. * Fix CPU2 errata: A core hang possible while executing a
  61. * msync instruction and a snoopable transaction from an I/O
  62. * master tagged to make quick forward progress is present.
  63. * Fixed in Silicon Rev.2.1
  64. */
  65. if (!(SVR_MAJ(svr) >= 2 && SVR_MIN(svr) >= 1))
  66. ecm->eebpcr |= (1 << 16);
  67. /*
  68. * Hack TSEC 3 and 4 IO voltages.
  69. */
  70. gur->tsec34ioovcr = 0xe7e0; /* 1110 0111 1110 0xxx */
  71. ecm->eedr = 0xffffffff; /* clear ecm errors */
  72. ecm->eeer = 0xffffffff; /* enable ecm errors */
  73. return 0;
  74. }
  75. phys_size_t
  76. initdram(int board_type)
  77. {
  78. long dram_size = 0;
  79. puts("Initializing\n");
  80. #if defined(CONFIG_DDR_DLL)
  81. {
  82. /*
  83. * Work around to stabilize DDR DLL MSYNC_IN.
  84. * Errata DDR9 seems to have been fixed.
  85. * This is now the workaround for Errata DDR11:
  86. * Override DLL = 1, Course Adj = 1, Tap Select = 0
  87. */
  88. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  89. gur->ddrdllcr = 0x81000000;
  90. asm("sync;isync;msync");
  91. udelay(200);
  92. }
  93. #endif
  94. dram_size = fsl_ddr_sdram();
  95. dram_size = setup_ddr_tlbs(dram_size / 0x100000);
  96. dram_size *= 0x100000;
  97. /*
  98. * SDRAM Initialization
  99. */
  100. sdram_init();
  101. puts(" DDR: ");
  102. return dram_size;
  103. }
  104. /*
  105. * Initialize Local Bus
  106. */
  107. void
  108. local_bus_init(void)
  109. {
  110. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  111. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  112. uint clkdiv;
  113. uint lbc_hz;
  114. sys_info_t sysinfo;
  115. get_sys_info(&sysinfo);
  116. clkdiv = (lbc->lcrr & 0x0f) * 2;
  117. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  118. gur->lbiuiplldcr1 = 0x00078080;
  119. if (clkdiv == 16) {
  120. gur->lbiuiplldcr0 = 0x7c0f1bf0;
  121. } else if (clkdiv == 8) {
  122. gur->lbiuiplldcr0 = 0x6c0f1bf0;
  123. } else if (clkdiv == 4) {
  124. gur->lbiuiplldcr0 = 0x5c0f1bf0;
  125. }
  126. lbc->lcrr |= 0x00030000;
  127. asm("sync;isync;msync");
  128. lbc->ltesr = 0xffffffff; /* Clear LBC error interrupts */
  129. lbc->lteir = 0xffffffff; /* Enable LBC error interrupts */
  130. }
  131. /*
  132. * Initialize SDRAM memory on the Local Bus.
  133. */
  134. void
  135. sdram_init(void)
  136. {
  137. #if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM)
  138. uint idx;
  139. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  140. uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
  141. uint cpu_board_rev;
  142. uint lsdmr_common;
  143. puts(" SDRAM: ");
  144. print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  145. /*
  146. * Setup SDRAM Base and Option Registers
  147. */
  148. lbc->or2 = CONFIG_SYS_OR2_PRELIM;
  149. asm("msync");
  150. lbc->br2 = CONFIG_SYS_BR2_PRELIM;
  151. asm("msync");
  152. lbc->lbcr = CONFIG_SYS_LBC_LBCR;
  153. asm("msync");
  154. lbc->lsrt = CONFIG_SYS_LBC_LSRT;
  155. lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
  156. asm("msync");
  157. /*
  158. * MPC8548 uses "new" 15-16 style addressing.
  159. */
  160. cpu_board_rev = get_cpu_board_revision();
  161. lsdmr_common = CONFIG_SYS_LBC_LSDMR_COMMON;
  162. lsdmr_common |= CONFIG_SYS_LBC_LSDMR_BSMA1516;
  163. /*
  164. * Issue PRECHARGE ALL command.
  165. */
  166. lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_PCHALL;
  167. asm("sync;msync");
  168. *sdram_addr = 0xff;
  169. ppcDcbf((unsigned long) sdram_addr);
  170. udelay(100);
  171. /*
  172. * Issue 8 AUTO REFRESH commands.
  173. */
  174. for (idx = 0; idx < 8; idx++) {
  175. lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_ARFRSH;
  176. asm("sync;msync");
  177. *sdram_addr = 0xff;
  178. ppcDcbf((unsigned long) sdram_addr);
  179. udelay(100);
  180. }
  181. /*
  182. * Issue 8 MODE-set command.
  183. */
  184. lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_MRW;
  185. asm("sync;msync");
  186. *sdram_addr = 0xff;
  187. ppcDcbf((unsigned long) sdram_addr);
  188. udelay(100);
  189. /*
  190. * Issue NORMAL OP command.
  191. */
  192. lbc->lsdmr = lsdmr_common | CONFIG_SYS_LBC_LSDMR_OP_NORMAL;
  193. asm("sync;msync");
  194. *sdram_addr = 0xff;
  195. ppcDcbf((unsigned long) sdram_addr);
  196. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  197. #endif /* enable SDRAM init */
  198. }
  199. #if defined(CONFIG_PCI) || defined(CONFIG_PCI1)
  200. /* For some reason the Tundra PCI bridge shows up on itself as a
  201. * different device. Work around that by refusing to configure it.
  202. */
  203. void dummy_func(struct pci_controller* hose, pci_dev_t dev, struct pci_config_table *tab) { }
  204. static struct pci_config_table pci_mpc85xxcds_config_table[] = {
  205. {0x10e3, 0x0513, PCI_ANY_ID, 1, 3, PCI_ANY_ID, dummy_func, {0,0,0}},
  206. {0x1106, 0x0686, PCI_ANY_ID, 1, VIA_ID, 0, mpc85xx_config_via, {0,0,0}},
  207. {0x1106, 0x0571, PCI_ANY_ID, 1, VIA_ID, 1,
  208. mpc85xx_config_via_usbide, {0,0,0}},
  209. {0x1105, 0x3038, PCI_ANY_ID, 1, VIA_ID, 2,
  210. mpc85xx_config_via_usb, {0,0,0}},
  211. {0x1106, 0x3038, PCI_ANY_ID, 1, VIA_ID, 3,
  212. mpc85xx_config_via_usb2, {0,0,0}},
  213. {0x1106, 0x3058, PCI_ANY_ID, 1, VIA_ID, 5,
  214. mpc85xx_config_via_power, {0,0,0}},
  215. {0x1106, 0x3068, PCI_ANY_ID, 1, VIA_ID, 6,
  216. mpc85xx_config_via_ac97, {0,0,0}},
  217. {},
  218. };
  219. static struct pci_controller pci1_hose = {
  220. config_table: pci_mpc85xxcds_config_table};
  221. #endif /* CONFIG_PCI */
  222. #ifdef CONFIG_PCI2
  223. static struct pci_controller pci2_hose;
  224. #endif /* CONFIG_PCI2 */
  225. #ifdef CONFIG_PCIE1
  226. static struct pci_controller pcie1_hose;
  227. #endif /* CONFIG_PCIE1 */
  228. extern int fsl_pci_setup_inbound_windows(struct pci_region *r);
  229. extern void fsl_pci_init(struct pci_controller *hose);
  230. int first_free_busno=0;
  231. void
  232. pci_init_board(void)
  233. {
  234. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  235. uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  236. uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  237. #ifdef CONFIG_PCI1
  238. {
  239. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI1_ADDR;
  240. struct pci_controller *hose = &pci1_hose;
  241. struct pci_config_table *table;
  242. struct pci_region *r = hose->regions;
  243. uint pci_32 = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32; /* PORDEVSR[15] */
  244. uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB; /* PORDEVSR[14] */
  245. uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD; /* PORPLLSR[16] */
  246. uint pci_agent = (host_agent == 3) || (host_agent == 4 ) || (host_agent == 6);
  247. uint pci_speed = get_clock_freq (); /* PCI PSPEED in [4:5] */
  248. if (!(gur->devdisr & MPC85xx_DEVDISR_PCI1)) {
  249. printf (" PCI: %d bit, %s MHz, %s, %s, %s\n",
  250. (pci_32) ? 32 : 64,
  251. (pci_speed == 33333000) ? "33" :
  252. (pci_speed == 66666000) ? "66" : "unknown",
  253. pci_clk_sel ? "sync" : "async",
  254. pci_agent ? "agent" : "host",
  255. pci_arb ? "arbiter" : "external-arbiter"
  256. );
  257. /* inbound */
  258. r += fsl_pci_setup_inbound_windows(r);
  259. /* outbound memory */
  260. pci_set_region(r++,
  261. CONFIG_SYS_PCI1_MEM_BASE,
  262. CONFIG_SYS_PCI1_MEM_PHYS,
  263. CONFIG_SYS_PCI1_MEM_SIZE,
  264. PCI_REGION_MEM);
  265. /* outbound io */
  266. pci_set_region(r++,
  267. CONFIG_SYS_PCI1_IO_BASE,
  268. CONFIG_SYS_PCI1_IO_PHYS,
  269. CONFIG_SYS_PCI1_IO_SIZE,
  270. PCI_REGION_IO);
  271. hose->region_count = r - hose->regions;
  272. /* relocate config table pointers */
  273. hose->config_table = \
  274. (struct pci_config_table *)((uint)hose->config_table + gd->reloc_off);
  275. for (table = hose->config_table; table && table->vendor; table++)
  276. table->config_device += gd->reloc_off;
  277. hose->first_busno=first_free_busno;
  278. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  279. fsl_pci_init(hose);
  280. first_free_busno=hose->last_busno+1;
  281. printf ("PCI on bus %02x - %02x\n",hose->first_busno,hose->last_busno);
  282. #ifdef CONFIG_PCIX_CHECK
  283. if (!(gur->pordevsr & PORDEVSR_PCI)) {
  284. /* PCI-X init */
  285. if (CONFIG_SYS_CLK_FREQ < 66000000)
  286. printf("PCI-X will only work at 66 MHz\n");
  287. reg16 = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
  288. | PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
  289. pci_hose_write_config_word(hose, bus, PCIX_COMMAND, reg16);
  290. }
  291. #endif
  292. } else {
  293. printf (" PCI: disabled\n");
  294. }
  295. }
  296. #else
  297. gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
  298. #endif
  299. #ifdef CONFIG_PCI2
  300. {
  301. uint pci2_clk_sel = gur->porpllsr & 0x4000; /* PORPLLSR[17] */
  302. uint pci_dual = get_pci_dual (); /* PCI DUAL in CM_PCI[3] */
  303. if (pci_dual) {
  304. printf (" PCI2: 32 bit, 66 MHz, %s\n",
  305. pci2_clk_sel ? "sync" : "async");
  306. } else {
  307. printf (" PCI2: disabled\n");
  308. }
  309. }
  310. #else
  311. gur->devdisr |= MPC85xx_DEVDISR_PCI2; /* disable */
  312. #endif /* CONFIG_PCI2 */
  313. #ifdef CONFIG_PCIE1
  314. {
  315. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
  316. struct pci_controller *hose = &pcie1_hose;
  317. int pcie_ep = (host_agent == 0) || (host_agent == 2 ) || (host_agent == 3);
  318. struct pci_region *r = hose->regions;
  319. int pcie_configured = io_sel >= 1;
  320. if (pcie_configured && !(gur->devdisr & MPC85xx_DEVDISR_PCIE)){
  321. printf ("\n PCIE connected to slot as %s (base address %x)",
  322. pcie_ep ? "End Point" : "Root Complex",
  323. (uint)pci);
  324. if (pci->pme_msg_det) {
  325. pci->pme_msg_det = 0xffffffff;
  326. debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
  327. }
  328. printf ("\n");
  329. /* inbound */
  330. r += fsl_pci_setup_inbound_windows(r);
  331. /* outbound memory */
  332. pci_set_region(r++,
  333. CONFIG_SYS_PCIE1_MEM_BASE,
  334. CONFIG_SYS_PCIE1_MEM_PHYS,
  335. CONFIG_SYS_PCIE1_MEM_SIZE,
  336. PCI_REGION_MEM);
  337. /* outbound io */
  338. pci_set_region(r++,
  339. CONFIG_SYS_PCIE1_IO_BASE,
  340. CONFIG_SYS_PCIE1_IO_PHYS,
  341. CONFIG_SYS_PCIE1_IO_SIZE,
  342. PCI_REGION_IO);
  343. hose->region_count = r - hose->regions;
  344. hose->first_busno=first_free_busno;
  345. pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
  346. fsl_pci_init(hose);
  347. printf ("PCIE on bus %d - %d\n",hose->first_busno,hose->last_busno);
  348. first_free_busno=hose->last_busno+1;
  349. } else {
  350. printf (" PCIE: disabled\n");
  351. }
  352. }
  353. #else
  354. gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
  355. #endif
  356. }
  357. int last_stage_init(void)
  358. {
  359. unsigned short temp;
  360. /* Change the resistors for the PHY */
  361. /* This is needed to get the RGMII working for the 1.3+
  362. * CDS cards */
  363. if (get_board_version() == 0x13) {
  364. miiphy_write(CONFIG_TSEC1_NAME,
  365. TSEC1_PHY_ADDR, 29, 18);
  366. miiphy_read(CONFIG_TSEC1_NAME,
  367. TSEC1_PHY_ADDR, 30, &temp);
  368. temp = (temp & 0xf03f);
  369. temp |= 2 << 9; /* 36 ohm */
  370. temp |= 2 << 6; /* 39 ohm */
  371. miiphy_write(CONFIG_TSEC1_NAME,
  372. TSEC1_PHY_ADDR, 30, temp);
  373. miiphy_write(CONFIG_TSEC1_NAME,
  374. TSEC1_PHY_ADDR, 29, 3);
  375. miiphy_write(CONFIG_TSEC1_NAME,
  376. TSEC1_PHY_ADDR, 30, 0x8000);
  377. }
  378. return 0;
  379. }
  380. #if defined(CONFIG_OF_BOARD_SETUP)
  381. extern void ft_fsl_pci_setup(void *blob, const char *pci_alias,
  382. struct pci_controller *hose);
  383. void ft_pci_setup(void *blob, bd_t *bd)
  384. {
  385. #ifdef CONFIG_PCI1
  386. ft_fsl_pci_setup(blob, "pci0", &pci1_hose);
  387. #endif
  388. #ifdef CONFIG_PCIE1
  389. ft_fsl_pci_setup(blob, "pci1", &pcie1_hose);
  390. #endif
  391. }
  392. #endif