blob: 07cb08b6b8cfbd477a83634c11295a53dd0dda6d [file] [log] [blame]
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001/*
Kumar Gala365024c2011-01-31 15:51:20 -06002 * Copyright 2006, 2007, 2010-2011 Freescale Semiconductor.
Jon Loeliger5c8aa972006-04-26 17:58:56 -05003 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Jon Loeliger5c8aa972006-04-26 17:58:56 -05005 */
6
7#include <common.h>
8#include <pci.h>
9#include <asm/processor.h>
10#include <asm/immap_86xx.h>
Kumar Gala9bbd6432009-04-02 13:22:48 -050011#include <asm/fsl_pci.h>
York Sunf0626592013-09-30 09:22:09 -070012#include <fsl_ddr_sdram.h>
Kumar Gala3d020382010-12-15 04:55:20 -060013#include <asm/fsl_serdes.h>
Haiying Wang57b6e9c2007-01-22 12:37:30 -060014#include <asm/io.h>
Jon Loeliger6160aa42007-11-28 14:47:18 -060015#include <libfdt.h>
16#include <fdt_support.h>
Ben Warren65b86232008-08-31 21:41:08 -070017#include <netdev.h>
Jon Loeliger5c8aa972006-04-26 17:58:56 -050018
Simon Glass39f90ba2017-03-31 08:40:25 -060019DECLARE_GLOBAL_DATA_PTR;
20
Becky Brucecc064ed2008-10-31 17:13:32 -050021phys_size_t fixed_sdram(void);
Jon Loeliger5c8aa972006-04-26 17:58:56 -050022
Jon Loeliger4fbb09c2006-08-22 12:25:27 -050023int checkboard(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050024{
Kumar Galaaba63972009-07-15 13:45:00 -050025 u8 vboot;
26 u8 *pixis_base = (u8 *)PIXIS_BASE;
27
28 printf ("Board: MPC8641HPCN, Sys ID: 0x%02x, "
29 "Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
30 in_8(pixis_base + PIXIS_ID), in_8(pixis_base + PIXIS_VER),
31 in_8(pixis_base + PIXIS_PVER));
32
33 vboot = in_8(pixis_base + PIXIS_VBOOT);
34 if (vboot & PIXIS_VBOOT_FMAP)
35 printf ("vBank: %d\n", ((vboot & PIXIS_VBOOT_FBANK) >> 6));
36 else
37 puts ("Promjet\n");
38
Jon Loeliger5c8aa972006-04-26 17:58:56 -050039 return 0;
40}
41
Simon Glass39f90ba2017-03-31 08:40:25 -060042int initdram(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050043{
Becky Brucecc064ed2008-10-31 17:13:32 -050044 phys_size_t dram_size = 0;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050045
46#if defined(CONFIG_SPD_EEPROM)
Kumar Galacad506c2008-08-26 15:01:35 -050047 dram_size = fsl_ddr_sdram();
Jon Loeliger5c8aa972006-04-26 17:58:56 -050048#else
Jon Loeliger4fbb09c2006-08-22 12:25:27 -050049 dram_size = fixed_sdram();
Jon Loeliger5c8aa972006-04-26 17:58:56 -050050#endif
51
Timur Tabi107e9cd2010-03-29 12:51:07 -050052 setup_ddr_bat(dram_size);
53
Wolfgang Denkf2bbb532011-07-25 10:13:53 +020054 debug(" DDR: ");
Simon Glass39f90ba2017-03-31 08:40:25 -060055 gd->ram_size = dram_size;
56
57 return 0;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050058}
59
Jon Loeliger5c8aa972006-04-26 17:58:56 -050060
Jon Loeliger5c8aa972006-04-26 17:58:56 -050061#if !defined(CONFIG_SPD_EEPROM)
Jon Loeliger465b9d82006-04-27 10:15:16 -050062/*
63 * Fixed sdram init -- doesn't use serial presence detect.
64 */
Becky Brucecc064ed2008-10-31 17:13:32 -050065phys_size_t
Jon Loeliger4fbb09c2006-08-22 12:25:27 -050066fixed_sdram(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050067{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020068#if !defined(CONFIG_SYS_RAMBOOT)
69 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
York Suna21803d2013-11-18 10:29:32 -080070 struct ccsr_ddr __iomem *ddr = &immap->im_ddr1;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050071
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020072 ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
73 ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
74 ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
75 ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
76 ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
77 ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
Peter Tyseraf5829cb2009-07-17 10:14:45 -050078 ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020079 ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2;
80 ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
81 ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT;
82 ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL;
83 ddr->sdram_ocd_cntl = CONFIG_SYS_DDR_OCD_CTRL;
84 ddr->sdram_ocd_status = CONFIG_SYS_DDR_OCD_STATUS;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050085
86#if defined (CONFIG_DDR_ECC)
87 ddr->err_disable = 0x0000008D;
88 ddr->err_sbe = 0x00ff0000;
89#endif
90 asm("sync;isync");
Jon Loeligere65e32e2006-05-31 12:44:44 -050091
Jon Loeliger5c8aa972006-04-26 17:58:56 -050092 udelay(500);
93
94#if defined (CONFIG_DDR_ECC)
95 /* Enable ECC checking */
Peter Tyseraf5829cb2009-07-17 10:14:45 -050096 ddr->sdram_cfg = (CONFIG_SYS_DDR_CONTROL | 0x20000000);
Jon Loeliger5c8aa972006-04-26 17:58:56 -050097#else
Peter Tyseraf5829cb2009-07-17 10:14:45 -050098 ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020099 ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL2;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500100#endif
101 asm("sync; isync");
Jon Loeligere65e32e2006-05-31 12:44:44 -0500102
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500103 udelay(500);
104#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200105 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500106}
107#endif /* !defined(CONFIG_SPD_EEPROM) */
108
Jon Loeliger4fbb09c2006-08-22 12:25:27 -0500109void pci_init_board(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500110{
Kumar Galadbbfb002010-12-17 10:47:36 -0600111 fsl_pcie_init_board(0);
Peter Tyser8d6f9fa2010-09-29 13:37:26 -0500112
Kumar Galae78f6652010-07-09 00:02:34 -0500113#ifdef CONFIG_PCIE1
Ed Swarthout91080f72007-08-02 14:09:49 -0500114 /*
115 * Activate ULI1575 legacy chip by performing a fake
116 * memory access. Needed to make ULI RTC work.
117 */
Kumar Galae78f6652010-07-09 00:02:34 -0500118 in_be32((unsigned *) ((char *)(CONFIG_SYS_PCIE1_MEM_VIRT
119 + CONFIG_SYS_PCIE1_MEM_SIZE - 0x1000000)));
Kumar Galae78f6652010-07-09 00:02:34 -0500120#endif /* CONFIG_PCIE1 */
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500121}
122
Jon Loeliger84640c92008-02-18 14:01:56 -0600123
Jon Loeliger6160aa42007-11-28 14:47:18 -0600124#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glass2aec3cc2014-10-23 18:58:47 -0600125int ft_board_setup(void *blob, bd_t *bd)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500126{
Becky Bruce48d3ce22008-11-07 13:46:19 -0600127 int off;
128 u64 *tmp;
Simon Glass9fbc6322014-10-23 18:58:57 -0600129 int addrcells;
Becky Bruce48d3ce22008-11-07 13:46:19 -0600130
Jon Loeliger84640c92008-02-18 14:01:56 -0600131 ft_cpu_setup(blob, bd);
Jon Loeliger6160aa42007-11-28 14:47:18 -0600132
Kumar Galad0f27d32010-07-08 22:37:44 -0500133 FT_FSL_PCI_SETUP;
Becky Bruce48d3ce22008-11-07 13:46:19 -0600134
135 /*
136 * Warn if it looks like the device tree doesn't match u-boot.
137 * This is just an estimation, based on the location of CCSR,
138 * which is defined by the "reg" property in the soc node.
139 */
140 off = fdt_path_offset(blob, "/soc8641");
Simon Glass9fbc6322014-10-23 18:58:57 -0600141 addrcells = fdt_address_cells(blob, 0);
Becky Bruce48d3ce22008-11-07 13:46:19 -0600142 tmp = (u64 *)fdt_getprop(blob, off, "reg", NULL);
143
144 if (tmp) {
145 u64 addr;
Simon Glass9fbc6322014-10-23 18:58:57 -0600146
147 if (addrcells == 1)
Becky Bruce48d3ce22008-11-07 13:46:19 -0600148 addr = *(u32 *)tmp;
Becky Bruceeccb5e72008-11-10 19:45:35 -0600149 else
150 addr = *tmp;
Becky Bruce48d3ce22008-11-07 13:46:19 -0600151
152 if (addr != CONFIG_SYS_CCSRBAR_PHYS)
153 printf("WARNING: The CCSRBAR address in your .dts "
154 "does not match the address of the CCSR "
155 "in u-boot. This means your .dts might "
156 "be old.\n");
157 }
Simon Glass2aec3cc2014-10-23 18:58:47 -0600158
159 return 0;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500160}
161#endif
162
Jon Loeliger72f8a8e2006-05-31 11:24:28 -0500163
Haiying Wang43d624d2006-07-28 12:41:18 -0400164/*
165 * get_board_sys_clk
166 * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
167 */
168
Jon Loeliger4fbb09c2006-08-22 12:25:27 -0500169unsigned long
170get_board_sys_clk(ulong dummy)
Haiying Wang43d624d2006-07-28 12:41:18 -0400171{
172 u8 i, go_bit, rd_clks;
173 ulong val = 0;
Kumar Gala146c4b22009-07-22 10:12:39 -0500174 u8 *pixis_base = (u8 *)PIXIS_BASE;
Haiying Wang43d624d2006-07-28 12:41:18 -0400175
Kumar Gala146c4b22009-07-22 10:12:39 -0500176 go_bit = in_8(pixis_base + PIXIS_VCTL);
Haiying Wang43d624d2006-07-28 12:41:18 -0400177 go_bit &= 0x01;
178
Kumar Gala146c4b22009-07-22 10:12:39 -0500179 rd_clks = in_8(pixis_base + PIXIS_VCFGEN0);
Haiying Wang43d624d2006-07-28 12:41:18 -0400180 rd_clks &= 0x1C;
181
182 /*
183 * Only if both go bit and the SCLK bit in VCFGEN0 are set
184 * should we be using the AUX register. Remember, we also set the
185 * GO bit to boot from the alternate bank on the on-board flash
186 */
187
188 if (go_bit) {
189 if (rd_clks == 0x1c)
Kumar Gala146c4b22009-07-22 10:12:39 -0500190 i = in_8(pixis_base + PIXIS_AUX);
Haiying Wang43d624d2006-07-28 12:41:18 -0400191 else
Kumar Gala146c4b22009-07-22 10:12:39 -0500192 i = in_8(pixis_base + PIXIS_SPD);
Haiying Wang43d624d2006-07-28 12:41:18 -0400193 } else {
Kumar Gala146c4b22009-07-22 10:12:39 -0500194 i = in_8(pixis_base + PIXIS_SPD);
Haiying Wang43d624d2006-07-28 12:41:18 -0400195 }
196
197 i &= 0x07;
198
199 switch (i) {
200 case 0:
201 val = 33000000;
202 break;
203 case 1:
204 val = 40000000;
205 break;
206 case 2:
207 val = 50000000;
208 break;
209 case 3:
210 val = 66000000;
211 break;
212 case 4:
213 val = 83000000;
214 break;
215 case 5:
216 val = 100000000;
217 break;
218 case 6:
219 val = 134000000;
220 break;
221 case 7:
222 val = 166000000;
223 break;
224 }
225
226 return val;
227}
Ben Warren65b86232008-08-31 21:41:08 -0700228
229int board_eth_init(bd_t *bis)
230{
231 /* Initialize TSECs */
232 cpu_eth_init(bis);
233 return pci_eth_init(bis);
234}
Peter Tyser69454402009-02-05 11:25:25 -0600235
236void board_reset(void)
237{
Kumar Gala146c4b22009-07-22 10:12:39 -0500238 u8 *pixis_base = (u8 *)PIXIS_BASE;
239
240 out_8(pixis_base + PIXIS_RST, 0);
Peter Tyser69454402009-02-05 11:25:25 -0600241
242 while (1)
243 ;
244}