blob: a67092daf47ff43b09d4362f7bcaae308994c912 [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>
Simon Glass3ba929a2020-10-30 21:38:53 -060019#include <asm/global_data.h>
Joe Hammane0bdea32007-08-09 15:10:53 -050020#include <asm/processor.h>
21#include <asm/immap_86xx.h>
Kumar Gala9bbd6432009-04-02 13:22:48 -050022#include <asm/fsl_pci.h>
York Sunf0626592013-09-30 09:22:09 -070023#include <fsl_ddr_sdram.h>
Kumar Gala3d020382010-12-15 04:55:20 -060024#include <asm/fsl_serdes.h>
Simon Glassdbd79542020-05-10 11:40:11 -060025#include <linux/delay.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090026#include <linux/libfdt.h>
Jon Loeliger84640c92008-02-18 14:01:56 -060027#include <fdt_support.h>
Joe Hammane0bdea32007-08-09 15:10:53 -050028
Simon Glass39f90ba2017-03-31 08:40:25 -060029DECLARE_GLOBAL_DATA_PTR;
30
Joe Hammane0bdea32007-08-09 15:10:53 -050031long int fixed_sdram (void);
32
33int board_early_init_f (void)
34{
35 return 0;
36}
37
38int checkboard (void)
39{
40 puts ("Board: Wind River SBC8641D\n");
41
Joe Hammane0bdea32007-08-09 15:10:53 -050042 return 0;
43}
44
Simon Glassd35f3382017-04-06 12:47:05 -060045int dram_init(void)
Joe Hammane0bdea32007-08-09 15:10:53 -050046{
47 long dram_size = 0;
48
49#if defined(CONFIG_SPD_EEPROM)
Kumar Galaa7adfe32008-08-26 15:01:37 -050050 dram_size = fsl_ddr_sdram();
Joe Hammane0bdea32007-08-09 15:10:53 -050051#else
52 dram_size = fixed_sdram ();
53#endif
54
Simon Glass8f055af2020-05-10 11:40:04 -060055 debug(" DDR: ");
Simon Glass39f90ba2017-03-31 08:40:25 -060056 gd->ram_size = dram_size;
57
58 return 0;
Joe Hammane0bdea32007-08-09 15:10:53 -050059}
60
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020061#if defined(CONFIG_SYS_DRAM_TEST)
Simon Glass0ffd9db2019-12-28 10:45:06 -070062int testdram(void)
Joe Hammane0bdea32007-08-09 15:10:53 -050063{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020064 uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
65 uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
Joe Hammane0bdea32007-08-09 15:10:53 -050066 uint *p;
67
68 puts ("SDRAM test phase 1:\n");
69 for (p = pstart; p < pend; p++)
70 *p = 0xaaaaaaaa;
71
72 for (p = pstart; p < pend; p++) {
73 if (*p != 0xaaaaaaaa) {
74 printf ("SDRAM test fails at: %08x\n", (uint) p);
75 return 1;
76 }
77 }
78
79 puts ("SDRAM test phase 2:\n");
80 for (p = pstart; p < pend; p++)
81 *p = 0x55555555;
82
83 for (p = pstart; p < pend; p++) {
84 if (*p != 0x55555555) {
85 printf ("SDRAM test fails at: %08x\n", (uint) p);
86 return 1;
87 }
88 }
89
90 puts ("SDRAM test passed.\n");
91 return 0;
92}
93#endif
94
95#if !defined(CONFIG_SPD_EEPROM)
96/*
97 * Fixed sdram init -- doesn't use serial presence detect.
98 */
99long int fixed_sdram (void)
100{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200101#if !defined(CONFIG_SYS_RAMBOOT)
102 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
York Suna21803d2013-11-18 10:29:32 -0800103 volatile struct ccsr_ddr *ddr = &immap->im_ddr1;
Joe Hammane0bdea32007-08-09 15:10:53 -0500104
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200105 ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
106 ddr->cs1_bnds = CONFIG_SYS_DDR_CS1_BNDS;
107 ddr->cs2_bnds = CONFIG_SYS_DDR_CS2_BNDS;
108 ddr->cs3_bnds = CONFIG_SYS_DDR_CS3_BNDS;
109 ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
110 ddr->cs1_config = CONFIG_SYS_DDR_CS1_CONFIG;
111 ddr->cs2_config = CONFIG_SYS_DDR_CS2_CONFIG;
112 ddr->cs3_config = CONFIG_SYS_DDR_CS3_CONFIG;
113 ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
114 ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
115 ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
116 ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500117 ddr->sdram_cfg = CONFIG_SYS_DDR_CFG_1A;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200118 ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CFG_2;
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500119 ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200120 ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2;
York Suna21803d2013-11-18 10:29:32 -0800121 ddr->sdram_md_cntl = CONFIG_SYS_DDR_MODE_CTL;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200122 ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
123 ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT;
124 ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL;
Joe Hammane0bdea32007-08-09 15:10:53 -0500125
126 asm ("sync;isync");
127
Simon Glass0db4b942020-05-10 11:40:10 -0600128 udelay(500);
Joe Hammane0bdea32007-08-09 15:10:53 -0500129
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500130 ddr->sdram_cfg = CONFIG_SYS_DDR_CFG_1B;
Joe Hammane0bdea32007-08-09 15:10:53 -0500131 asm ("sync; isync");
132
Simon Glass0db4b942020-05-10 11:40:10 -0600133 udelay(500);
Joe Hammane0bdea32007-08-09 15:10:53 -0500134 ddr = &immap->im_ddr2;
135
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200136 ddr->cs0_bnds = CONFIG_SYS_DDR2_CS0_BNDS;
137 ddr->cs1_bnds = CONFIG_SYS_DDR2_CS1_BNDS;
138 ddr->cs2_bnds = CONFIG_SYS_DDR2_CS2_BNDS;
139 ddr->cs3_bnds = CONFIG_SYS_DDR2_CS3_BNDS;
140 ddr->cs0_config = CONFIG_SYS_DDR2_CS0_CONFIG;
141 ddr->cs1_config = CONFIG_SYS_DDR2_CS1_CONFIG;
142 ddr->cs2_config = CONFIG_SYS_DDR2_CS2_CONFIG;
143 ddr->cs3_config = CONFIG_SYS_DDR2_CS3_CONFIG;
144 ddr->timing_cfg_3 = CONFIG_SYS_DDR2_EXT_REFRESH;
145 ddr->timing_cfg_0 = CONFIG_SYS_DDR2_TIMING_0;
146 ddr->timing_cfg_1 = CONFIG_SYS_DDR2_TIMING_1;
147 ddr->timing_cfg_2 = CONFIG_SYS_DDR2_TIMING_2;
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500148 ddr->sdram_cfg = CONFIG_SYS_DDR2_CFG_1A;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200149 ddr->sdram_cfg_2 = CONFIG_SYS_DDR2_CFG_2;
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500150 ddr->sdram_mode = CONFIG_SYS_DDR2_MODE_1;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200151 ddr->sdram_mode_2 = CONFIG_SYS_DDR2_MODE_2;
York Suna21803d2013-11-18 10:29:32 -0800152 ddr->sdram_md_cntl = CONFIG_SYS_DDR2_MODE_CTL;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200153 ddr->sdram_interval = CONFIG_SYS_DDR2_INTERVAL;
154 ddr->sdram_data_init = CONFIG_SYS_DDR2_DATA_INIT;
155 ddr->sdram_clk_cntl = CONFIG_SYS_DDR2_CLK_CTRL;
Joe Hammane0bdea32007-08-09 15:10:53 -0500156
157 asm ("sync;isync");
158
Simon Glass0db4b942020-05-10 11:40:10 -0600159 udelay(500);
Joe Hammane0bdea32007-08-09 15:10:53 -0500160
Peter Tyseraf5829cb2009-07-17 10:14:45 -0500161 ddr->sdram_cfg = CONFIG_SYS_DDR2_CFG_1B;
Joe Hammane0bdea32007-08-09 15:10:53 -0500162 asm ("sync; isync");
163
Simon Glass0db4b942020-05-10 11:40:10 -0600164 udelay(500);
Joe Hammane0bdea32007-08-09 15:10:53 -0500165#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200166 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
Joe Hammane0bdea32007-08-09 15:10:53 -0500167}
168#endif /* !defined(CONFIG_SPD_EEPROM) */
169
170#if defined(CONFIG_PCI)
171/*
172 * Initialize PCI Devices, report devices found.
173 */
174
Joe Hamman18f2f032007-08-11 06:54:58 -0500175void pci_init_board(void)
176{
Kumar Galacc8b5342010-12-17 10:26:44 -0600177 fsl_pcie_init_board(0);
Joe Hammane0bdea32007-08-09 15:10:53 -0500178}
Kumar Galacc8b5342010-12-17 10:26:44 -0600179#endif /* CONFIG_PCI */
Joe Hammane0bdea32007-08-09 15:10:53 -0500180
Jon Loeliger84640c92008-02-18 14:01:56 -0600181
182#if defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900183int ft_board_setup(void *blob, struct bd_info *bd)
Joe Hammane0bdea32007-08-09 15:10:53 -0500184{
Jon Loeliger84640c92008-02-18 14:01:56 -0600185 ft_cpu_setup(blob, bd);
Joe Hammane0bdea32007-08-09 15:10:53 -0500186
Kumar Galad0f27d32010-07-08 22:37:44 -0500187 FT_FSL_PCI_SETUP;
Simon Glass2aec3cc2014-10-23 18:58:47 -0600188
189 return 0;
Joe Hammane0bdea32007-08-09 15:10:53 -0500190}
191#endif
192
193void sbc8641d_reset_board (void)
194{
195 puts ("Resetting board....\n");
196}
197
198/*
199 * get_board_sys_clk
200 * Clock is fixed at 1GHz on this board. Used for CONFIG_SYS_CLK_FREQ
201 */
202
203unsigned long get_board_sys_clk (ulong dummy)
204{
205 int i;
206 ulong val = 0;
207
208 i = 5;
209 i &= 0x07;
210
211 switch (i) {
212 case 0:
213 val = 33000000;
214 break;
215 case 1:
216 val = 40000000;
217 break;
218 case 2:
219 val = 50000000;
220 break;
221 case 3:
222 val = 66000000;
223 break;
224 case 4:
225 val = 83000000;
226 break;
227 case 5:
228 val = 100000000;
229 break;
230 case 6:
231 val = 134000000;
232 break;
233 case 7:
234 val = 166000000;
235 break;
236 }
237
238 return val;
239}
Peter Tyser69454402009-02-05 11:25:25 -0600240
241void board_reset(void)
242{
243#ifdef CONFIG_SYS_RESET_ADDRESS
244 ulong addr = CONFIG_SYS_RESET_ADDRESS;
245
246 /* flush and disable I/D cache */
247 __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3");
248 __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5");
249 __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4");
250 __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5");
251 __asm__ __volatile__ ("sync");
252 __asm__ __volatile__ ("mtspr 1008, 4");
253 __asm__ __volatile__ ("isync");
254 __asm__ __volatile__ ("sync");
255 __asm__ __volatile__ ("mtspr 1008, 5");
256 __asm__ __volatile__ ("isync");
257 __asm__ __volatile__ ("sync");
258
259 /*
260 * SRR0 has system reset vector, SRR1 has default MSR value
261 * rfi restores MSR from SRR1 and sets the PC to the SRR0 value
262 */
263 __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr));
264 __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4");
265 __asm__ __volatile__ ("mtspr 27, 4");
266 __asm__ __volatile__ ("rfi");
267#endif
268}