blob: fb5db6c93d71d956cb3d825623d6612ae5141b05 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Joe Hamman8ac27322007-08-09 15:10:53 -05002/*
3 * Copyright 2007 Wind River Systemes, Inc. <www.windriver.com>
4 * Copyright 2007 Embedded Specialties, Inc.
5 * Joe Hamman joe.hamman@embeddedspecialties.com
6 *
7 * Copyright 2004 Freescale Semiconductor.
8 * Jeff Brown
9 * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
10 *
11 * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
Joe Hamman8ac27322007-08-09 15:10:53 -050012 */
13
14#include <common.h>
15#include <command.h>
16#include <pci.h>
17#include <asm/processor.h>
18#include <asm/immap_86xx.h>
Kumar Galac8514622009-04-02 13:22:48 -050019#include <asm/fsl_pci.h>
York Sun5614e712013-09-30 09:22:09 -070020#include <fsl_ddr_sdram.h>
Kumar Gala5d27e022010-12-15 04:55:20 -060021#include <asm/fsl_serdes.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090022#include <linux/libfdt.h>
Jon Loeliger13f54332008-02-18 14:01:56 -060023#include <fdt_support.h>
Joe Hamman8ac27322007-08-09 15:10:53 -050024
Simon Glass088454c2017-03-31 08:40:25 -060025DECLARE_GLOBAL_DATA_PTR;
26
Joe Hamman8ac27322007-08-09 15:10:53 -050027long int fixed_sdram (void);
28
29int board_early_init_f (void)
30{
31 return 0;
32}
33
34int checkboard (void)
35{
36 puts ("Board: Wind River SBC8641D\n");
37
Joe Hamman8ac27322007-08-09 15:10:53 -050038 return 0;
39}
40
Simon Glassf1683aa2017-04-06 12:47:05 -060041int dram_init(void)
Joe Hamman8ac27322007-08-09 15:10:53 -050042{
43 long dram_size = 0;
44
45#if defined(CONFIG_SPD_EEPROM)
Kumar Gala9bd4e592008-08-26 15:01:37 -050046 dram_size = fsl_ddr_sdram();
Joe Hamman8ac27322007-08-09 15:10:53 -050047#else
48 dram_size = fixed_sdram ();
49#endif
50
Wolfgang Denk21cd5812011-07-25 10:13:53 +020051 debug (" DDR: ");
Simon Glass088454c2017-03-31 08:40:25 -060052 gd->ram_size = dram_size;
53
54 return 0;
Joe Hamman8ac27322007-08-09 15:10:53 -050055}
56
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020057#if defined(CONFIG_SYS_DRAM_TEST)
Joe Hamman8ac27322007-08-09 15:10:53 -050058int testdram (void)
59{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020060 uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
61 uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
Joe Hamman8ac27322007-08-09 15:10:53 -050062 uint *p;
63
64 puts ("SDRAM test phase 1:\n");
65 for (p = pstart; p < pend; p++)
66 *p = 0xaaaaaaaa;
67
68 for (p = pstart; p < pend; p++) {
69 if (*p != 0xaaaaaaaa) {
70 printf ("SDRAM test fails at: %08x\n", (uint) p);
71 return 1;
72 }
73 }
74
75 puts ("SDRAM test phase 2:\n");
76 for (p = pstart; p < pend; p++)
77 *p = 0x55555555;
78
79 for (p = pstart; p < pend; p++) {
80 if (*p != 0x55555555) {
81 printf ("SDRAM test fails at: %08x\n", (uint) p);
82 return 1;
83 }
84 }
85
86 puts ("SDRAM test passed.\n");
87 return 0;
88}
89#endif
90
91#if !defined(CONFIG_SPD_EEPROM)
92/*
93 * Fixed sdram init -- doesn't use serial presence detect.
94 */
95long int fixed_sdram (void)
96{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020097#if !defined(CONFIG_SYS_RAMBOOT)
98 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
York Sun9a17eb52013-11-18 10:29:32 -080099 volatile struct ccsr_ddr *ddr = &immap->im_ddr1;
Joe Hamman8ac27322007-08-09 15:10:53 -0500100
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200101 ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
102 ddr->cs1_bnds = CONFIG_SYS_DDR_CS1_BNDS;
103 ddr->cs2_bnds = CONFIG_SYS_DDR_CS2_BNDS;
104 ddr->cs3_bnds = CONFIG_SYS_DDR_CS3_BNDS;
105 ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
106 ddr->cs1_config = CONFIG_SYS_DDR_CS1_CONFIG;
107 ddr->cs2_config = CONFIG_SYS_DDR_CS2_CONFIG;
108 ddr->cs3_config = CONFIG_SYS_DDR_CS3_CONFIG;
109 ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
110 ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
111 ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
112 ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
Peter Tysere7ee23e2009-07-17 10:14:45 -0500113 ddr->sdram_cfg = CONFIG_SYS_DDR_CFG_1A;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200114 ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CFG_2;
Peter Tysere7ee23e2009-07-17 10:14:45 -0500115 ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200116 ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2;
York Sun9a17eb52013-11-18 10:29:32 -0800117 ddr->sdram_md_cntl = CONFIG_SYS_DDR_MODE_CTL;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200118 ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
119 ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT;
120 ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL;
Joe Hamman8ac27322007-08-09 15:10:53 -0500121
122 asm ("sync;isync");
123
124 udelay (500);
125
Peter Tysere7ee23e2009-07-17 10:14:45 -0500126 ddr->sdram_cfg = CONFIG_SYS_DDR_CFG_1B;
Joe Hamman8ac27322007-08-09 15:10:53 -0500127 asm ("sync; isync");
128
129 udelay (500);
130 ddr = &immap->im_ddr2;
131
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200132 ddr->cs0_bnds = CONFIG_SYS_DDR2_CS0_BNDS;
133 ddr->cs1_bnds = CONFIG_SYS_DDR2_CS1_BNDS;
134 ddr->cs2_bnds = CONFIG_SYS_DDR2_CS2_BNDS;
135 ddr->cs3_bnds = CONFIG_SYS_DDR2_CS3_BNDS;
136 ddr->cs0_config = CONFIG_SYS_DDR2_CS0_CONFIG;
137 ddr->cs1_config = CONFIG_SYS_DDR2_CS1_CONFIG;
138 ddr->cs2_config = CONFIG_SYS_DDR2_CS2_CONFIG;
139 ddr->cs3_config = CONFIG_SYS_DDR2_CS3_CONFIG;
140 ddr->timing_cfg_3 = CONFIG_SYS_DDR2_EXT_REFRESH;
141 ddr->timing_cfg_0 = CONFIG_SYS_DDR2_TIMING_0;
142 ddr->timing_cfg_1 = CONFIG_SYS_DDR2_TIMING_1;
143 ddr->timing_cfg_2 = CONFIG_SYS_DDR2_TIMING_2;
Peter Tysere7ee23e2009-07-17 10:14:45 -0500144 ddr->sdram_cfg = CONFIG_SYS_DDR2_CFG_1A;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200145 ddr->sdram_cfg_2 = CONFIG_SYS_DDR2_CFG_2;
Peter Tysere7ee23e2009-07-17 10:14:45 -0500146 ddr->sdram_mode = CONFIG_SYS_DDR2_MODE_1;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200147 ddr->sdram_mode_2 = CONFIG_SYS_DDR2_MODE_2;
York Sun9a17eb52013-11-18 10:29:32 -0800148 ddr->sdram_md_cntl = CONFIG_SYS_DDR2_MODE_CTL;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200149 ddr->sdram_interval = CONFIG_SYS_DDR2_INTERVAL;
150 ddr->sdram_data_init = CONFIG_SYS_DDR2_DATA_INIT;
151 ddr->sdram_clk_cntl = CONFIG_SYS_DDR2_CLK_CTRL;
Joe Hamman8ac27322007-08-09 15:10:53 -0500152
153 asm ("sync;isync");
154
155 udelay (500);
156
Peter Tysere7ee23e2009-07-17 10:14:45 -0500157 ddr->sdram_cfg = CONFIG_SYS_DDR2_CFG_1B;
Joe Hamman8ac27322007-08-09 15:10:53 -0500158 asm ("sync; isync");
159
160 udelay (500);
161#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200162 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
Joe Hamman8ac27322007-08-09 15:10:53 -0500163}
164#endif /* !defined(CONFIG_SPD_EEPROM) */
165
166#if defined(CONFIG_PCI)
167/*
168 * Initialize PCI Devices, report devices found.
169 */
170
Joe Hammancca34962007-08-11 06:54:58 -0500171void pci_init_board(void)
Joe Hamman8ac27322007-08-09 15:10:53 -0500172{
Kumar Galac51136e2010-12-17 10:26:44 -0600173 fsl_pcie_init_board(0);
Joe Hamman8ac27322007-08-09 15:10:53 -0500174}
Kumar Galac51136e2010-12-17 10:26:44 -0600175#endif /* CONFIG_PCI */
Joe Hamman8ac27322007-08-09 15:10:53 -0500176
Jon Loeliger13f54332008-02-18 14:01:56 -0600177
178#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glasse895a4b2014-10-23 18:58:47 -0600179int ft_board_setup(void *blob, bd_t *bd)
Joe Hamman8ac27322007-08-09 15:10:53 -0500180{
Jon Loeliger13f54332008-02-18 14:01:56 -0600181 ft_cpu_setup(blob, bd);
Joe Hamman8ac27322007-08-09 15:10:53 -0500182
Kumar Gala6525d512010-07-08 22:37:44 -0500183 FT_FSL_PCI_SETUP;
Simon Glasse895a4b2014-10-23 18:58:47 -0600184
185 return 0;
Joe Hamman8ac27322007-08-09 15:10:53 -0500186}
187#endif
188
189void sbc8641d_reset_board (void)
190{
191 puts ("Resetting board....\n");
192}
193
194/*
195 * get_board_sys_clk
196 * Clock is fixed at 1GHz on this board. Used for CONFIG_SYS_CLK_FREQ
197 */
198
199unsigned long get_board_sys_clk (ulong dummy)
200{
201 int i;
202 ulong val = 0;
203
204 i = 5;
205 i &= 0x07;
206
207 switch (i) {
208 case 0:
209 val = 33000000;
210 break;
211 case 1:
212 val = 40000000;
213 break;
214 case 2:
215 val = 50000000;
216 break;
217 case 3:
218 val = 66000000;
219 break;
220 case 4:
221 val = 83000000;
222 break;
223 case 5:
224 val = 100000000;
225 break;
226 case 6:
227 val = 134000000;
228 break;
229 case 7:
230 val = 166000000;
231 break;
232 }
233
234 return val;
235}
Peter Tyser4ef630d2009-02-05 11:25:25 -0600236
237void board_reset(void)
238{
239#ifdef CONFIG_SYS_RESET_ADDRESS
240 ulong addr = CONFIG_SYS_RESET_ADDRESS;
241
242 /* flush and disable I/D cache */
243 __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3");
244 __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5");
245 __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4");
246 __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5");
247 __asm__ __volatile__ ("sync");
248 __asm__ __volatile__ ("mtspr 1008, 4");
249 __asm__ __volatile__ ("isync");
250 __asm__ __volatile__ ("sync");
251 __asm__ __volatile__ ("mtspr 1008, 5");
252 __asm__ __volatile__ ("isync");
253 __asm__ __volatile__ ("sync");
254
255 /*
256 * SRR0 has system reset vector, SRR1 has default MSR value
257 * rfi restores MSR from SRR1 and sets the PC to the SRR0 value
258 */
259 __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr));
260 __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4");
261 __asm__ __volatile__ ("mtspr 27, 4");
262 __asm__ __volatile__ ("rfi");
263#endif
264}