mpc8548cds.c 10.0 KB

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