mpc8548cds.c 8.6 KB

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