blob: 30ed7083657fb7e3e5d0eb123f02dbfcd9cea669 [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>
Simon Glass18afe102019-11-14 12:57:47 -07008#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -06009#include <net.h>
Ed Swarthout52b98522007-07-27 01:50:51 -050010#include <pci.h>
Jon Loeliger0553fc02007-04-11 16:51:02 -050011#include <asm/processor.h>
Kumar Gala573ad302008-08-26 08:02:30 -050012#include <asm/mmu.h>
Jon Loeliger0553fc02007-04-11 16:51:02 -050013#include <asm/immap_85xx.h>
Kumar Gala9bbd6432009-04-02 13:22:48 -050014#include <asm/fsl_pci.h>
York Sunf0626592013-09-30 09:22:09 -070015#include <fsl_ddr_sdram.h>
Kumar Gala3d020382010-12-15 04:55:20 -060016#include <asm/fsl_serdes.h>
Kumar Galae1e870a2007-08-30 16:18:18 -050017#include <asm/io.h>
Jon Loeliger0553fc02007-04-11 16:51:02 -050018#include <miiphy.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090019#include <linux/libfdt.h>
Kumar Gala67b349b2007-11-26 17:12:24 -060020#include <fdt_support.h>
Andy Fleming422effd2011-04-08 02:10:54 -050021#include <fsl_mdio.h>
Andy Flemingafcf7762008-08-31 16:33:29 -050022#include <tsec.h>
Ben Warren65b86232008-08-31 21:41:08 -070023#include <netdev.h>
Jon Loeliger0553fc02007-04-11 16:51:02 -050024
Andy Flemingafcf7762008-08-31 16:33:29 -050025#include "../common/sgmii_riser.h"
Jon Loeliger0553fc02007-04-11 16:51:02 -050026
Jon Loeliger0553fc02007-04-11 16:51:02 -050027int checkboard (void)
28{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020029 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Becky Bruce0d4cee12010-06-17 11:37:20 -050030 volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020031 volatile ccsr_local_ecm_t *ecm = (void *)(CONFIG_SYS_MPC85xx_ECM_ADDR);
Kumar Galae21db032009-07-14 22:42:01 -050032 u8 vboot;
33 u8 *pixis_base = (u8 *)PIXIS_BASE;
Jon Loeliger0553fc02007-04-11 16:51:02 -050034
Wolfgang Denk58c495b2007-05-05 18:23:11 +020035 if ((uint)&gur->porpllsr != 0xe00e0000) {
Wolfgang Denk12cec0a2008-07-11 01:16:00 +020036 printf("immap size error %lx\n",(ulong)&gur->porpllsr);
Jon Loeliger0553fc02007-04-11 16:51:02 -050037 }
Kumar Galae21db032009-07-14 22:42:01 -050038 printf ("Board: MPC8544DS, Sys ID: 0x%02x, "
39 "Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
40 in_8(pixis_base + PIXIS_ID), in_8(pixis_base + PIXIS_VER),
41 in_8(pixis_base + PIXIS_PVER));
42
43 vboot = in_8(pixis_base + PIXIS_VBOOT);
44 if (vboot & PIXIS_VBOOT_FMAP)
45 printf ("vBank: %d\n", ((vboot & PIXIS_VBOOT_FBANK) >> 6));
46 else
47 puts ("Promjet\n");
Jon Loeliger0553fc02007-04-11 16:51:02 -050048
Ed Swarthout52b98522007-07-27 01:50:51 -050049 lbc->ltesr = 0xffffffff; /* Clear LBC error interrupts */
50 lbc->lteir = 0xffffffff; /* Enable LBC error interrupts */
51 ecm->eedr = 0xffffffff; /* Clear ecm errors */
52 ecm->eeer = 0xffffffff; /* Enable ecm errors */
53
Jon Loeliger0553fc02007-04-11 16:51:02 -050054 return 0;
55}
56
Ed Swarthout52b98522007-07-27 01:50:51 -050057#ifdef CONFIG_PCI1
58static struct pci_controller pci1_hose;
59#endif
60
Ed Swarthout52b98522007-07-27 01:50:51 -050061#ifdef CONFIG_PCIE3
62static struct pci_controller pcie3_hose;
63#endif
64
Kumar Gala949ea662009-11-04 10:22:26 -060065void pci_init_board(void)
Ed Swarthout52b98522007-07-27 01:50:51 -050066{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020067 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Kumar Galacc46bc72010-12-17 06:01:24 -060068 struct fsl_pci_info pci_info;
Kumar Gala949ea662009-11-04 10:22:26 -060069 u32 devdisr, pordevsr, io_sel;
70 u32 porpllsr, pci_agent, pci_speed, pci_32, pci_arb, pci_clk_sel;
71 int first_free_busno = 0;
Kumar Gala949ea662009-11-04 10:22:26 -060072
73 int pcie_ep, pcie_configured;
Ed Swarthout52b98522007-07-27 01:50:51 -050074
Kumar Gala949ea662009-11-04 10:22:26 -060075 devdisr = in_be32(&gur->devdisr);
76 pordevsr = in_be32(&gur->pordevsr);
77 porpllsr = in_be32(&gur->porpllsr);
78 io_sel = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
79
80 debug (" pci_init_board: devdisr=%x, io_sel=%x\n", devdisr, io_sel);
Ed Swarthout52b98522007-07-27 01:50:51 -050081
Kumar Gala949ea662009-11-04 10:22:26 -060082 puts("\n");
Ed Swarthout52b98522007-07-27 01:50:51 -050083
84#ifdef CONFIG_PCIE3
Kumar Gala3d020382010-12-15 04:55:20 -060085 pcie_configured = is_serdes_configured(PCIE3);
Ed Swarthout52b98522007-07-27 01:50:51 -050086
Kumar Gala949ea662009-11-04 10:22:26 -060087 if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE3)){
Kumar Galacc46bc72010-12-17 06:01:24 -060088 /* contains both PCIE3 MEM & IO space */
89 set_next_law(CONFIG_SYS_PCIE3_MEM_PHYS, LAW_SIZE_4M,
90 LAW_TRGT_IF_PCIE_3);
91 SET_STD_PCIE_INFO(pci_info, 3);
92 pcie_ep = fsl_setup_hose(&pcie3_hose, pci_info.regs);
93
Ed Swarthout52b98522007-07-27 01:50:51 -050094 /* outbound memory */
Kumar Gala949ea662009-11-04 10:22:26 -060095 pci_set_region(&pcie3_hose.regions[0],
Kumar Gala3fe80872008-12-02 16:08:36 -060096 CONFIG_SYS_PCIE3_MEM_BUS2,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020097 CONFIG_SYS_PCIE3_MEM_PHYS2,
98 CONFIG_SYS_PCIE3_MEM_SIZE2,
Ed Swarthout52b98522007-07-27 01:50:51 -050099 PCI_REGION_MEM);
Ed Swarthout52b98522007-07-27 01:50:51 -0500100
Kumar Gala949ea662009-11-04 10:22:26 -0600101 pcie3_hose.region_count = 1;
Kumar Galacc46bc72010-12-17 06:01:24 -0600102
Peter Tyser2b91f712010-10-29 17:59:24 -0500103 printf("PCIE3: connected to ULI as %s (base addr %lx)\n",
104 pcie_ep ? "Endpoint" : "Root Complex",
Kumar Galacc46bc72010-12-17 06:01:24 -0600105 pci_info.regs);
106 first_free_busno = fsl_pci_init_port(&pci_info,
Kumar Gala949ea662009-11-04 10:22:26 -0600107 &pcie3_hose, first_free_busno);
Ed Swarthout52b98522007-07-27 01:50:51 -0500108
Kumar Galae1e870a2007-08-30 16:18:18 -0500109 /*
110 * Activate ULI1575 legacy chip by performing a fake
111 * memory access. Needed to make ULI RTC work.
112 */
Kumar Gala3fe80872008-12-02 16:08:36 -0600113 in_be32((u32 *)CONFIG_SYS_PCIE3_MEM_BUS);
Ed Swarthout52b98522007-07-27 01:50:51 -0500114 } else {
Peter Tyser2b91f712010-10-29 17:59:24 -0500115 printf("PCIE3: disabled\n");
Ed Swarthout52b98522007-07-27 01:50:51 -0500116 }
Kumar Gala949ea662009-11-04 10:22:26 -0600117 puts("\n");
Ed Swarthout52b98522007-07-27 01:50:51 -0500118#else
Kumar Gala949ea662009-11-04 10:22:26 -0600119 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE3); /* disable */
Ed Swarthout52b98522007-07-27 01:50:51 -0500120#endif
121
122#ifdef CONFIG_PCIE1
Kumar Galacc46bc72010-12-17 06:01:24 -0600123 SET_STD_PCIE_INFO(pci_info, 1);
124 first_free_busno = fsl_pcie_init_ctrl(first_free_busno, devdisr, PCIE1, &pci_info);
Ed Swarthout52b98522007-07-27 01:50:51 -0500125#else
Kumar Galacc46bc72010-12-17 06:01:24 -0600126 setbits_be32(&gur->devdisr, _DEVDISR_PCIE1); /* disable */
Ed Swarthout52b98522007-07-27 01:50:51 -0500127#endif
128
129#ifdef CONFIG_PCIE2
Kumar Galacc46bc72010-12-17 06:01:24 -0600130 SET_STD_PCIE_INFO(pci_info, 2);
131 first_free_busno = fsl_pcie_init_ctrl(first_free_busno, devdisr, PCIE2, &pci_info);
Ed Swarthout52b98522007-07-27 01:50:51 -0500132#else
Kumar Galacc46bc72010-12-17 06:01:24 -0600133 setbits_be32(&gur->devdisr, _DEVDISR_PCIE2); /* disable */
Ed Swarthout52b98522007-07-27 01:50:51 -0500134#endif
135
Ed Swarthout52b98522007-07-27 01:50:51 -0500136#ifdef CONFIG_PCI1
Kumar Gala949ea662009-11-04 10:22:26 -0600137 pci_speed = 66666000;
138 pci_32 = 1;
139 pci_arb = pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;
140 pci_clk_sel = porpllsr & MPC85xx_PORDEVSR_PCI1_SPD;
Ed Swarthout52b98522007-07-27 01:50:51 -0500141
142 if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
Kumar Galacc46bc72010-12-17 06:01:24 -0600143 SET_STD_PCI_INFO(pci_info, 1);
144 set_next_law(pci_info.mem_phys,
145 law_size_bits(pci_info.mem_size), pci_info.law);
146 set_next_law(pci_info.io_phys,
147 law_size_bits(pci_info.io_size), pci_info.law);
148
149 pci_agent = fsl_setup_hose(&pci1_hose, pci_info.regs);
Peter Tyser2b91f712010-10-29 17:59:24 -0500150 printf("PCI: %d bit, %s MHz, %s, %s, %s (base address %lx)\n",
Ed Swarthout52b98522007-07-27 01:50:51 -0500151 (pci_32) ? 32 : 64,
152 (pci_speed == 33333000) ? "33" :
153 (pci_speed == 66666000) ? "66" : "unknown",
154 pci_clk_sel ? "sync" : "async",
155 pci_agent ? "agent" : "host",
156 pci_arb ? "arbiter" : "external-arbiter",
Kumar Galacc46bc72010-12-17 06:01:24 -0600157 pci_info.regs);
Ed Swarthout52b98522007-07-27 01:50:51 -0500158
Kumar Galacc46bc72010-12-17 06:01:24 -0600159 first_free_busno = fsl_pci_init_port(&pci_info,
Kumar Gala949ea662009-11-04 10:22:26 -0600160 &pci1_hose, first_free_busno);
Ed Swarthout52b98522007-07-27 01:50:51 -0500161 } else {
Peter Tyser2b91f712010-10-29 17:59:24 -0500162 printf("PCI: disabled\n");
Ed Swarthout52b98522007-07-27 01:50:51 -0500163 }
Kumar Gala949ea662009-11-04 10:22:26 -0600164
165 puts("\n");
Ed Swarthout52b98522007-07-27 01:50:51 -0500166#else
Kumar Gala949ea662009-11-04 10:22:26 -0600167 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI1); /* disable */
Jon Loeliger0553fc02007-04-11 16:51:02 -0500168#endif
Ed Swarthout52b98522007-07-27 01:50:51 -0500169}
170
Jon Loeliger0553fc02007-04-11 16:51:02 -0500171int last_stage_init(void)
172{
173 return 0;
174}
175
176
177unsigned long
178get_board_sys_clk(ulong dummy)
179{
180 u8 i, go_bit, rd_clks;
181 ulong val = 0;
Kumar Gala146c4b22009-07-22 10:12:39 -0500182 u8 *pixis_base = (u8 *)PIXIS_BASE;
Jon Loeliger0553fc02007-04-11 16:51:02 -0500183
Kumar Gala146c4b22009-07-22 10:12:39 -0500184 go_bit = in_8(pixis_base + PIXIS_VCTL);
Jon Loeliger0553fc02007-04-11 16:51:02 -0500185 go_bit &= 0x01;
186
Kumar Gala146c4b22009-07-22 10:12:39 -0500187 rd_clks = in_8(pixis_base + PIXIS_VCFGEN0);
Jon Loeliger0553fc02007-04-11 16:51:02 -0500188 rd_clks &= 0x1C;
189
190 /*
191 * Only if both go bit and the SCLK bit in VCFGEN0 are set
192 * should we be using the AUX register. Remember, we also set the
193 * GO bit to boot from the alternate bank on the on-board flash
194 */
195
196 if (go_bit) {
197 if (rd_clks == 0x1c)
Kumar Gala146c4b22009-07-22 10:12:39 -0500198 i = in_8(pixis_base + PIXIS_AUX);
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 } else {
Kumar Gala146c4b22009-07-22 10:12:39 -0500202 i = in_8(pixis_base + PIXIS_SPD);
Jon Loeliger0553fc02007-04-11 16:51:02 -0500203 }
204
205 i &= 0x07;
206
207 switch (i) {
208 case 0:
209 val = 33333333;
210 break;
211 case 1:
212 val = 40000000;
213 break;
214 case 2:
215 val = 50000000;
216 break;
217 case 3:
218 val = 66666666;
219 break;
220 case 4:
221 val = 83000000;
222 break;
223 case 5:
224 val = 100000000;
225 break;
226 case 6:
227 val = 133333333;
228 break;
229 case 7:
230 val = 166666666;
231 break;
232 }
233
234 return val;
235}
236
Andy Fleming422effd2011-04-08 02:10:54 -0500237
238#define MIIM_CIS8204_SLED_CON 0x1b
239#define MIIM_CIS8204_SLEDCON_INIT 0x1115
240/*
241 * Hack to write all 4 PHYs with the LED values
242 */
243int board_phy_config(struct phy_device *phydev)
244{
245 static int do_once;
246 uint phyid;
247 struct mii_dev *bus = phydev->bus;
248
Troy Kisky85846412012-02-07 14:08:49 +0000249 if (phydev->drv->config)
250 phydev->drv->config(phydev);
Andy Fleming422effd2011-04-08 02:10:54 -0500251 if (do_once)
252 return 0;
253
254 for (phyid = 0; phyid < 4; phyid++)
255 bus->write(bus, phyid, MDIO_DEVAD_NONE, MIIM_CIS8204_SLED_CON,
256 MIIM_CIS8204_SLEDCON_INIT);
257
258 do_once = 1;
259
260 return 0;
261}
262
263
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900264int board_eth_init(struct bd_info *bis)
Andy Flemingafcf7762008-08-31 16:33:29 -0500265{
Ben Warren65b86232008-08-31 21:41:08 -0700266#ifdef CONFIG_TSEC_ENET
Andy Fleming422effd2011-04-08 02:10:54 -0500267 struct fsl_pq_mdio_info mdio_info;
Andy Flemingafcf7762008-08-31 16:33:29 -0500268 struct tsec_info_struct tsec_info[2];
Andy Flemingafcf7762008-08-31 16:33:29 -0500269 int num = 0;
270
271#ifdef CONFIG_TSEC1
272 SET_STD_TSEC_INFO(tsec_info[num], 1);
Kumar Galae6dc4842010-12-16 14:28:06 -0600273 if (is_serdes_configured(SGMII_TSEC1)) {
274 puts("eTSEC1 is in sgmii mode.\n");
Andy Flemingafcf7762008-08-31 16:33:29 -0500275 tsec_info[num].flags |= TSEC_SGMII;
Kumar Galae6dc4842010-12-16 14:28:06 -0600276 }
Andy Flemingafcf7762008-08-31 16:33:29 -0500277 num++;
278#endif
279#ifdef CONFIG_TSEC3
280 SET_STD_TSEC_INFO(tsec_info[num], 3);
Kumar Galae6dc4842010-12-16 14:28:06 -0600281 if (is_serdes_configured(SGMII_TSEC3)) {
282 puts("eTSEC3 is in sgmii mode.\n");
Andy Flemingafcf7762008-08-31 16:33:29 -0500283 tsec_info[num].flags |= TSEC_SGMII;
Kumar Galae6dc4842010-12-16 14:28:06 -0600284 }
Andy Flemingafcf7762008-08-31 16:33:29 -0500285 num++;
286#endif
287
288 if (!num) {
289 printf("No TSECs initialized\n");
290
291 return 0;
292 }
293
Kumar Galae6dc4842010-12-16 14:28:06 -0600294 if (is_serdes_configured(SGMII_TSEC1) ||
295 is_serdes_configured(SGMII_TSEC3)) {
Andy Flemingafcf7762008-08-31 16:33:29 -0500296 fsl_sgmii_riser_init(tsec_info, num);
Kumar Galae6dc4842010-12-16 14:28:06 -0600297 }
Andy Flemingafcf7762008-08-31 16:33:29 -0500298
Andy Fleming422effd2011-04-08 02:10:54 -0500299 mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
300 mdio_info.name = DEFAULT_MII_NAME;
301 fsl_pq_mdio_init(bis, &mdio_info);
Andy Flemingafcf7762008-08-31 16:33:29 -0500302
303 tsec_eth_init(bis, tsec_info, num);
Andy Flemingafcf7762008-08-31 16:33:29 -0500304#endif
Ben Warren65b86232008-08-31 21:41:08 -0700305 return pci_eth_init(bis);
306}
Andy Flemingafcf7762008-08-31 16:33:29 -0500307
Kumar Gala67b349b2007-11-26 17:12:24 -0600308#if defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900309int ft_board_setup(void *blob, struct bd_info *bd)
Jon Loeliger0553fc02007-04-11 16:51:02 -0500310{
Wolfgang Denk58c495b2007-05-05 18:23:11 +0200311 ft_cpu_setup(blob, bd);
Jon Loeliger0553fc02007-04-11 16:51:02 -0500312
Kumar Galad0f27d32010-07-08 22:37:44 -0500313 FT_FSL_PCI_SETUP;
Kumar Galac10a0c42008-10-21 08:28:33 -0500314
Andy Flemingacaccae2008-12-05 20:10:22 -0600315#ifdef CONFIG_FSL_SGMII_RISER
316 fsl_sgmii_riser_fdt_fixup(blob);
317#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600318
319 return 0;
Jon Loeliger0553fc02007-04-11 16:51:02 -0500320}
321#endif