mpc8548cds.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /*
  2. * Copyright 2004, 2007, 2009-2010 Freescale Semiconductor, Inc.
  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/fsl_pci.h>
  30. #include <asm/fsl_ddr_sdram.h>
  31. #include <asm/fsl_serdes.h>
  32. #include <spd_sdram.h>
  33. #include <miiphy.h>
  34. #include <libfdt.h>
  35. #include <fdt_support.h>
  36. #include "../common/cadmus.h"
  37. #include "../common/eeprom.h"
  38. #include "../common/via.h"
  39. DECLARE_GLOBAL_DATA_PTR;
  40. void local_bus_init(void);
  41. void sdram_init(void);
  42. int checkboard (void)
  43. {
  44. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  45. volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
  46. /* PCI slot in USER bits CSR[6:7] by convention. */
  47. uint pci_slot = get_pci_slot ();
  48. uint cpu_board_rev = get_cpu_board_revision ();
  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. /*
  59. * Hack TSEC 3 and 4 IO voltages.
  60. */
  61. gur->tsec34ioovcr = 0xe7e0; /* 1110 0111 1110 0xxx */
  62. ecm->eedr = 0xffffffff; /* clear ecm errors */
  63. ecm->eeer = 0xffffffff; /* enable ecm errors */
  64. return 0;
  65. }
  66. phys_size_t
  67. initdram(int board_type)
  68. {
  69. long dram_size = 0;
  70. puts("Initializing\n");
  71. #if defined(CONFIG_DDR_DLL)
  72. {
  73. /*
  74. * Work around to stabilize DDR DLL MSYNC_IN.
  75. * Errata DDR9 seems to have been fixed.
  76. * This is now the workaround for Errata DDR11:
  77. * Override DLL = 1, Course Adj = 1, Tap Select = 0
  78. */
  79. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  80. gur->ddrdllcr = 0x81000000;
  81. asm("sync;isync;msync");
  82. udelay(200);
  83. }
  84. #endif
  85. dram_size = fsl_ddr_sdram();
  86. dram_size = setup_ddr_tlbs(dram_size / 0x100000);
  87. dram_size *= 0x100000;
  88. /*
  89. * SDRAM Initialization
  90. */
  91. sdram_init();
  92. puts(" DDR: ");
  93. return dram_size;
  94. }
  95. /*
  96. * Initialize Local Bus
  97. */
  98. void
  99. local_bus_init(void)
  100. {
  101. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  102. volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
  103. uint clkdiv;
  104. uint lbc_hz;
  105. sys_info_t sysinfo;
  106. get_sys_info(&sysinfo);
  107. clkdiv = (lbc->lcrr & LCRR_CLKDIV) * 2;
  108. lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
  109. gur->lbiuiplldcr1 = 0x00078080;
  110. if (clkdiv == 16) {
  111. gur->lbiuiplldcr0 = 0x7c0f1bf0;
  112. } else if (clkdiv == 8) {
  113. gur->lbiuiplldcr0 = 0x6c0f1bf0;
  114. } else if (clkdiv == 4) {
  115. gur->lbiuiplldcr0 = 0x5c0f1bf0;
  116. }
  117. lbc->lcrr |= 0x00030000;
  118. asm("sync;isync;msync");
  119. lbc->ltesr = 0xffffffff; /* Clear LBC error interrupts */
  120. lbc->lteir = 0xffffffff; /* Enable LBC error interrupts */
  121. }
  122. /*
  123. * Initialize SDRAM memory on the Local Bus.
  124. */
  125. void
  126. sdram_init(void)
  127. {
  128. #if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM)
  129. uint idx;
  130. volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
  131. uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
  132. uint cpu_board_rev;
  133. uint lsdmr_common;
  134. puts(" SDRAM: ");
  135. print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  136. /*
  137. * Setup SDRAM Base and Option Registers
  138. */
  139. set_lbc_or(2, CONFIG_SYS_OR2_PRELIM);
  140. set_lbc_br(2, CONFIG_SYS_BR2_PRELIM);
  141. lbc->lbcr = CONFIG_SYS_LBC_LBCR;
  142. asm("msync");
  143. lbc->lsrt = CONFIG_SYS_LBC_LSRT;
  144. lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
  145. asm("msync");
  146. /*
  147. * MPC8548 uses "new" 15-16 style addressing.
  148. */
  149. cpu_board_rev = get_cpu_board_revision();
  150. lsdmr_common = CONFIG_SYS_LBC_LSDMR_COMMON;
  151. lsdmr_common |= LSDMR_BSMA1516;
  152. /*
  153. * Issue PRECHARGE ALL command.
  154. */
  155. lbc->lsdmr = lsdmr_common | LSDMR_OP_PCHALL;
  156. asm("sync;msync");
  157. *sdram_addr = 0xff;
  158. ppcDcbf((unsigned long) sdram_addr);
  159. udelay(100);
  160. /*
  161. * Issue 8 AUTO REFRESH commands.
  162. */
  163. for (idx = 0; idx < 8; idx++) {
  164. lbc->lsdmr = lsdmr_common | LSDMR_OP_ARFRSH;
  165. asm("sync;msync");
  166. *sdram_addr = 0xff;
  167. ppcDcbf((unsigned long) sdram_addr);
  168. udelay(100);
  169. }
  170. /*
  171. * Issue 8 MODE-set command.
  172. */
  173. lbc->lsdmr = lsdmr_common | LSDMR_OP_MRW;
  174. asm("sync;msync");
  175. *sdram_addr = 0xff;
  176. ppcDcbf((unsigned long) sdram_addr);
  177. udelay(100);
  178. /*
  179. * Issue NORMAL OP command.
  180. */
  181. lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
  182. asm("sync;msync");
  183. *sdram_addr = 0xff;
  184. ppcDcbf((unsigned long) sdram_addr);
  185. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  186. #endif /* enable SDRAM init */
  187. }
  188. #if defined(CONFIG_PCI) || defined(CONFIG_PCI1)
  189. /* For some reason the Tundra PCI bridge shows up on itself as a
  190. * different device. Work around that by refusing to configure it.
  191. */
  192. void dummy_func(struct pci_controller* hose, pci_dev_t dev, struct pci_config_table *tab) { }
  193. static struct pci_config_table pci_mpc85xxcds_config_table[] = {
  194. {0x10e3, 0x0513, PCI_ANY_ID, 1, 3, PCI_ANY_ID, dummy_func, {0,0,0}},
  195. {0x1106, 0x0686, PCI_ANY_ID, 1, VIA_ID, 0, mpc85xx_config_via, {0,0,0}},
  196. {0x1106, 0x0571, PCI_ANY_ID, 1, VIA_ID, 1,
  197. mpc85xx_config_via_usbide, {0,0,0}},
  198. {0x1105, 0x3038, PCI_ANY_ID, 1, VIA_ID, 2,
  199. mpc85xx_config_via_usb, {0,0,0}},
  200. {0x1106, 0x3038, PCI_ANY_ID, 1, VIA_ID, 3,
  201. mpc85xx_config_via_usb2, {0,0,0}},
  202. {0x1106, 0x3058, PCI_ANY_ID, 1, VIA_ID, 5,
  203. mpc85xx_config_via_power, {0,0,0}},
  204. {0x1106, 0x3068, PCI_ANY_ID, 1, VIA_ID, 6,
  205. mpc85xx_config_via_ac97, {0,0,0}},
  206. {},
  207. };
  208. static struct pci_controller pci1_hose = {
  209. config_table: pci_mpc85xxcds_config_table};
  210. #endif /* CONFIG_PCI */
  211. #ifdef CONFIG_PCI2
  212. static struct pci_controller pci2_hose;
  213. #endif /* CONFIG_PCI2 */
  214. #ifdef CONFIG_PCIE1
  215. static struct pci_controller pcie1_hose;
  216. #endif /* CONFIG_PCIE1 */
  217. void pci_init_board(void)
  218. {
  219. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  220. struct fsl_pci_info pci_info[4];
  221. u32 devdisr, pordevsr, io_sel;
  222. u32 porpllsr, pci_agent, pci_speed, pci_32, pci_arb, pci_clk_sel;
  223. int first_free_busno = 0;
  224. int num = 0;
  225. int pcie_ep, pcie_configured;
  226. devdisr = in_be32(&gur->devdisr);
  227. pordevsr = in_be32(&gur->pordevsr);
  228. porpllsr = in_be32(&gur->porpllsr);
  229. io_sel = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  230. debug (" pci_init_board: devdisr=%x, io_sel=%x\n", devdisr, io_sel);
  231. #ifdef CONFIG_PCI1
  232. pci_speed = get_clock_freq (); /* PCI PSPEED in [4:5] */
  233. pci_32 = pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32; /* PORDEVSR[15] */
  234. pci_arb = pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;
  235. pci_clk_sel = porpllsr & MPC85xx_PORDEVSR_PCI1_SPD;
  236. if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
  237. SET_STD_PCI_INFO(pci_info[num], 1);
  238. pci_agent = fsl_setup_hose(&pci1_hose, pci_info[num].regs);
  239. printf("PCI: %d bit, %s MHz, %s, %s, %s (base address %lx)\n",
  240. (pci_32) ? 32 : 64,
  241. (pci_speed == 33333000) ? "33" :
  242. (pci_speed == 66666000) ? "66" : "unknown",
  243. pci_clk_sel ? "sync" : "async",
  244. pci_agent ? "agent" : "host",
  245. pci_arb ? "arbiter" : "external-arbiter",
  246. pci_info[num].regs);
  247. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  248. &pci1_hose, first_free_busno);
  249. #ifdef CONFIG_PCIX_CHECK
  250. if (!(pordevsr & MPC85xx_PORDEVSR_PCI1)) {
  251. /* PCI-X init */
  252. if (CONFIG_SYS_CLK_FREQ < 66000000)
  253. printf("PCI-X will only work at 66 MHz\n");
  254. reg16 = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
  255. | PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
  256. pci_hose_write_config_word(hose, bus, PCIX_COMMAND, reg16);
  257. }
  258. #endif
  259. } else {
  260. printf("PCI: disabled\n");
  261. }
  262. puts("\n");
  263. #else
  264. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI1); /* disable */
  265. #endif
  266. #ifdef CONFIG_PCI2
  267. {
  268. uint pci2_clk_sel = porpllsr & 0x4000; /* PORPLLSR[17] */
  269. uint pci_dual = get_pci_dual (); /* PCI DUAL in CM_PCI[3] */
  270. if (pci_dual) {
  271. printf("PCI2: 32 bit, 66 MHz, %s\n",
  272. pci2_clk_sel ? "sync" : "async");
  273. } else {
  274. printf("PCI2: disabled\n");
  275. }
  276. }
  277. #else
  278. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI2); /* disable */
  279. #endif /* CONFIG_PCI2 */
  280. #ifdef CONFIG_PCIE1
  281. pcie_configured = is_serdes_configured(PCIE1);
  282. if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
  283. SET_STD_PCIE_INFO(pci_info[num], 1);
  284. pcie_ep = fsl_setup_hose(&pcie1_hose, pci_info[num].regs);
  285. printf("PCIE1: connected to Slot as %s (base addr %lx)\n",
  286. pcie_ep ? "Endpoint" : "Root Complex",
  287. pci_info[num].regs);
  288. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  289. &pcie1_hose, first_free_busno);
  290. } else {
  291. printf("PCIE1: disabled\n");
  292. }
  293. puts("\n");
  294. #else
  295. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE); /* disable */
  296. #endif
  297. }
  298. int last_stage_init(void)
  299. {
  300. unsigned short temp;
  301. /* Change the resistors for the PHY */
  302. /* This is needed to get the RGMII working for the 1.3+
  303. * CDS cards */
  304. if (get_board_version() == 0x13) {
  305. miiphy_write(CONFIG_TSEC1_NAME,
  306. TSEC1_PHY_ADDR, 29, 18);
  307. miiphy_read(CONFIG_TSEC1_NAME,
  308. TSEC1_PHY_ADDR, 30, &temp);
  309. temp = (temp & 0xf03f);
  310. temp |= 2 << 9; /* 36 ohm */
  311. temp |= 2 << 6; /* 39 ohm */
  312. miiphy_write(CONFIG_TSEC1_NAME,
  313. TSEC1_PHY_ADDR, 30, temp);
  314. miiphy_write(CONFIG_TSEC1_NAME,
  315. TSEC1_PHY_ADDR, 29, 3);
  316. miiphy_write(CONFIG_TSEC1_NAME,
  317. TSEC1_PHY_ADDR, 30, 0x8000);
  318. }
  319. return 0;
  320. }
  321. #if defined(CONFIG_OF_BOARD_SETUP)
  322. void ft_pci_setup(void *blob, bd_t *bd)
  323. {
  324. FT_FSL_PCI_SETUP;
  325. }
  326. #endif