blob: 3375cd621cff817fc3362b52a398af940891c5bf [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>
Simon Glassdbd79542020-05-10 11:40:11 -060024#include <linux/delay.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090025#include <linux/libfdt.h>
Jon Loeliger84640c92008-02-18 14:01:56 -060026#include <fdt_support.h>
Joe Hammane0bdea32007-08-09 15:10:53 -050027
Simon Glass39f90ba2017-03-31 08:40:25 -060028DECLARE_GLOBAL_DATA_PTR;
29
Joe Hammane0bdea32007-08-09 15:10:53 -050030long int fixed_sdram (void);
31
32int board_early_init_f (void)
33{
34 return 0;
35}
36
37int checkboard (void)
38{
39 puts ("Board: Wind River SBC8641D\n");
40
Joe Hammane0bdea32007-08-09 15:10:53 -050041 return 0;
42}
43
Simon Glassd35f3382017-04-06 12:47:05 -060044int dram_init(void)
Joe Hammane0bdea32007-08-09 15:10:53 -050045{
46 long dram_size = 0;
47
48#if defined(CONFIG_SPD_EEPROM)
Kumar Galaa7adfe32008-08-26 15:01:37 -050049 dram_size = fsl_ddr_sdram();
Joe Hammane0bdea32007-08-09 15:10:53 -050050#else
51 dram_size = fixed_sdram ();
52#endif
53
Simon Glass8f055af2020-05-10 11:40:04 -060054 debug(" DDR: ");
Simon Glass39f90ba2017-03-31 08:40:25 -060055 gd->ram_size = dram_size;
56
57 return 0;
Joe Hammane0bdea32007-08-09 15:10:53 -050058}
59
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020060#if defined(CONFIG_SYS_DRAM_TEST)
Simon Glass0ffd9db2019-12-28 10:45:06 -070061int testdram(void)
Joe Hammane0bdea32007-08-09 15:10:53 -050062{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020063 uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
64 uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
Joe Hammane0bdea32007-08-09 15:10:53 -050065 uint *p;
66
67 puts ("SDRAM test phase 1:\n");
68 for (p = pstart; p < pend; p++)
69 *p = 0xaaaaaaaa;
70
71 for (p = pstart; p < pend; p++) {
72 if (*p != 0xaaaaaaaa) {
73 printf ("SDRAM test fails at: %08x\n", (uint) p);
74 return 1;
75 }
76 }
77
78 puts ("SDRAM test phase 2:\n");
79 for (p = pstart; p < pend; p++)
80 *p = 0x55555555;
81
82 for (p = pstart; p < pend; p++) {
83 if (*p != 0x55555555) {
84 printf ("SDRAM test fails at: %08x\n", (uint) p);
85 return 1;
86 }
87 }
88
89 puts ("SDRAM test passed.\n");
90 return 0;
91}
92#endif
93
94#if !defined(CONFIG_SPD_EEPROM)
95/*
96 * Fixed sdram init -- doesn't use serial presence detect.
97 */
98long int fixed_sdram (void)
99{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200100#if !defined(CONFIG_SYS_RAMBOOT)
101 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
York Suna21803d2013-11-18 10:29:32 -0800102 volatile struct ccsr_ddr *ddr = &immap->im_ddr1;
Joe Hammane0bdea32007-08-09 15:10:53 -0500103
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200104 ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
105 ddr->cs1_bnds = CONFIG_SYS_DDR_CS1_BNDS;
106 ddr->cs2_bnds = CONFIG_SYS_DDR_CS2_BNDS;
107 ddr->cs3_bnds = CONFIG_SYS_DDR_CS3_BNDS;
108 ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
109 ddr->cs1_config = CONFIG_SYS_DDR_CS1_CONFIG;
110 ddr->cs2_config = CONFIG_SYS_DDR_CS2_CONFIG;
111 ddr->cs3_config = CONFIG_SYS_DDR_CS3_CONFIG;
112 ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
113 ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
114 ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
115 ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500116 ddr->sdram_cfg = CONFIG_SYS_DDR_CFG_1A;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200117 ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CFG_2;
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500118 ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200119 ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2;
York Suna21803d2013-11-18 10:29:32 -0800120 ddr->sdram_md_cntl = CONFIG_SYS_DDR_MODE_CTL;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200121 ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
122 ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT;
123 ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL;
Joe Hammane0bdea32007-08-09 15:10:53 -0500124
125 asm ("sync;isync");
126
Simon Glass0db4b942020-05-10 11:40:10 -0600127 udelay(500);
Joe Hammane0bdea32007-08-09 15:10:53 -0500128
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500129 ddr->sdram_cfg = CONFIG_SYS_DDR_CFG_1B;
Joe Hammane0bdea32007-08-09 15:10:53 -0500130 asm ("sync; isync");
131
Simon Glass0db4b942020-05-10 11:40:10 -0600132 udelay(500);
Joe Hammane0bdea32007-08-09 15:10:53 -0500133 ddr = &immap->im_ddr2;
134
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200135 ddr->cs0_bnds = CONFIG_SYS_DDR2_CS0_BNDS;
136 ddr->cs1_bnds = CONFIG_SYS_DDR2_CS1_BNDS;
137 ddr->cs2_bnds = CONFIG_SYS_DDR2_CS2_BNDS;
138 ddr->cs3_bnds = CONFIG_SYS_DDR2_CS3_BNDS;
139 ddr->cs0_config = CONFIG_SYS_DDR2_CS0_CONFIG;
140 ddr->cs1_config = CONFIG_SYS_DDR2_CS1_CONFIG;
141 ddr->cs2_config = CONFIG_SYS_DDR2_CS2_CONFIG;
142 ddr->cs3_config = CONFIG_SYS_DDR2_CS3_CONFIG;
143 ddr->timing_cfg_3 = CONFIG_SYS_DDR2_EXT_REFRESH;
144 ddr->timing_cfg_0 = CONFIG_SYS_DDR2_TIMING_0;
145 ddr->timing_cfg_1 = CONFIG_SYS_DDR2_TIMING_1;
146 ddr->timing_cfg_2 = CONFIG_SYS_DDR2_TIMING_2;
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500147 ddr->sdram_cfg = CONFIG_SYS_DDR2_CFG_1A;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200148 ddr->sdram_cfg_2 = CONFIG_SYS_DDR2_CFG_2;
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500149 ddr->sdram_mode = CONFIG_SYS_DDR2_MODE_1;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200150 ddr->sdram_mode_2 = CONFIG_SYS_DDR2_MODE_2;
York Suna21803d2013-11-18 10:29:32 -0800151 ddr->sdram_md_cntl = CONFIG_SYS_DDR2_MODE_CTL;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200152 ddr->sdram_interval = CONFIG_SYS_DDR2_INTERVAL;
153 ddr->sdram_data_init = CONFIG_SYS_DDR2_DATA_INIT;
154 ddr->sdram_clk_cntl = CONFIG_SYS_DDR2_CLK_CTRL;
Joe Hammane0bdea32007-08-09 15:10:53 -0500155
156 asm ("sync;isync");
157
Simon Glass0db4b942020-05-10 11:40:10 -0600158 udelay(500);
Joe Hammane0bdea32007-08-09 15:10:53 -0500159
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500160 ddr->sdram_cfg = CONFIG_SYS_DDR2_CFG_1B;
Joe Hammane0bdea32007-08-09 15:10:53 -0500161 asm ("sync; isync");
162
Simon Glass0db4b942020-05-10 11:40:10 -0600163 udelay(500);
Joe Hammane0bdea32007-08-09 15:10:53 -0500164#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200165 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
Joe Hammane0bdea32007-08-09 15:10:53 -0500166}
167#endif /* !defined(CONFIG_SPD_EEPROM) */
168
169#if defined(CONFIG_PCI)
170/*
171 * Initialize PCI Devices, report devices found.
172 */
173
Joe Hamman18f2f032007-08-11 06:54:58 -0500174void pci_init_board(void)
175{
Kumar Galacc8b5342010-12-17 10:26:44 -0600176 fsl_pcie_init_board(0);
Joe Hammane0bdea32007-08-09 15:10:53 -0500177}
Kumar Galacc8b5342010-12-17 10:26:44 -0600178#endif /* CONFIG_PCI */
Joe Hammane0bdea32007-08-09 15:10:53 -0500179
Jon Loeliger84640c92008-02-18 14:01:56 -0600180
181#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glass2aec3cc2014-10-23 18:58:47 -0600182int ft_board_setup(void *blob, bd_t *bd)
Joe Hammane0bdea32007-08-09 15:10:53 -0500183{
Jon Loeliger84640c92008-02-18 14:01:56 -0600184 ft_cpu_setup(blob, bd);
Joe Hammane0bdea32007-08-09 15:10:53 -0500185
Kumar Galad0f27d32010-07-08 22:37:44 -0500186 FT_FSL_PCI_SETUP;
Simon Glass2aec3cc2014-10-23 18:58:47 -0600187
188 return 0;
Joe Hammane0bdea32007-08-09 15:10:53 -0500189}
190#endif
191
192void sbc8641d_reset_board (void)
193{
194 puts ("Resetting board....\n");
195}
196
197/*
198 * get_board_sys_clk
199 * Clock is fixed at 1GHz on this board. Used for CONFIG_SYS_CLK_FREQ
200 */
201
202unsigned long get_board_sys_clk (ulong dummy)
203{
204 int i;
205 ulong val = 0;
206
207 i = 5;
208 i &= 0x07;
209
210 switch (i) {
211 case 0:
212 val = 33000000;
213 break;
214 case 1:
215 val = 40000000;
216 break;
217 case 2:
218 val = 50000000;
219 break;
220 case 3:
221 val = 66000000;
222 break;
223 case 4:
224 val = 83000000;
225 break;
226 case 5:
227 val = 100000000;
228 break;
229 case 6:
230 val = 134000000;
231 break;
232 case 7:
233 val = 166000000;
234 break;
235 }
236
237 return val;
238}
Peter Tyser69454402009-02-05 11:25:25 -0600239
240void board_reset(void)
241{
242#ifdef CONFIG_SYS_RESET_ADDRESS
243 ulong addr = CONFIG_SYS_RESET_ADDRESS;
244
245 /* flush and disable I/D cache */
246 __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3");
247 __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5");
248 __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4");
249 __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5");
250 __asm__ __volatile__ ("sync");
251 __asm__ __volatile__ ("mtspr 1008, 4");
252 __asm__ __volatile__ ("isync");
253 __asm__ __volatile__ ("sync");
254 __asm__ __volatile__ ("mtspr 1008, 5");
255 __asm__ __volatile__ ("isync");
256 __asm__ __volatile__ ("sync");
257
258 /*
259 * SRR0 has system reset vector, SRR1 has default MSR value
260 * rfi restores MSR from SRR1 and sets the PC to the SRR0 value
261 */
262 __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr));
263 __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4");
264 __asm__ __volatile__ ("mtspr 27, 4");
265 __asm__ __volatile__ ("rfi");
266#endif
267}