blob: dbfa80a216c7e29a56f9c61c17abb6ef39d8b882 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jon Loeliger0553fc02007-04-11 16:51:02 -05002/*
Kumar Galad0f27d32010-07-08 22:37:44 -05003 * Copyright 2007,2009-2010 Freescale Semiconductor, Inc.
Jon Loeliger0553fc02007-04-11 16:51:02 -05004 */
5
6#include <common.h>
7#include <command.h>
Ed Swarthout52b98522007-07-27 01:50:51 -05008#include <pci.h>
Jon Loeliger0553fc02007-04-11 16:51:02 -05009#include <asm/processor.h>
Kumar Gala573ad302008-08-26 08:02:30 -050010#include <asm/mmu.h>
Jon Loeliger0553fc02007-04-11 16:51:02 -050011#include <asm/immap_85xx.h>
Kumar Gala9bbd6432009-04-02 13:22:48 -050012#include <asm/fsl_pci.h>
York Sunf0626592013-09-30 09:22:09 -070013#include <fsl_ddr_sdram.h>
Kumar Gala3d020382010-12-15 04:55:20 -060014#include <asm/fsl_serdes.h>
Kumar Galae1e870a2007-08-30 16:18:18 -050015#include <asm/io.h>
Jon Loeliger0553fc02007-04-11 16:51:02 -050016#include <miiphy.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090017#include <linux/libfdt.h>
Kumar Gala67b349b2007-11-26 17:12:24 -060018#include <fdt_support.h>
Andy Fleming422effd2011-04-08 02:10:54 -050019#include <fsl_mdio.h>
Andy Flemingafcf7762008-08-31 16:33:29 -050020#include <tsec.h>
Ben Warren65b86232008-08-31 21:41:08 -070021#include <netdev.h>
Jon Loeliger0553fc02007-04-11 16:51:02 -050022
Andy Flemingafcf7762008-08-31 16:33:29 -050023#include "../common/sgmii_riser.h"
Jon Loeliger0553fc02007-04-11 16:51:02 -050024
Jon Loeliger0553fc02007-04-11 16:51:02 -050025int checkboard (void)
26{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020027 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Becky Bruce0d4cee12010-06-17 11:37:20 -050028 volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020029 volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
Kumar Galae21db032009-07-14 22:42:01 -050030 u8 vboot;
31 u8 *pixis_base = (u8 *)PIXIS_BASE;
Jon Loeliger0553fc02007-04-11 16:51:02 -050032
Wolfgang Denk58c495b2007-05-05 18:23:11 +020033 if ((uint)&gur->porpllsr != 0xe00e0000) {
Wolfgang Denk12cec0a2008-07-11 01:16:00 +020034 printf("immap size error %lx\n",(ulong)&gur->porpllsr);
Jon Loeliger0553fc02007-04-11 16:51:02 -050035 }
Kumar Galae21db032009-07-14 22:42:01 -050036 printf ("Board: MPC8544DS, Sys ID: 0x%02x, "
37 "Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
38 in_8(pixis_base + PIXIS_ID), in_8(pixis_base + PIXIS_VER),
39 in_8(pixis_base + PIXIS_PVER));
40
41 vboot = in_8(pixis_base + PIXIS_VBOOT);
42 if (vboot & PIXIS_VBOOT_FMAP)
43 printf ("vBank: %d\n", ((vboot & PIXIS_VBOOT_FBANK) >> 6));
44 else
45 puts ("Promjet\n");
Jon Loeliger0553fc02007-04-11 16:51:02 -050046
Ed Swarthout52b98522007-07-27 01:50:51 -050047 lbc->ltesr = 0xffffffff; /* Clear LBC error interrupts */
48 lbc->lteir = 0xffffffff; /* Enable LBC error interrupts */
49 ecm->eedr = 0xffffffff; /* Clear ecm errors */
50 ecm->eeer = 0xffffffff; /* Enable ecm errors */
51
Jon Loeliger0553fc02007-04-11 16:51:02 -050052 return 0;
53}
54
Ed Swarthout52b98522007-07-27 01:50:51 -050055#ifdef CONFIG_PCI1
56static struct pci_controller pci1_hose;
57#endif
58
Ed Swarthout52b98522007-07-27 01:50:51 -050059#ifdef CONFIG_PCIE3
60static struct pci_controller pcie3_hose;
61#endif
62
Kumar Gala949ea662009-11-04 10:22:26 -060063void pci_init_board(void)
Ed Swarthout52b98522007-07-27 01:50:51 -050064{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020065 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Kumar Galacc46bc72010-12-17 06:01:24 -060066 struct fsl_pci_info pci_info;
Kumar Gala949ea662009-11-04 10:22:26 -060067 u32 devdisr, pordevsr, io_sel;
68 u32 porpllsr, pci_agent, pci_speed, pci_32, pci_arb, pci_clk_sel;
69 int first_free_busno = 0;
Kumar Gala949ea662009-11-04 10:22:26 -060070
71 int pcie_ep, pcie_configured;
Ed Swarthout52b98522007-07-27 01:50:51 -050072
Kumar Gala949ea662009-11-04 10:22:26 -060073 devdisr = in_be32(&gur->devdisr);
74 pordevsr = in_be32(&gur->pordevsr);
75 porpllsr = in_be32(&gur->porpllsr);
76 io_sel = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
77
78 debug (" pci_init_board: devdisr=%x, io_sel=%x\n", devdisr, io_sel);
Ed Swarthout52b98522007-07-27 01:50:51 -050079
Kumar Gala949ea662009-11-04 10:22:26 -060080 puts("\n");
Ed Swarthout52b98522007-07-27 01:50:51 -050081
82#ifdef CONFIG_PCIE3
Kumar Gala3d020382010-12-15 04:55:20 -060083 pcie_configured = is_serdes_configured(PCIE3);
Ed Swarthout52b98522007-07-27 01:50:51 -050084
Kumar Gala949ea662009-11-04 10:22:26 -060085 if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE3)){
Kumar Galacc46bc72010-12-17 06:01:24 -060086 /* contains both PCIE3 MEM & IO space */
87 set_next_law(CONFIG_SYS_PCIE3_MEM_PHYS, LAW_SIZE_4M,
88 LAW_TRGT_IF_PCIE_3);
89 SET_STD_PCIE_INFO(pci_info, 3);
90 pcie_ep = fsl_setup_hose(&pcie3_hose, pci_info.regs);
91
Ed Swarthout52b98522007-07-27 01:50:51 -050092 /* outbound memory */
Kumar Gala949ea662009-11-04 10:22:26 -060093 pci_set_region(&pcie3_hose.regions[0],
Kumar Gala3fe80872008-12-02 16:08:36 -060094 CONFIG_SYS_PCIE3_MEM_BUS2,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020095 CONFIG_SYS_PCIE3_MEM_PHYS2,
96 CONFIG_SYS_PCIE3_MEM_SIZE2,
Ed Swarthout52b98522007-07-27 01:50:51 -050097 PCI_REGION_MEM);
Ed Swarthout52b98522007-07-27 01:50:51 -050098
Kumar Gala949ea662009-11-04 10:22:26 -060099 pcie3_hose.region_count = 1;
Kumar Galacc46bc72010-12-17 06:01:24 -0600100
Peter Tyser2b91f712010-10-29 17:59:24 -0500101 printf("PCIE3: connected to ULI as %s (base addr %lx)\n",
102 pcie_ep ? "Endpoint" : "Root Complex",
Kumar Galacc46bc72010-12-17 06:01:24 -0600103 pci_info.regs);
104 first_free_busno = fsl_pci_init_port(&pci_info,
Kumar Gala949ea662009-11-04 10:22:26 -0600105 &pcie3_hose, first_free_busno);
Ed Swarthout52b98522007-07-27 01:50:51 -0500106
Kumar Galae1e870a2007-08-30 16:18:18 -0500107 /*
108 * Activate ULI1575 legacy chip by performing a fake
109 * memory access. Needed to make ULI RTC work.
110 */
Kumar Gala3fe80872008-12-02 16:08:36 -0600111 in_be32((u32 *)CONFIG_SYS_PCIE3_MEM_BUS);
Ed Swarthout52b98522007-07-27 01:50:51 -0500112 } else {
Peter Tyser2b91f712010-10-29 17:59:24 -0500113 printf("PCIE3: disabled\n");
Ed Swarthout52b98522007-07-27 01:50:51 -0500114 }
Kumar Gala949ea662009-11-04 10:22:26 -0600115 puts("\n");
Ed Swarthout52b98522007-07-27 01:50:51 -0500116#else
Kumar Gala949ea662009-11-04 10:22:26 -0600117 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE3); /* disable */
Ed Swarthout52b98522007-07-27 01:50:51 -0500118#endif
119
120#ifdef CONFIG_PCIE1
Kumar Galacc46bc72010-12-17 06:01:24 -0600121 SET_STD_PCIE_INFO(pci_info, 1);
122 first_free_busno = fsl_pcie_init_ctrl(first_free_busno, devdisr, PCIE1, &pci_info);
Ed Swarthout52b98522007-07-27 01:50:51 -0500123#else
Kumar Galacc46bc72010-12-17 06:01:24 -0600124 setbits_be32(&gur->devdisr, _DEVDISR_PCIE1); /* disable */
Ed Swarthout52b98522007-07-27 01:50:51 -0500125#endif
126
127#ifdef CONFIG_PCIE2
Kumar Galacc46bc72010-12-17 06:01:24 -0600128 SET_STD_PCIE_INFO(pci_info, 2);
129 first_free_busno = fsl_pcie_init_ctrl(first_free_busno, devdisr, PCIE2, &pci_info);
Ed Swarthout52b98522007-07-27 01:50:51 -0500130#else
Kumar Galacc46bc72010-12-17 06:01:24 -0600131 setbits_be32(&gur->devdisr, _DEVDISR_PCIE2); /* disable */
Ed Swarthout52b98522007-07-27 01:50:51 -0500132#endif
133
Ed Swarthout52b98522007-07-27 01:50:51 -0500134#ifdef CONFIG_PCI1
Kumar Gala949ea662009-11-04 10:22:26 -0600135 pci_speed = 66666000;
136 pci_32 = 1;
137 pci_arb = pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;
138 pci_clk_sel = porpllsr & MPC85xx_PORDEVSR_PCI1_SPD;
Ed Swarthout52b98522007-07-27 01:50:51 -0500139
140 if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
Kumar Galacc46bc72010-12-17 06:01:24 -0600141 SET_STD_PCI_INFO(pci_info, 1);
142 set_next_law(pci_info.mem_phys,
143 law_size_bits(pci_info.mem_size), pci_info.law);
144 set_next_law(pci_info.io_phys,
145 law_size_bits(pci_info.io_size), pci_info.law);
146
147 pci_agent = fsl_setup_hose(&pci1_hose, pci_info.regs);
Peter Tyser2b91f712010-10-29 17:59:24 -0500148 printf("PCI: %d bit, %s MHz, %s, %s, %s (base address %lx)\n",
Ed Swarthout52b98522007-07-27 01:50:51 -0500149 (pci_32) ? 32 : 64,
150 (pci_speed == 33333000) ? "33" :
151 (pci_speed == 66666000) ? "66" : "unknown",
152 pci_clk_sel ? "sync" : "async",
153 pci_agent ? "agent" : "host",
154 pci_arb ? "arbiter" : "external-arbiter",
Kumar Galacc46bc72010-12-17 06:01:24 -0600155 pci_info.regs);
Ed Swarthout52b98522007-07-27 01:50:51 -0500156
Kumar Galacc46bc72010-12-17 06:01:24 -0600157 first_free_busno = fsl_pci_init_port(&pci_info,
Kumar Gala949ea662009-11-04 10:22:26 -0600158 &pci1_hose, first_free_busno);
Ed Swarthout52b98522007-07-27 01:50:51 -0500159 } else {
Peter Tyser2b91f712010-10-29 17:59:24 -0500160 printf("PCI: disabled\n");
Ed Swarthout52b98522007-07-27 01:50:51 -0500161 }
Kumar Gala949ea662009-11-04 10:22:26 -0600162
163 puts("\n");
Ed Swarthout52b98522007-07-27 01:50:51 -0500164#else
Kumar Gala949ea662009-11-04 10:22:26 -0600165 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI1); /* disable */
Jon Loeliger0553fc02007-04-11 16:51:02 -0500166#endif
Ed Swarthout52b98522007-07-27 01:50:51 -0500167}
168
Jon Loeliger0553fc02007-04-11 16:51:02 -0500169int last_stage_init(void)
170{
171 return 0;
172}
173
174
175unsigned long
176get_board_sys_clk(ulong dummy)
177{
178 u8 i, go_bit, rd_clks;
179 ulong val = 0;
Kumar Gala146c4b22009-07-22 10:12:39 -0500180 u8 *pixis_base = (u8 *)PIXIS_BASE;
Jon Loeliger0553fc02007-04-11 16:51:02 -0500181
Kumar Gala146c4b22009-07-22 10:12:39 -0500182 go_bit = in_8(pixis_base + PIXIS_VCTL);
Jon Loeliger0553fc02007-04-11 16:51:02 -0500183 go_bit &= 0x01;
184
Kumar Gala146c4b22009-07-22 10:12:39 -0500185 rd_clks = in_8(pixis_base + PIXIS_VCFGEN0);
Jon Loeliger0553fc02007-04-11 16:51:02 -0500186 rd_clks &= 0x1C;
187
188 /*
189 * Only if both go bit and the SCLK bit in VCFGEN0 are set
190 * should we be using the AUX register. Remember, we also set the
191 * GO bit to boot from the alternate bank on the on-board flash
192 */
193
194 if (go_bit) {
195 if (rd_clks == 0x1c)
Kumar Gala146c4b22009-07-22 10:12:39 -0500196 i = in_8(pixis_base + PIXIS_AUX);
Jon Loeliger0553fc02007-04-11 16:51:02 -0500197 else
Kumar Gala146c4b22009-07-22 10:12:39 -0500198 i = in_8(pixis_base + PIXIS_SPD);
Jon Loeliger0553fc02007-04-11 16:51:02 -0500199 } else {
Kumar Gala146c4b22009-07-22 10:12:39 -0500200 i = in_8(pixis_base + PIXIS_SPD);
Jon Loeliger0553fc02007-04-11 16:51:02 -0500201 }
202
203 i &= 0x07;
204
205 switch (i) {
206 case 0:
207 val = 33333333;
208 break;
209 case 1:
210 val = 40000000;
211 break;
212 case 2:
213 val = 50000000;
214 break;
215 case 3:
216 val = 66666666;
217 break;
218 case 4:
219 val = 83000000;
220 break;
221 case 5:
222 val = 100000000;
223 break;
224 case 6:
225 val = 133333333;
226 break;
227 case 7:
228 val = 166666666;
229 break;
230 }
231
232 return val;
233}
234
Andy Fleming422effd2011-04-08 02:10:54 -0500235
236#define MIIM_CIS8204_SLED_CON 0x1b
237#define MIIM_CIS8204_SLEDCON_INIT 0x1115
238/*
239 * Hack to write all 4 PHYs with the LED values
240 */
241int board_phy_config(struct phy_device *phydev)
242{
243 static int do_once;
244 uint phyid;
245 struct mii_dev *bus = phydev->bus;
246
Troy Kisky85846412012-02-07 14:08:49 +0000247 if (phydev->drv->config)
248 phydev->drv->config(phydev);
Andy Fleming422effd2011-04-08 02:10:54 -0500249 if (do_once)
250 return 0;
251
252 for (phyid = 0; phyid < 4; phyid++)
253 bus->write(bus, phyid, MDIO_DEVAD_NONE, MIIM_CIS8204_SLED_CON,
254 MIIM_CIS8204_SLEDCON_INIT);
255
256 do_once = 1;
257
258 return 0;
259}
260
261
Andy Flemingafcf7762008-08-31 16:33:29 -0500262int board_eth_init(bd_t *bis)
263{
Ben Warren65b86232008-08-31 21:41:08 -0700264#ifdef CONFIG_TSEC_ENET
Andy Fleming422effd2011-04-08 02:10:54 -0500265 struct fsl_pq_mdio_info mdio_info;
Andy Flemingafcf7762008-08-31 16:33:29 -0500266 struct tsec_info_struct tsec_info[2];
Andy Flemingafcf7762008-08-31 16:33:29 -0500267 int num = 0;
268
269#ifdef CONFIG_TSEC1
270 SET_STD_TSEC_INFO(tsec_info[num], 1);
Kumar Galae6dc4842010-12-16 14:28:06 -0600271 if (is_serdes_configured(SGMII_TSEC1)) {
272 puts("eTSEC1 is in sgmii mode.\n");
Andy Flemingafcf7762008-08-31 16:33:29 -0500273 tsec_info[num].flags |= TSEC_SGMII;
Kumar Galae6dc4842010-12-16 14:28:06 -0600274 }
Andy Flemingafcf7762008-08-31 16:33:29 -0500275 num++;
276#endif
277#ifdef CONFIG_TSEC3
278 SET_STD_TSEC_INFO(tsec_info[num], 3);
Kumar Galae6dc4842010-12-16 14:28:06 -0600279 if (is_serdes_configured(SGMII_TSEC3)) {
280 puts("eTSEC3 is in sgmii mode.\n");
Andy Flemingafcf7762008-08-31 16:33:29 -0500281 tsec_info[num].flags |= TSEC_SGMII;
Kumar Galae6dc4842010-12-16 14:28:06 -0600282 }
Andy Flemingafcf7762008-08-31 16:33:29 -0500283 num++;
284#endif
285
286 if (!num) {
287 printf("No TSECs initialized\n");
288
289 return 0;
290 }
291
Kumar Galae6dc4842010-12-16 14:28:06 -0600292 if (is_serdes_configured(SGMII_TSEC1) ||
293 is_serdes_configured(SGMII_TSEC3)) {
Andy Flemingafcf7762008-08-31 16:33:29 -0500294 fsl_sgmii_riser_init(tsec_info, num);
Kumar Galae6dc4842010-12-16 14:28:06 -0600295 }
Andy Flemingafcf7762008-08-31 16:33:29 -0500296
Andy Fleming422effd2011-04-08 02:10:54 -0500297 mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
298 mdio_info.name = DEFAULT_MII_NAME;
299 fsl_pq_mdio_init(bis, &mdio_info);
Andy Flemingafcf7762008-08-31 16:33:29 -0500300
301 tsec_eth_init(bis, tsec_info, num);
Andy Flemingafcf7762008-08-31 16:33:29 -0500302#endif
Ben Warren65b86232008-08-31 21:41:08 -0700303 return pci_eth_init(bis);
304}
Andy Flemingafcf7762008-08-31 16:33:29 -0500305
Kumar Gala67b349b2007-11-26 17:12:24 -0600306#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glass2aec3cc2014-10-23 18:58:47 -0600307int ft_board_setup(void *blob, bd_t *bd)
Jon Loeliger0553fc02007-04-11 16:51:02 -0500308{
Wolfgang Denk58c495b2007-05-05 18:23:11 +0200309 ft_cpu_setup(blob, bd);
Jon Loeliger0553fc02007-04-11 16:51:02 -0500310
Kumar Galad0f27d32010-07-08 22:37:44 -0500311 FT_FSL_PCI_SETUP;
Kumar Galac10a0c42008-10-21 08:28:33 -0500312
Andy Flemingacaccae2008-12-05 20:10:22 -0600313#ifdef CONFIG_FSL_SGMII_RISER
314 fsl_sgmii_riser_fdt_fixup(blob);
315#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600316
317 return 0;
Jon Loeliger0553fc02007-04-11 16:51:02 -0500318}
319#endif