mpc8548cds.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. /*
  2. * Copyright 2004, 2007, 2009-2011 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 <miiphy.h>
  33. #include <libfdt.h>
  34. #include <fdt_support.h>
  35. #include <tsec.h>
  36. #include <fsl_mdio.h>
  37. #include <netdev.h>
  38. #include "../common/cadmus.h"
  39. #include "../common/eeprom.h"
  40. #include "../common/via.h"
  41. void local_bus_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. puts("Board: MPC8548CDS");
  50. printf(" Carrier Rev: 0x%02x, PCI Slot %d\n",
  51. get_board_version(), pci_slot);
  52. printf(" Daughtercard Rev: %d.%d (0x%04x)\n",
  53. MPC85XX_CPU_BOARD_MAJOR (cpu_board_rev),
  54. MPC85XX_CPU_BOARD_MINOR (cpu_board_rev), cpu_board_rev);
  55. /*
  56. * Initialize local bus.
  57. */
  58. local_bus_init ();
  59. /*
  60. * Hack TSEC 3 and 4 IO voltages.
  61. */
  62. gur->tsec34ioovcr = 0xe7e0; /* 1110 0111 1110 0xxx */
  63. ecm->eedr = 0xffffffff; /* clear ecm errors */
  64. ecm->eeer = 0xffffffff; /* enable ecm errors */
  65. return 0;
  66. }
  67. /*
  68. * Initialize Local Bus
  69. */
  70. void
  71. local_bus_init(void)
  72. {
  73. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  74. volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
  75. uint clkdiv;
  76. sys_info_t sysinfo;
  77. get_sys_info(&sysinfo);
  78. clkdiv = (lbc->lcrr & LCRR_CLKDIV) * 2;
  79. gur->lbiuiplldcr1 = 0x00078080;
  80. if (clkdiv == 16) {
  81. gur->lbiuiplldcr0 = 0x7c0f1bf0;
  82. } else if (clkdiv == 8) {
  83. gur->lbiuiplldcr0 = 0x6c0f1bf0;
  84. } else if (clkdiv == 4) {
  85. gur->lbiuiplldcr0 = 0x5c0f1bf0;
  86. }
  87. lbc->lcrr |= 0x00030000;
  88. asm("sync;isync;msync");
  89. lbc->ltesr = 0xffffffff; /* Clear LBC error interrupts */
  90. lbc->lteir = 0xffffffff; /* Enable LBC error interrupts */
  91. }
  92. /*
  93. * Initialize SDRAM memory on the Local Bus.
  94. */
  95. void lbc_sdram_init(void)
  96. {
  97. #if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM)
  98. uint idx;
  99. volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
  100. uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
  101. uint lsdmr_common;
  102. puts("LBC SDRAM: ");
  103. print_size(CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024,
  104. "\n");
  105. /*
  106. * Setup SDRAM Base and Option Registers
  107. */
  108. set_lbc_or(2, CONFIG_SYS_OR2_PRELIM);
  109. set_lbc_br(2, CONFIG_SYS_BR2_PRELIM);
  110. lbc->lbcr = CONFIG_SYS_LBC_LBCR;
  111. asm("msync");
  112. lbc->lsrt = CONFIG_SYS_LBC_LSRT;
  113. lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
  114. asm("msync");
  115. /*
  116. * MPC8548 uses "new" 15-16 style addressing.
  117. */
  118. lsdmr_common = CONFIG_SYS_LBC_LSDMR_COMMON;
  119. lsdmr_common |= LSDMR_BSMA1516;
  120. /*
  121. * Issue PRECHARGE ALL command.
  122. */
  123. lbc->lsdmr = lsdmr_common | LSDMR_OP_PCHALL;
  124. asm("sync;msync");
  125. *sdram_addr = 0xff;
  126. ppcDcbf((unsigned long) sdram_addr);
  127. udelay(100);
  128. /*
  129. * Issue 8 AUTO REFRESH commands.
  130. */
  131. for (idx = 0; idx < 8; idx++) {
  132. lbc->lsdmr = lsdmr_common | LSDMR_OP_ARFRSH;
  133. asm("sync;msync");
  134. *sdram_addr = 0xff;
  135. ppcDcbf((unsigned long) sdram_addr);
  136. udelay(100);
  137. }
  138. /*
  139. * Issue 8 MODE-set command.
  140. */
  141. lbc->lsdmr = lsdmr_common | LSDMR_OP_MRW;
  142. asm("sync;msync");
  143. *sdram_addr = 0xff;
  144. ppcDcbf((unsigned long) sdram_addr);
  145. udelay(100);
  146. /*
  147. * Issue NORMAL OP command.
  148. */
  149. lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
  150. asm("sync;msync");
  151. *sdram_addr = 0xff;
  152. ppcDcbf((unsigned long) sdram_addr);
  153. udelay(200); /* Overkill. Must wait > 200 bus cycles */
  154. #endif /* enable SDRAM init */
  155. }
  156. #if defined(CONFIG_PCI) || defined(CONFIG_PCI1)
  157. /* For some reason the Tundra PCI bridge shows up on itself as a
  158. * different device. Work around that by refusing to configure it.
  159. */
  160. void dummy_func(struct pci_controller* hose, pci_dev_t dev, struct pci_config_table *tab) { }
  161. static struct pci_config_table pci_mpc85xxcds_config_table[] = {
  162. {0x10e3, 0x0513, PCI_ANY_ID, 1, 3, PCI_ANY_ID, dummy_func, {0,0,0}},
  163. {0x1106, 0x0686, PCI_ANY_ID, 1, VIA_ID, 0, mpc85xx_config_via, {0,0,0}},
  164. {0x1106, 0x0571, PCI_ANY_ID, 1, VIA_ID, 1,
  165. mpc85xx_config_via_usbide, {0,0,0}},
  166. {0x1105, 0x3038, PCI_ANY_ID, 1, VIA_ID, 2,
  167. mpc85xx_config_via_usb, {0,0,0}},
  168. {0x1106, 0x3038, PCI_ANY_ID, 1, VIA_ID, 3,
  169. mpc85xx_config_via_usb2, {0,0,0}},
  170. {0x1106, 0x3058, PCI_ANY_ID, 1, VIA_ID, 5,
  171. mpc85xx_config_via_power, {0,0,0}},
  172. {0x1106, 0x3068, PCI_ANY_ID, 1, VIA_ID, 6,
  173. mpc85xx_config_via_ac97, {0,0,0}},
  174. {},
  175. };
  176. static struct pci_controller pci1_hose;
  177. #endif /* CONFIG_PCI */
  178. void pci_init_board(void)
  179. {
  180. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  181. struct fsl_pci_info pci_info;
  182. u32 devdisr, pordevsr, io_sel;
  183. u32 porpllsr, pci_agent, pci_speed, pci_32, pci_arb, pci_clk_sel;
  184. int first_free_busno = 0;
  185. char buf[32];
  186. devdisr = in_be32(&gur->devdisr);
  187. pordevsr = in_be32(&gur->pordevsr);
  188. porpllsr = in_be32(&gur->porpllsr);
  189. io_sel = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  190. debug (" pci_init_board: devdisr=%x, io_sel=%x\n", devdisr, io_sel);
  191. #ifdef CONFIG_PCI1
  192. pci_speed = get_clock_freq (); /* PCI PSPEED in [4:5] */
  193. pci_32 = pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32; /* PORDEVSR[15] */
  194. pci_arb = pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;
  195. pci_clk_sel = porpllsr & MPC85xx_PORDEVSR_PCI1_SPD;
  196. if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
  197. SET_STD_PCI_INFO(pci_info, 1);
  198. set_next_law(pci_info.mem_phys,
  199. law_size_bits(pci_info.mem_size), pci_info.law);
  200. set_next_law(pci_info.io_phys,
  201. law_size_bits(pci_info.io_size), pci_info.law);
  202. pci_agent = fsl_setup_hose(&pci1_hose, pci_info.regs);
  203. printf("PCI1: %d bit, %s MHz, %s, %s, %s (base address %lx)\n",
  204. (pci_32) ? 32 : 64,
  205. strmhz(buf, pci_speed),
  206. pci_clk_sel ? "sync" : "async",
  207. pci_agent ? "agent" : "host",
  208. pci_arb ? "arbiter" : "external-arbiter",
  209. pci_info.regs);
  210. pci1_hose.config_table = pci_mpc85xxcds_config_table;
  211. first_free_busno = fsl_pci_init_port(&pci_info,
  212. &pci1_hose, first_free_busno);
  213. #ifdef CONFIG_PCIX_CHECK
  214. if (!(pordevsr & MPC85xx_PORDEVSR_PCI1)) {
  215. /* PCI-X init */
  216. if (CONFIG_SYS_CLK_FREQ < 66000000)
  217. printf("PCI-X will only work at 66 MHz\n");
  218. reg16 = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
  219. | PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
  220. pci_hose_write_config_word(hose, bus, PCIX_COMMAND, reg16);
  221. }
  222. #endif
  223. } else {
  224. printf("PCI1: disabled\n");
  225. }
  226. puts("\n");
  227. #else
  228. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI1); /* disable */
  229. #endif
  230. #ifdef CONFIG_PCI2
  231. {
  232. uint pci2_clk_sel = porpllsr & 0x4000; /* PORPLLSR[17] */
  233. uint pci_dual = get_pci_dual (); /* PCI DUAL in CM_PCI[3] */
  234. if (pci_dual) {
  235. printf("PCI2: 32 bit, 66 MHz, %s\n",
  236. pci2_clk_sel ? "sync" : "async");
  237. } else {
  238. printf("PCI2: disabled\n");
  239. }
  240. }
  241. #else
  242. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI2); /* disable */
  243. #endif /* CONFIG_PCI2 */
  244. fsl_pcie_init_board(first_free_busno);
  245. }
  246. void configure_rgmii(void)
  247. {
  248. unsigned short temp;
  249. /* Change the resistors for the PHY */
  250. /* This is needed to get the RGMII working for the 1.3+
  251. * CDS cards */
  252. if (get_board_version() == 0x13) {
  253. miiphy_write(DEFAULT_MII_NAME,
  254. TSEC1_PHY_ADDR, 29, 18);
  255. miiphy_read(DEFAULT_MII_NAME,
  256. TSEC1_PHY_ADDR, 30, &temp);
  257. temp = (temp & 0xf03f);
  258. temp |= 2 << 9; /* 36 ohm */
  259. temp |= 2 << 6; /* 39 ohm */
  260. miiphy_write(DEFAULT_MII_NAME,
  261. TSEC1_PHY_ADDR, 30, temp);
  262. miiphy_write(DEFAULT_MII_NAME,
  263. TSEC1_PHY_ADDR, 29, 3);
  264. miiphy_write(DEFAULT_MII_NAME,
  265. TSEC1_PHY_ADDR, 30, 0x8000);
  266. }
  267. return;
  268. }
  269. #ifdef CONFIG_TSEC_ENET
  270. int board_eth_init(bd_t *bis)
  271. {
  272. struct fsl_pq_mdio_info mdio_info;
  273. struct tsec_info_struct tsec_info[4];
  274. int num = 0;
  275. #ifdef CONFIG_TSEC1
  276. SET_STD_TSEC_INFO(tsec_info[num], 1);
  277. num++;
  278. #endif
  279. #ifdef CONFIG_TSEC2
  280. SET_STD_TSEC_INFO(tsec_info[num], 2);
  281. num++;
  282. #endif
  283. #ifdef CONFIG_TSEC3
  284. /* initialize TSEC3 only if Carrier is 1.3 or above on CDS */
  285. if (get_board_version() >= 0x13) {
  286. SET_STD_TSEC_INFO(tsec_info[num], 3);
  287. tsec_info[num].interface = PHY_INTERFACE_MODE_RGMII_ID;
  288. num++;
  289. }
  290. #endif
  291. #ifdef CONFIG_TSEC4
  292. /* initialize TSEC4 only if Carrier is 1.3 or above on CDS */
  293. if (get_board_version() >= 0x13) {
  294. SET_STD_TSEC_INFO(tsec_info[num], 4);
  295. tsec_info[num].interface = PHY_INTERFACE_MODE_RGMII_ID;
  296. num++;
  297. }
  298. #endif
  299. if (!num) {
  300. printf("No TSECs initialized\n");
  301. return 0;
  302. }
  303. mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
  304. mdio_info.name = DEFAULT_MII_NAME;
  305. fsl_pq_mdio_init(bis, &mdio_info);
  306. tsec_eth_init(bis, tsec_info, num);
  307. configure_rgmii();
  308. return pci_eth_init(bis);
  309. }
  310. #endif
  311. #if defined(CONFIG_OF_BOARD_SETUP)
  312. void ft_pci_setup(void *blob, bd_t *bd)
  313. {
  314. FT_FSL_PCI_SETUP;
  315. }
  316. #endif