blob: 91867d4f3d2d9e6c45d3e37bc993006cd644fa1b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Joe Hammane0bdea32007-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 Hammane0bdea32007-08-09 15:10:53 -050012 */
13
14#include <common.h>
15#include <command.h>
Simon Glass18afe102019-11-14 12:57:47 -070016#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060017#include <log.h>
Joe Hammane0bdea32007-08-09 15:10:53 -050018#include <pci.h>
19#include <asm/processor.h>
20#include <asm/immap_86xx.h>
Kumar Gala9bbd6432009-04-02 13:22:48 -050021#include <asm/fsl_pci.h>
York Sunf0626592013-09-30 09:22:09 -070022#include <fsl_ddr_sdram.h>
Kumar Gala3d020382010-12-15 04:55:20 -060023#include <asm/fsl_serdes.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090024#include <linux/libfdt.h>
Jon Loeliger84640c92008-02-18 14:01:56 -060025#include <fdt_support.h>
Joe Hammane0bdea32007-08-09 15:10:53 -050026
Simon Glass39f90ba2017-03-31 08:40:25 -060027DECLARE_GLOBAL_DATA_PTR;
28
Joe Hammane0bdea32007-08-09 15:10:53 -050029long int fixed_sdram (void);
30
31int board_early_init_f (void)
32{
33 return 0;
34}
35
36int checkboard (void)
37{
38 puts ("Board: Wind River SBC8641D\n");
39
Joe Hammane0bdea32007-08-09 15:10:53 -050040 return 0;
41}
42
Simon Glassd35f3382017-04-06 12:47:05 -060043int dram_init(void)
Joe Hammane0bdea32007-08-09 15:10:53 -050044{
45 long dram_size = 0;
46
47#if defined(CONFIG_SPD_EEPROM)
Kumar Galaa7adfe32008-08-26 15:01:37 -050048 dram_size = fsl_ddr_sdram();
Joe Hammane0bdea32007-08-09 15:10:53 -050049#else
50 dram_size = fixed_sdram ();
51#endif
52
Simon Glass8f055af2020-05-10 11:40:04 -060053 debug(" DDR: ");
Simon Glass39f90ba2017-03-31 08:40:25 -060054 gd->ram_size = dram_size;
55
56 return 0;
Joe Hammane0bdea32007-08-09 15:10:53 -050057}
58
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020059#if defined(CONFIG_SYS_DRAM_TEST)
Simon Glass0ffd9db2019-12-28 10:45:06 -070060int testdram(void)
Joe Hammane0bdea32007-08-09 15:10:53 -050061{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020062 uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
63 uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
Joe Hammane0bdea32007-08-09 15:10:53 -050064 uint *p;
65
66 puts ("SDRAM test phase 1:\n");
67 for (p = pstart; p < pend; p++)
68 *p = 0xaaaaaaaa;
69
70 for (p = pstart; p < pend; p++) {
71 if (*p != 0xaaaaaaaa) {
72 printf ("SDRAM test fails at: %08x\n", (uint) p);
73 return 1;
74 }
75 }
76
77 puts ("SDRAM test phase 2:\n");
78 for (p = pstart; p < pend; p++)
79 *p = 0x55555555;
80
81 for (p = pstart; p < pend; p++) {
82 if (*p != 0x55555555) {
83 printf ("SDRAM test fails at: %08x\n", (uint) p);
84 return 1;
85 }
86 }
87
88 puts ("SDRAM test passed.\n");
89 return 0;
90}
91#endif
92
93#if !defined(CONFIG_SPD_EEPROM)
94/*
95 * Fixed sdram init -- doesn't use serial presence detect.
96 */
97long int fixed_sdram (void)
98{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020099#if !defined(CONFIG_SYS_RAMBOOT)
100 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
York Suna21803d2013-11-18 10:29:32 -0800101 volatile struct ccsr_ddr *ddr = &immap->im_ddr1;
Joe Hammane0bdea32007-08-09 15:10:53 -0500102
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200103 ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
104 ddr->cs1_bnds = CONFIG_SYS_DDR_CS1_BNDS;
105 ddr->cs2_bnds = CONFIG_SYS_DDR_CS2_BNDS;
106 ddr->cs3_bnds = CONFIG_SYS_DDR_CS3_BNDS;
107 ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
108 ddr->cs1_config = CONFIG_SYS_DDR_CS1_CONFIG;
109 ddr->cs2_config = CONFIG_SYS_DDR_CS2_CONFIG;
110 ddr->cs3_config = CONFIG_SYS_DDR_CS3_CONFIG;
111 ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
112 ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
113 ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
114 ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500115 ddr->sdram_cfg = CONFIG_SYS_DDR_CFG_1A;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200116 ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CFG_2;
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500117 ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200118 ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2;
York Suna21803d2013-11-18 10:29:32 -0800119 ddr->sdram_md_cntl = CONFIG_SYS_DDR_MODE_CTL;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200120 ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
121 ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT;
122 ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL;
Joe Hammane0bdea32007-08-09 15:10:53 -0500123
124 asm ("sync;isync");
125
Simon Glass0db4b942020-05-10 11:40:10 -0600126 udelay(500);
Joe Hammane0bdea32007-08-09 15:10:53 -0500127
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500128 ddr->sdram_cfg = CONFIG_SYS_DDR_CFG_1B;
Joe Hammane0bdea32007-08-09 15:10:53 -0500129 asm ("sync; isync");
130
Simon Glass0db4b942020-05-10 11:40:10 -0600131 udelay(500);
Joe Hammane0bdea32007-08-09 15:10:53 -0500132 ddr = &immap->im_ddr2;
133
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200134 ddr->cs0_bnds = CONFIG_SYS_DDR2_CS0_BNDS;
135 ddr->cs1_bnds = CONFIG_SYS_DDR2_CS1_BNDS;
136 ddr->cs2_bnds = CONFIG_SYS_DDR2_CS2_BNDS;
137 ddr->cs3_bnds = CONFIG_SYS_DDR2_CS3_BNDS;
138 ddr->cs0_config = CONFIG_SYS_DDR2_CS0_CONFIG;
139 ddr->cs1_config = CONFIG_SYS_DDR2_CS1_CONFIG;
140 ddr->cs2_config = CONFIG_SYS_DDR2_CS2_CONFIG;
141 ddr->cs3_config = CONFIG_SYS_DDR2_CS3_CONFIG;
142 ddr->timing_cfg_3 = CONFIG_SYS_DDR2_EXT_REFRESH;
143 ddr->timing_cfg_0 = CONFIG_SYS_DDR2_TIMING_0;
144 ddr->timing_cfg_1 = CONFIG_SYS_DDR2_TIMING_1;
145 ddr->timing_cfg_2 = CONFIG_SYS_DDR2_TIMING_2;
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500146 ddr->sdram_cfg = CONFIG_SYS_DDR2_CFG_1A;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200147 ddr->sdram_cfg_2 = CONFIG_SYS_DDR2_CFG_2;
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500148 ddr->sdram_mode = CONFIG_SYS_DDR2_MODE_1;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200149 ddr->sdram_mode_2 = CONFIG_SYS_DDR2_MODE_2;
York Suna21803d2013-11-18 10:29:32 -0800150 ddr->sdram_md_cntl = CONFIG_SYS_DDR2_MODE_CTL;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200151 ddr->sdram_interval = CONFIG_SYS_DDR2_INTERVAL;
152 ddr->sdram_data_init = CONFIG_SYS_DDR2_DATA_INIT;
153 ddr->sdram_clk_cntl = CONFIG_SYS_DDR2_CLK_CTRL;
Joe Hammane0bdea32007-08-09 15:10:53 -0500154
155 asm ("sync;isync");
156
Simon Glass0db4b942020-05-10 11:40:10 -0600157 udelay(500);
Joe Hammane0bdea32007-08-09 15:10:53 -0500158
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500159 ddr->sdram_cfg = CONFIG_SYS_DDR2_CFG_1B;
Joe Hammane0bdea32007-08-09 15:10:53 -0500160 asm ("sync; isync");
161
Simon Glass0db4b942020-05-10 11:40:10 -0600162 udelay(500);
Joe Hammane0bdea32007-08-09 15:10:53 -0500163#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200164 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
Joe Hammane0bdea32007-08-09 15:10:53 -0500165}
166#endif /* !defined(CONFIG_SPD_EEPROM) */
167
168#if defined(CONFIG_PCI)
169/*
170 * Initialize PCI Devices, report devices found.
171 */
172
Joe Hamman18f2f032007-08-11 06:54:58 -0500173void pci_init_board(void)
174{
Kumar Galacc8b5342010-12-17 10:26:44 -0600175 fsl_pcie_init_board(0);
Joe Hammane0bdea32007-08-09 15:10:53 -0500176}
Kumar Galacc8b5342010-12-17 10:26:44 -0600177#endif /* CONFIG_PCI */
Joe Hammane0bdea32007-08-09 15:10:53 -0500178
Jon Loeliger84640c92008-02-18 14:01:56 -0600179
180#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glass2aec3cc2014-10-23 18:58:47 -0600181int ft_board_setup(void *blob, bd_t *bd)
Joe Hammane0bdea32007-08-09 15:10:53 -0500182{
Jon Loeliger84640c92008-02-18 14:01:56 -0600183 ft_cpu_setup(blob, bd);
Joe Hammane0bdea32007-08-09 15:10:53 -0500184
Kumar Galad0f27d32010-07-08 22:37:44 -0500185 FT_FSL_PCI_SETUP;
Simon Glass2aec3cc2014-10-23 18:58:47 -0600186
187 return 0;
Joe Hammane0bdea32007-08-09 15:10:53 -0500188}
189#endif
190
191void sbc8641d_reset_board (void)
192{
193 puts ("Resetting board....\n");
194}
195
196/*
197 * get_board_sys_clk
198 * Clock is fixed at 1GHz on this board. Used for CONFIG_SYS_CLK_FREQ
199 */
200
201unsigned long get_board_sys_clk (ulong dummy)
202{
203 int i;
204 ulong val = 0;
205
206 i = 5;
207 i &= 0x07;
208
209 switch (i) {
210 case 0:
211 val = 33000000;
212 break;
213 case 1:
214 val = 40000000;
215 break;
216 case 2:
217 val = 50000000;
218 break;
219 case 3:
220 val = 66000000;
221 break;
222 case 4:
223 val = 83000000;
224 break;
225 case 5:
226 val = 100000000;
227 break;
228 case 6:
229 val = 134000000;
230 break;
231 case 7:
232 val = 166000000;
233 break;
234 }
235
236 return val;
237}
Peter Tyser69454402009-02-05 11:25:25 -0600238
239void board_reset(void)
240{
241#ifdef CONFIG_SYS_RESET_ADDRESS
242 ulong addr = CONFIG_SYS_RESET_ADDRESS;
243
244 /* flush and disable I/D cache */
245 __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3");
246 __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5");
247 __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4");
248 __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5");
249 __asm__ __volatile__ ("sync");
250 __asm__ __volatile__ ("mtspr 1008, 4");
251 __asm__ __volatile__ ("isync");
252 __asm__ __volatile__ ("sync");
253 __asm__ __volatile__ ("mtspr 1008, 5");
254 __asm__ __volatile__ ("isync");
255 __asm__ __volatile__ ("sync");
256
257 /*
258 * SRR0 has system reset vector, SRR1 has default MSR value
259 * rfi restores MSR from SRR1 and sets the PC to the SRR0 value
260 */
261 __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr));
262 __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4");
263 __asm__ __volatile__ ("mtspr 27, 4");
264 __asm__ __volatile__ ("rfi");
265#endif
266}