blob: ea4f3d670bb7cf2a703c212b32988469918735b7 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jon Loeliger5c8aa972006-04-26 17:58:56 -05002/*
Kumar Gala365024c2011-01-31 15:51:20 -06003 * Copyright 2006, 2007, 2010-2011 Freescale Semiconductor.
Jon Loeliger5c8aa972006-04-26 17:58:56 -05004 */
5
6#include <common.h>
7#include <pci.h>
8#include <asm/processor.h>
9#include <asm/immap_86xx.h>
Kumar Gala9bbd6432009-04-02 13:22:48 -050010#include <asm/fsl_pci.h>
York Sunf0626592013-09-30 09:22:09 -070011#include <fsl_ddr_sdram.h>
Kumar Gala3d020382010-12-15 04:55:20 -060012#include <asm/fsl_serdes.h>
Haiying Wang57b6e9c2007-01-22 12:37:30 -060013#include <asm/io.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090014#include <linux/libfdt.h>
Jon Loeliger6160aa42007-11-28 14:47:18 -060015#include <fdt_support.h>
Ben Warren65b86232008-08-31 21:41:08 -070016#include <netdev.h>
Jon Loeliger5c8aa972006-04-26 17:58:56 -050017
Simon Glass39f90ba2017-03-31 08:40:25 -060018DECLARE_GLOBAL_DATA_PTR;
19
Becky Brucecc064ed2008-10-31 17:13:32 -050020phys_size_t fixed_sdram(void);
Jon Loeliger5c8aa972006-04-26 17:58:56 -050021
Jon Loeliger4fbb09c2006-08-22 12:25:27 -050022int checkboard(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050023{
Kumar Galaaba63972009-07-15 13:45:00 -050024 u8 vboot;
25 u8 *pixis_base = (u8 *)PIXIS_BASE;
26
27 printf ("Board: MPC8641HPCN, Sys ID: 0x%02x, "
28 "Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
29 in_8(pixis_base + PIXIS_ID), in_8(pixis_base + PIXIS_VER),
30 in_8(pixis_base + PIXIS_PVER));
31
32 vboot = in_8(pixis_base + PIXIS_VBOOT);
33 if (vboot & PIXIS_VBOOT_FMAP)
34 printf ("vBank: %d\n", ((vboot & PIXIS_VBOOT_FBANK) >> 6));
35 else
36 puts ("Promjet\n");
37
Jon Loeliger5c8aa972006-04-26 17:58:56 -050038 return 0;
39}
40
Simon Glassd35f3382017-04-06 12:47:05 -060041int dram_init(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050042{
Becky Brucecc064ed2008-10-31 17:13:32 -050043 phys_size_t dram_size = 0;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050044
45#if defined(CONFIG_SPD_EEPROM)
Kumar Galacad506c2008-08-26 15:01:35 -050046 dram_size = fsl_ddr_sdram();
Jon Loeliger5c8aa972006-04-26 17:58:56 -050047#else
Jon Loeliger4fbb09c2006-08-22 12:25:27 -050048 dram_size = fixed_sdram();
Jon Loeliger5c8aa972006-04-26 17:58:56 -050049#endif
50
Timur Tabi107e9cd2010-03-29 12:51:07 -050051 setup_ddr_bat(dram_size);
52
Wolfgang Denkf2bbb532011-07-25 10:13:53 +020053 debug(" DDR: ");
Simon Glass39f90ba2017-03-31 08:40:25 -060054 gd->ram_size = dram_size;
55
56 return 0;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050057}
58
Jon Loeliger5c8aa972006-04-26 17:58:56 -050059
Jon Loeliger5c8aa972006-04-26 17:58:56 -050060#if !defined(CONFIG_SPD_EEPROM)
Jon Loeliger465b9d82006-04-27 10:15:16 -050061/*
62 * Fixed sdram init -- doesn't use serial presence detect.
63 */
Becky Brucecc064ed2008-10-31 17:13:32 -050064phys_size_t
Jon Loeliger4fbb09c2006-08-22 12:25:27 -050065fixed_sdram(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050066{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020067#if !defined(CONFIG_SYS_RAMBOOT)
68 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
York Suna21803d2013-11-18 10:29:32 -080069 struct ccsr_ddr __iomem *ddr = &immap->im_ddr1;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050070
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020071 ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
72 ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
73 ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
74 ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
75 ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
76 ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
Peter Tyseraf5829cb2009-07-17 10:14:45 -050077 ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020078 ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2;
79 ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
80 ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT;
81 ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL;
82 ddr->sdram_ocd_cntl = CONFIG_SYS_DDR_OCD_CTRL;
83 ddr->sdram_ocd_status = CONFIG_SYS_DDR_OCD_STATUS;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050084
85#if defined (CONFIG_DDR_ECC)
86 ddr->err_disable = 0x0000008D;
87 ddr->err_sbe = 0x00ff0000;
88#endif
89 asm("sync;isync");
Jon Loeligere65e32e2006-05-31 12:44:44 -050090
Jon Loeliger5c8aa972006-04-26 17:58:56 -050091 udelay(500);
92
93#if defined (CONFIG_DDR_ECC)
94 /* Enable ECC checking */
Peter Tyseraf5829cb2009-07-17 10:14:45 -050095 ddr->sdram_cfg = (CONFIG_SYS_DDR_CONTROL | 0x20000000);
Jon Loeliger5c8aa972006-04-26 17:58:56 -050096#else
Peter Tyseraf5829cb2009-07-17 10:14:45 -050097 ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020098 ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL2;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050099#endif
100 asm("sync; isync");
Jon Loeligere65e32e2006-05-31 12:44:44 -0500101
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500102 udelay(500);
103#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200104 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500105}
106#endif /* !defined(CONFIG_SPD_EEPROM) */
107
Jon Loeliger4fbb09c2006-08-22 12:25:27 -0500108void pci_init_board(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500109{
Kumar Galadbbfb002010-12-17 10:47:36 -0600110 fsl_pcie_init_board(0);
Peter Tyser8d6f9fa2010-09-29 13:37:26 -0500111
Kumar Galae78f6652010-07-09 00:02:34 -0500112#ifdef CONFIG_PCIE1
Ed Swarthout91080f72007-08-02 14:09:49 -0500113 /*
114 * Activate ULI1575 legacy chip by performing a fake
115 * memory access. Needed to make ULI RTC work.
116 */
Kumar Galae78f6652010-07-09 00:02:34 -0500117 in_be32((unsigned *) ((char *)(CONFIG_SYS_PCIE1_MEM_VIRT
118 + CONFIG_SYS_PCIE1_MEM_SIZE - 0x1000000)));
Kumar Galae78f6652010-07-09 00:02:34 -0500119#endif /* CONFIG_PCIE1 */
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500120}
121
Jon Loeliger84640c92008-02-18 14:01:56 -0600122
Jon Loeliger6160aa42007-11-28 14:47:18 -0600123#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glass2aec3cc2014-10-23 18:58:47 -0600124int ft_board_setup(void *blob, bd_t *bd)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500125{
Becky Bruce48d3ce22008-11-07 13:46:19 -0600126 int off;
127 u64 *tmp;
Simon Glass9fbc6322014-10-23 18:58:57 -0600128 int addrcells;
Becky Bruce48d3ce22008-11-07 13:46:19 -0600129
Jon Loeliger84640c92008-02-18 14:01:56 -0600130 ft_cpu_setup(blob, bd);
Jon Loeliger6160aa42007-11-28 14:47:18 -0600131
Kumar Galad0f27d32010-07-08 22:37:44 -0500132 FT_FSL_PCI_SETUP;
Becky Bruce48d3ce22008-11-07 13:46:19 -0600133
134 /*
135 * Warn if it looks like the device tree doesn't match u-boot.
136 * This is just an estimation, based on the location of CCSR,
137 * which is defined by the "reg" property in the soc node.
138 */
139 off = fdt_path_offset(blob, "/soc8641");
Simon Glass9fbc6322014-10-23 18:58:57 -0600140 addrcells = fdt_address_cells(blob, 0);
Becky Bruce48d3ce22008-11-07 13:46:19 -0600141 tmp = (u64 *)fdt_getprop(blob, off, "reg", NULL);
142
143 if (tmp) {
144 u64 addr;
Simon Glass9fbc6322014-10-23 18:58:57 -0600145
146 if (addrcells == 1)
Becky Bruce48d3ce22008-11-07 13:46:19 -0600147 addr = *(u32 *)tmp;
Becky Bruceeccb5e72008-11-10 19:45:35 -0600148 else
149 addr = *tmp;
Becky Bruce48d3ce22008-11-07 13:46:19 -0600150
151 if (addr != CONFIG_SYS_CCSRBAR_PHYS)
152 printf("WARNING: The CCSRBAR address in your .dts "
153 "does not match the address of the CCSR "
154 "in u-boot. This means your .dts might "
155 "be old.\n");
156 }
Simon Glass2aec3cc2014-10-23 18:58:47 -0600157
158 return 0;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500159}
160#endif
161
Jon Loeliger72f8a8e2006-05-31 11:24:28 -0500162
Haiying Wang43d624d2006-07-28 12:41:18 -0400163/*
164 * get_board_sys_clk
165 * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
166 */
167
Jon Loeliger4fbb09c2006-08-22 12:25:27 -0500168unsigned long
169get_board_sys_clk(ulong dummy)
Haiying Wang43d624d2006-07-28 12:41:18 -0400170{
171 u8 i, go_bit, rd_clks;
172 ulong val = 0;
Kumar Gala146c4b22009-07-22 10:12:39 -0500173 u8 *pixis_base = (u8 *)PIXIS_BASE;
Haiying Wang43d624d2006-07-28 12:41:18 -0400174
Kumar Gala146c4b22009-07-22 10:12:39 -0500175 go_bit = in_8(pixis_base + PIXIS_VCTL);
Haiying Wang43d624d2006-07-28 12:41:18 -0400176 go_bit &= 0x01;
177
Kumar Gala146c4b22009-07-22 10:12:39 -0500178 rd_clks = in_8(pixis_base + PIXIS_VCFGEN0);
Haiying Wang43d624d2006-07-28 12:41:18 -0400179 rd_clks &= 0x1C;
180
181 /*
182 * Only if both go bit and the SCLK bit in VCFGEN0 are set
183 * should we be using the AUX register. Remember, we also set the
184 * GO bit to boot from the alternate bank on the on-board flash
185 */
186
187 if (go_bit) {
188 if (rd_clks == 0x1c)
Kumar Gala146c4b22009-07-22 10:12:39 -0500189 i = in_8(pixis_base + PIXIS_AUX);
Haiying Wang43d624d2006-07-28 12:41:18 -0400190 else
Kumar Gala146c4b22009-07-22 10:12:39 -0500191 i = in_8(pixis_base + PIXIS_SPD);
Haiying Wang43d624d2006-07-28 12:41:18 -0400192 } else {
Kumar Gala146c4b22009-07-22 10:12:39 -0500193 i = in_8(pixis_base + PIXIS_SPD);
Haiying Wang43d624d2006-07-28 12:41:18 -0400194 }
195
196 i &= 0x07;
197
198 switch (i) {
199 case 0:
200 val = 33000000;
201 break;
202 case 1:
203 val = 40000000;
204 break;
205 case 2:
206 val = 50000000;
207 break;
208 case 3:
209 val = 66000000;
210 break;
211 case 4:
212 val = 83000000;
213 break;
214 case 5:
215 val = 100000000;
216 break;
217 case 6:
218 val = 134000000;
219 break;
220 case 7:
221 val = 166000000;
222 break;
223 }
224
225 return val;
226}
Ben Warren65b86232008-08-31 21:41:08 -0700227
228int board_eth_init(bd_t *bis)
229{
230 /* Initialize TSECs */
231 cpu_eth_init(bis);
232 return pci_eth_init(bis);
233}
Peter Tyser69454402009-02-05 11:25:25 -0600234
235void board_reset(void)
236{
Kumar Gala146c4b22009-07-22 10:12:39 -0500237 u8 *pixis_base = (u8 *)PIXIS_BASE;
238
239 out_8(pixis_base + PIXIS_RST, 0);
Peter Tyser69454402009-02-05 11:25:25 -0600240
241 while (1)
242 ;
243}