blob: 882ff0bf2d1eb8b41f8d92ef5cebb732e19984c9 [file] [log] [blame]
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001/*
Kumar Galae78f6652010-07-09 00:02:34 -05002 * Copyright 2006, 2007, 2010 Freescale Semiconductor.
Jon Loeliger5c8aa972006-04-26 17:58:56 -05003 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Ed Swarthout91080f72007-08-02 14:09:49 -050014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Jon Loeliger5c8aa972006-04-26 17:58:56 -050015 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23#include <common.h>
24#include <pci.h>
25#include <asm/processor.h>
26#include <asm/immap_86xx.h>
Kumar Gala9bbd6432009-04-02 13:22:48 -050027#include <asm/fsl_pci.h>
Kumar Galacad506c2008-08-26 15:01:35 -050028#include <asm/fsl_ddr_sdram.h>
Haiying Wang57b6e9c2007-01-22 12:37:30 -060029#include <asm/io.h>
Jon Loeliger6160aa42007-11-28 14:47:18 -060030#include <libfdt.h>
31#include <fdt_support.h>
Ben Warren65b86232008-08-31 21:41:08 -070032#include <netdev.h>
Jon Loeliger5c8aa972006-04-26 17:58:56 -050033
Becky Brucecc064ed2008-10-31 17:13:32 -050034phys_size_t fixed_sdram(void);
Jon Loeliger5c8aa972006-04-26 17:58:56 -050035
Jon Loeliger4fbb09c2006-08-22 12:25:27 -050036int board_early_init_f(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050037{
Jon Loeligere65e32e2006-05-31 12:44:44 -050038 return 0;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050039}
40
Jon Loeliger4fbb09c2006-08-22 12:25:27 -050041int checkboard(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050042{
Kumar Galaaba63972009-07-15 13:45:00 -050043 u8 vboot;
44 u8 *pixis_base = (u8 *)PIXIS_BASE;
45
46 printf ("Board: MPC8641HPCN, Sys ID: 0x%02x, "
47 "Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
48 in_8(pixis_base + PIXIS_ID), in_8(pixis_base + PIXIS_VER),
49 in_8(pixis_base + PIXIS_PVER));
50
51 vboot = in_8(pixis_base + PIXIS_VBOOT);
52 if (vboot & PIXIS_VBOOT_FMAP)
53 printf ("vBank: %d\n", ((vboot & PIXIS_VBOOT_FBANK) >> 6));
54 else
55 puts ("Promjet\n");
56
Becky Bruce977d7052009-02-12 10:43:32 -060057#ifdef CONFIG_PHYS_64BIT
58 printf (" 36-bit physical address map\n");
59#endif
Jon Loeliger5c8aa972006-04-26 17:58:56 -050060 return 0;
61}
62
Becky Brucebd99ae72008-06-09 16:03:40 -050063phys_size_t
Jon Loeliger5c8aa972006-04-26 17:58:56 -050064initdram(int board_type)
65{
Becky Brucecc064ed2008-10-31 17:13:32 -050066 phys_size_t dram_size = 0;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050067
68#if defined(CONFIG_SPD_EEPROM)
Kumar Galacad506c2008-08-26 15:01:35 -050069 dram_size = fsl_ddr_sdram();
Jon Loeliger5c8aa972006-04-26 17:58:56 -050070#else
Jon Loeliger4fbb09c2006-08-22 12:25:27 -050071 dram_size = fixed_sdram();
Jon Loeliger5c8aa972006-04-26 17:58:56 -050072#endif
73
Timur Tabi107e9cd2010-03-29 12:51:07 -050074 setup_ddr_bat(dram_size);
75
Jon Loeliger5c8aa972006-04-26 17:58:56 -050076 puts(" DDR: ");
77 return dram_size;
78}
79
Jon Loeliger5c8aa972006-04-26 17:58:56 -050080
Jon Loeliger5c8aa972006-04-26 17:58:56 -050081#if !defined(CONFIG_SPD_EEPROM)
Jon Loeliger465b9d82006-04-27 10:15:16 -050082/*
83 * Fixed sdram init -- doesn't use serial presence detect.
84 */
Becky Brucecc064ed2008-10-31 17:13:32 -050085phys_size_t
Jon Loeliger4fbb09c2006-08-22 12:25:27 -050086fixed_sdram(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050087{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020088#if !defined(CONFIG_SYS_RAMBOOT)
89 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Jon Loeliger4fbb09c2006-08-22 12:25:27 -050090 volatile ccsr_ddr_t *ddr = &immap->im_ddr1;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050091
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020092 ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
93 ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
94 ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
95 ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
96 ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
97 ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
Peter Tyseraf5829cb2009-07-17 10:14:45 -050098 ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020099 ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2;
100 ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
101 ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT;
102 ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL;
103 ddr->sdram_ocd_cntl = CONFIG_SYS_DDR_OCD_CTRL;
104 ddr->sdram_ocd_status = CONFIG_SYS_DDR_OCD_STATUS;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500105
106#if defined (CONFIG_DDR_ECC)
107 ddr->err_disable = 0x0000008D;
108 ddr->err_sbe = 0x00ff0000;
109#endif
110 asm("sync;isync");
Jon Loeligere65e32e2006-05-31 12:44:44 -0500111
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500112 udelay(500);
113
114#if defined (CONFIG_DDR_ECC)
115 /* Enable ECC checking */
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500116 ddr->sdram_cfg = (CONFIG_SYS_DDR_CONTROL | 0x20000000);
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500117#else
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500118 ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200119 ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL2;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500120#endif
121 asm("sync; isync");
Jon Loeligere65e32e2006-05-31 12:44:44 -0500122
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500123 udelay(500);
124#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200125 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500126}
127#endif /* !defined(CONFIG_SPD_EEPROM) */
128
129
130#if defined(CONFIG_PCI)
Kumar Galae78f6652010-07-09 00:02:34 -0500131static struct pci_controller pcie1_hose;
Jon Loeliger4fbb09c2006-08-22 12:25:27 -0500132#endif /* CONFIG_PCI */
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500133
Kumar Galae78f6652010-07-09 00:02:34 -0500134#ifdef CONFIG_PCIE2
135static struct pci_controller pcie2_hose;
136#endif /* CONFIG_PCIE2 */
Ed Swarthout91080f72007-08-02 14:09:49 -0500137
138int first_free_busno = 0;
139
Jon Loeliger4fbb09c2006-08-22 12:25:27 -0500140void pci_init_board(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500141{
Peter Tyser8d6f9fa2010-09-29 13:37:26 -0500142 struct fsl_pci_info pci_info[2];
143 int pcie_ep;
144 int num = 0;
145
Kumar Galae78f6652010-07-09 00:02:34 -0500146#ifdef CONFIG_PCIE1
Becky Bruce6c2bec32008-10-31 17:14:14 -0500147 volatile immap_t *immap = (immap_t *) CONFIG_SYS_CCSRBAR;
148 volatile ccsr_gur_t *gur = &immap->im_gur;
Peter Tyser8d6f9fa2010-09-29 13:37:26 -0500149 uint devdisr = in_be32(&gur->devdisr);
Becky Bruce6c2bec32008-10-31 17:14:14 -0500150 uint io_sel = (gur->pordevsr & MPC8641_PORDEVSR_IO_SEL)
151 >> MPC8641_PORDEVSR_IO_SEL_SHIFT;
Kumar Gala666ced12009-09-02 09:03:08 -0500152 int pcie_configured = is_fsl_pci_cfg(LAW_TRGT_IF_PCIE_1, io_sel);
Kumar Gala7772ccd2008-10-22 14:38:55 -0500153
Kumar Gala666ced12009-09-02 09:03:08 -0500154 if (pcie_configured && !(devdisr & MPC86xx_DEVDISR_PCIEX1)) {
Peter Tyser8d6f9fa2010-09-29 13:37:26 -0500155 SET_STD_PCIE_INFO(pci_info[num], 1);
156 pcie_ep = fsl_setup_hose(&pcie1_hose, pci_info[num].regs);
Peter Tyser2b91f712010-10-29 17:59:24 -0500157 printf("PCIE1: connected to ULI as %s (base addr %lx)\n",
158 pcie_ep ? "Endpoint" : "Root Complex",
159 pci_info[num].regs);
Peter Tyser8d6f9fa2010-09-29 13:37:26 -0500160 first_free_busno = fsl_pci_init_port(&pci_info[num++],
161 &pcie1_hose, first_free_busno);
Ed Swarthout91080f72007-08-02 14:09:49 -0500162
163 /*
164 * Activate ULI1575 legacy chip by performing a fake
165 * memory access. Needed to make ULI RTC work.
166 */
Kumar Galae78f6652010-07-09 00:02:34 -0500167 in_be32((unsigned *) ((char *)(CONFIG_SYS_PCIE1_MEM_VIRT
168 + CONFIG_SYS_PCIE1_MEM_SIZE - 0x1000000)));
Ed Swarthout91080f72007-08-02 14:09:49 -0500169
170 } else {
Peter Tyser2b91f712010-10-29 17:59:24 -0500171 puts("PCIE1: disabled\n");
Ed Swarthout91080f72007-08-02 14:09:49 -0500172 }
Ed Swarthout91080f72007-08-02 14:09:49 -0500173#else
Peter Tyser2b91f712010-10-29 17:59:24 -0500174 puts("PCIE1: disabled\n");
Kumar Galae78f6652010-07-09 00:02:34 -0500175#endif /* CONFIG_PCIE1 */
Ed Swarthout91080f72007-08-02 14:09:49 -0500176
Kumar Galae78f6652010-07-09 00:02:34 -0500177#ifdef CONFIG_PCIE2
Peter Tyser8d6f9fa2010-09-29 13:37:26 -0500178 SET_STD_PCIE_INFO(pci_info[num], 2);
179 pcie_ep = fsl_setup_hose(&pcie2_hose, pci_info[num].regs);
Peter Tyser2b91f712010-10-29 17:59:24 -0500180 printf("PCIE2: connected as %s (base addr %lx)\n",
181 pcie_ep ? "Endpoint" : "Root Complex",
182 pci_info[num].regs);
Peter Tyser8d6f9fa2010-09-29 13:37:26 -0500183 first_free_busno = fsl_pci_init_port(&pci_info[num++],
184 &pcie2_hose, first_free_busno);
Ed Swarthout91080f72007-08-02 14:09:49 -0500185#else
Peter Tyser2b91f712010-10-29 17:59:24 -0500186 puts("PCIE2: disabled\n");
Kumar Galae78f6652010-07-09 00:02:34 -0500187#endif /* CONFIG_PCIE2 */
Ed Swarthout91080f72007-08-02 14:09:49 -0500188
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500189}
190
Jon Loeliger84640c92008-02-18 14:01:56 -0600191
Jon Loeliger6160aa42007-11-28 14:47:18 -0600192#if defined(CONFIG_OF_BOARD_SETUP)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500193void
194ft_board_setup(void *blob, bd_t *bd)
195{
Becky Bruce48d3ce22008-11-07 13:46:19 -0600196 int off;
197 u64 *tmp;
198 u32 *addrcells;
199
Jon Loeliger84640c92008-02-18 14:01:56 -0600200 ft_cpu_setup(blob, bd);
Jon Loeliger6160aa42007-11-28 14:47:18 -0600201
Kumar Galad0f27d32010-07-08 22:37:44 -0500202 FT_FSL_PCI_SETUP;
Becky Bruce48d3ce22008-11-07 13:46:19 -0600203
204 /*
205 * Warn if it looks like the device tree doesn't match u-boot.
206 * This is just an estimation, based on the location of CCSR,
207 * which is defined by the "reg" property in the soc node.
208 */
209 off = fdt_path_offset(blob, "/soc8641");
210 addrcells = (u32 *)fdt_getprop(blob, 0, "#address-cells", NULL);
211 tmp = (u64 *)fdt_getprop(blob, off, "reg", NULL);
212
213 if (tmp) {
214 u64 addr;
Becky Bruceeccb5e72008-11-10 19:45:35 -0600215 if (addrcells && (*addrcells == 1))
Becky Bruce48d3ce22008-11-07 13:46:19 -0600216 addr = *(u32 *)tmp;
Becky Bruceeccb5e72008-11-10 19:45:35 -0600217 else
218 addr = *tmp;
Becky Bruce48d3ce22008-11-07 13:46:19 -0600219
220 if (addr != CONFIG_SYS_CCSRBAR_PHYS)
221 printf("WARNING: The CCSRBAR address in your .dts "
222 "does not match the address of the CCSR "
223 "in u-boot. This means your .dts might "
224 "be old.\n");
225 }
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500226}
227#endif
228
Jon Loeliger72f8a8e2006-05-31 11:24:28 -0500229
Haiying Wang43d624d2006-07-28 12:41:18 -0400230/*
231 * get_board_sys_clk
232 * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
233 */
234
Jon Loeliger4fbb09c2006-08-22 12:25:27 -0500235unsigned long
236get_board_sys_clk(ulong dummy)
Haiying Wang43d624d2006-07-28 12:41:18 -0400237{
238 u8 i, go_bit, rd_clks;
239 ulong val = 0;
Kumar Gala146c4b22009-07-22 10:12:39 -0500240 u8 *pixis_base = (u8 *)PIXIS_BASE;
Haiying Wang43d624d2006-07-28 12:41:18 -0400241
Kumar Gala146c4b22009-07-22 10:12:39 -0500242 go_bit = in_8(pixis_base + PIXIS_VCTL);
Haiying Wang43d624d2006-07-28 12:41:18 -0400243 go_bit &= 0x01;
244
Kumar Gala146c4b22009-07-22 10:12:39 -0500245 rd_clks = in_8(pixis_base + PIXIS_VCFGEN0);
Haiying Wang43d624d2006-07-28 12:41:18 -0400246 rd_clks &= 0x1C;
247
248 /*
249 * Only if both go bit and the SCLK bit in VCFGEN0 are set
250 * should we be using the AUX register. Remember, we also set the
251 * GO bit to boot from the alternate bank on the on-board flash
252 */
253
254 if (go_bit) {
255 if (rd_clks == 0x1c)
Kumar Gala146c4b22009-07-22 10:12:39 -0500256 i = in_8(pixis_base + PIXIS_AUX);
Haiying Wang43d624d2006-07-28 12:41:18 -0400257 else
Kumar Gala146c4b22009-07-22 10:12:39 -0500258 i = in_8(pixis_base + PIXIS_SPD);
Haiying Wang43d624d2006-07-28 12:41:18 -0400259 } else {
Kumar Gala146c4b22009-07-22 10:12:39 -0500260 i = in_8(pixis_base + PIXIS_SPD);
Haiying Wang43d624d2006-07-28 12:41:18 -0400261 }
262
263 i &= 0x07;
264
265 switch (i) {
266 case 0:
267 val = 33000000;
268 break;
269 case 1:
270 val = 40000000;
271 break;
272 case 2:
273 val = 50000000;
274 break;
275 case 3:
276 val = 66000000;
277 break;
278 case 4:
279 val = 83000000;
280 break;
281 case 5:
282 val = 100000000;
283 break;
284 case 6:
285 val = 134000000;
286 break;
287 case 7:
288 val = 166000000;
289 break;
290 }
291
292 return val;
293}
Ben Warren65b86232008-08-31 21:41:08 -0700294
295int board_eth_init(bd_t *bis)
296{
297 /* Initialize TSECs */
298 cpu_eth_init(bis);
299 return pci_eth_init(bis);
300}
Peter Tyser69454402009-02-05 11:25:25 -0600301
302void board_reset(void)
303{
Kumar Gala146c4b22009-07-22 10:12:39 -0500304 u8 *pixis_base = (u8 *)PIXIS_BASE;
305
306 out_8(pixis_base + PIXIS_RST, 0);
Peter Tyser69454402009-02-05 11:25:25 -0600307
308 while (1)
309 ;
310}
Becky Brucebd9c0cf2009-03-31 18:38:37 -0500311
Kumar Gala56d150e2009-03-31 23:02:38 -0500312#ifdef CONFIG_MP
Becky Brucebd9c0cf2009-03-31 18:38:37 -0500313extern void cpu_mp_lmb_reserve(struct lmb *lmb);
314
315void board_lmb_reserve(struct lmb *lmb)
316{
317 cpu_mp_lmb_reserve(lmb);
318}
319#endif