blob: 4f068cc8849a78d36d96b46a3ce1f74acce2918a [file] [log] [blame]
wdenk97d80fc2004-06-09 00:34:46 +00001 /*
wdenk0ac6f8b2004-07-09 23:27:13 +00002 * Copyright 2004 Freescale Semiconductor.
wdenk42d1f032003-10-15 23:53:47 +00003 * (C) Copyright 2002,2003, Motorola Inc.
4 * Xianghua Xiao, (X.Xiao@motorola.com)
5 *
6 * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
7 *
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
27
wdenk42d1f032003-10-15 23:53:47 +000028#include <common.h>
wdenk9aea9532004-08-01 23:02:45 +000029#include <pci.h>
wdenk42d1f032003-10-15 23:53:47 +000030#include <asm/processor.h>
31#include <asm/immap_85xx.h>
Jon Loeligera30a5492008-03-04 10:03:03 -060032#include <spd_sdram.h>
Kumar Gala0fd5ec62007-11-28 22:54:27 -060033#include <libfdt.h>
34#include <fdt_support.h>
Matthew McClintock40d5fa32006-06-28 10:43:36 -050035
Jon Loeligerd9b94f22005-07-25 14:05:07 -050036#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
wdenk0ac6f8b2004-07-09 23:27:13 +000037extern void ddr_enable_ecc(unsigned int dram_size);
wdenk97d80fc2004-06-09 00:34:46 +000038#endif
39
wdenk9aea9532004-08-01 23:02:45 +000040void local_bus_init(void);
wdenk0ac6f8b2004-07-09 23:27:13 +000041void sdram_init(void);
42long int fixed_sdram(void);
43
wdenk42d1f032003-10-15 23:53:47 +000044int checkboard (void)
45{
wdenk97d80fc2004-06-09 00:34:46 +000046 puts("Board: ADS\n");
wdenk0ac6f8b2004-07-09 23:27:13 +000047
48#ifdef CONFIG_PCI
49 printf(" PCI1: 32 bit, %d MHz (compiled)\n",
50 CONFIG_SYS_CLK_FREQ / 1000000);
51#else
52 printf(" PCI1: disabled\n");
53#endif
54
wdenk9aea9532004-08-01 23:02:45 +000055 /*
56 * Initialize local bus.
57 */
58 local_bus_init();
59
wdenk97d80fc2004-06-09 00:34:46 +000060 return 0;
wdenk42d1f032003-10-15 23:53:47 +000061}
62
wdenk97d80fc2004-06-09 00:34:46 +000063
Becky Bruce9973e3c2008-06-09 16:03:40 -050064phys_size_t
wdenk0ac6f8b2004-07-09 23:27:13 +000065initdram(int board_type)
wdenk42d1f032003-10-15 23:53:47 +000066{
67 long dram_size = 0;
wdenk0ac6f8b2004-07-09 23:27:13 +000068
69 puts("Initializing\n");
wdenk97d80fc2004-06-09 00:34:46 +000070
wdenk42d1f032003-10-15 23:53:47 +000071#if defined(CONFIG_DDR_DLL)
wdenk0ac6f8b2004-07-09 23:27:13 +000072 {
Kumar Galaf59b55a2007-11-27 23:25:02 -060073 volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
wdenk9aea9532004-08-01 23:02:45 +000074 uint temp_ddrdll = 0;
wdenk42d1f032003-10-15 23:53:47 +000075
wdenk9aea9532004-08-01 23:02:45 +000076 /*
77 * Work around to stabilize DDR DLL
78 */
79 temp_ddrdll = gur->ddrdllcr;
80 gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
81 asm("sync;isync;msync");
wdenk0ac6f8b2004-07-09 23:27:13 +000082 }
wdenk42d1f032003-10-15 23:53:47 +000083#endif
84
85#if defined(CONFIG_SPD_EEPROM)
86 dram_size = spd_sdram ();
87#else
88 dram_size = fixed_sdram ();
89#endif
90
Jon Loeligerd9b94f22005-07-25 14:05:07 -050091#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
wdenk0ac6f8b2004-07-09 23:27:13 +000092 /*
93 * Initialize and enable DDR ECC.
94 */
95 ddr_enable_ecc(dram_size);
96#endif
97
98 /*
99 * Initialize SDRAM.
100 */
101 sdram_init();
102
103 puts(" DDR: ");
104 return dram_size;
105}
106
107
108/*
wdenk9aea9532004-08-01 23:02:45 +0000109 * Initialize Local Bus
wdenk0ac6f8b2004-07-09 23:27:13 +0000110 */
111
wdenk9aea9532004-08-01 23:02:45 +0000112void
113local_bus_init(void)
wdenk0ac6f8b2004-07-09 23:27:13 +0000114{
Kumar Galaf59b55a2007-11-27 23:25:02 -0600115 volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
Kumar Gala04db4002007-11-29 02:10:09 -0600116 volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
wdenk0ac6f8b2004-07-09 23:27:13 +0000117
wdenk9aea9532004-08-01 23:02:45 +0000118 uint clkdiv;
119 uint lbc_hz;
120 sys_info_t sysinfo;
wdenk0ac6f8b2004-07-09 23:27:13 +0000121
122 /*
wdenk9aea9532004-08-01 23:02:45 +0000123 * Errata LBC11.
124 * Fix Local Bus clock glitch when DLL is enabled.
wdenk0ac6f8b2004-07-09 23:27:13 +0000125 *
wdenk9aea9532004-08-01 23:02:45 +0000126 * If localbus freq is < 66Mhz, DLL bypass mode must be used.
127 * If localbus freq is > 133Mhz, DLL can be safely enabled.
128 * Between 66 and 133, the DLL is enabled with an override workaround.
wdenk0ac6f8b2004-07-09 23:27:13 +0000129 */
wdenk9aea9532004-08-01 23:02:45 +0000130
131 get_sys_info(&sysinfo);
132 clkdiv = lbc->lcrr & 0x0f;
133 lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
134
135 if (lbc_hz < 66) {
136 lbc->lcrr = CFG_LBC_LCRR | 0x80000000; /* DLL Bypass */
137
138 } else if (lbc_hz >= 133) {
139 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
wdenk0ac6f8b2004-07-09 23:27:13 +0000140
wdenk42d1f032003-10-15 23:53:47 +0000141 } else {
wdenk0ac6f8b2004-07-09 23:27:13 +0000142 /*
143 * On REV1 boards, need to change CLKDIV before enable DLL.
144 * Default CLKDIV is 8, change it to 4 temporarily.
145 */
wdenk9aea9532004-08-01 23:02:45 +0000146 uint pvr = get_pvr();
wdenk0ac6f8b2004-07-09 23:27:13 +0000147 uint temp_lbcdll = 0;
wdenk97d80fc2004-06-09 00:34:46 +0000148
149 if (pvr == PVR_85xx_REV1) {
wdenk9aea9532004-08-01 23:02:45 +0000150 /* FIXME: Justify the high bit here. */
wdenk0ac6f8b2004-07-09 23:27:13 +0000151 lbc->lcrr = 0x10000004;
wdenk97d80fc2004-06-09 00:34:46 +0000152 }
wdenk0ac6f8b2004-07-09 23:27:13 +0000153
wdenk9aea9532004-08-01 23:02:45 +0000154 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
155 udelay(200);
156
157 /*
158 * Sample LBC DLL ctrl reg, upshift it to set the
159 * override bits.
160 */
wdenk42d1f032003-10-15 23:53:47 +0000161 temp_lbcdll = gur->lbcdllcr;
wdenk9aea9532004-08-01 23:02:45 +0000162 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
163 asm("sync;isync;msync");
wdenk42d1f032003-10-15 23:53:47 +0000164 }
wdenk9aea9532004-08-01 23:02:45 +0000165}
166
167
168/*
169 * Initialize SDRAM memory on the Local Bus.
170 */
171
172void
173sdram_init(void)
174{
Kumar Gala04db4002007-11-29 02:10:09 -0600175 volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
wdenk9aea9532004-08-01 23:02:45 +0000176 uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
177
178 puts(" SDRAM: ");
179 print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
wdenk0ac6f8b2004-07-09 23:27:13 +0000180
181 /*
182 * Setup SDRAM Base and Option Registers
183 */
184 lbc->or2 = CFG_OR2_PRELIM;
wdenk42d1f032003-10-15 23:53:47 +0000185 lbc->br2 = CFG_BR2_PRELIM;
186 lbc->lbcr = CFG_LBC_LBCR;
wdenk9aea9532004-08-01 23:02:45 +0000187 asm("msync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000188
wdenk42d1f032003-10-15 23:53:47 +0000189 lbc->lsrt = CFG_LBC_LSRT;
wdenk42d1f032003-10-15 23:53:47 +0000190 lbc->mrtpr = CFG_LBC_MRTPR;
wdenk9aea9532004-08-01 23:02:45 +0000191 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000192
193 /*
194 * Configure the SDRAM controller.
195 */
196 lbc->lsdmr = CFG_LBC_LSDMR_1;
wdenk9aea9532004-08-01 23:02:45 +0000197 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000198 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000199 ppcDcbf((unsigned long) sdram_addr);
200 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000201
202 lbc->lsdmr = CFG_LBC_LSDMR_2;
wdenk9aea9532004-08-01 23:02:45 +0000203 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000204 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000205 ppcDcbf((unsigned long) sdram_addr);
206 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000207
208 lbc->lsdmr = CFG_LBC_LSDMR_3;
wdenk9aea9532004-08-01 23:02:45 +0000209 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000210 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000211 ppcDcbf((unsigned long) sdram_addr);
212 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000213
214 lbc->lsdmr = CFG_LBC_LSDMR_4;
wdenk9aea9532004-08-01 23:02:45 +0000215 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000216 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000217 ppcDcbf((unsigned long) sdram_addr);
218 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000219
220 lbc->lsdmr = CFG_LBC_LSDMR_5;
wdenk9aea9532004-08-01 23:02:45 +0000221 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000222 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000223 ppcDcbf((unsigned long) sdram_addr);
224 udelay(100);
wdenk42d1f032003-10-15 23:53:47 +0000225}
226
wdenk42d1f032003-10-15 23:53:47 +0000227#if !defined(CONFIG_SPD_EEPROM)
228/*************************************************************************
229 * fixed sdram init -- doesn't use serial presence detect.
230 ************************************************************************/
231long int fixed_sdram (void)
232{
233 #ifndef CFG_RAMBOOT
Kumar Gala04db4002007-11-29 02:10:09 -0600234 volatile ccsr_ddr_t *ddr= (void *)(CFG_MPC85xx_DDR_ADDR);
wdenk42d1f032003-10-15 23:53:47 +0000235
236 ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
237 ddr->cs0_config = CFG_DDR_CS0_CONFIG;
238 ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
239 ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
240 ddr->sdram_mode = CFG_DDR_MODE;
241 ddr->sdram_interval = CFG_DDR_INTERVAL;
242 #if defined (CONFIG_DDR_ECC)
243 ddr->err_disable = 0x0000000D;
244 ddr->err_sbe = 0x00ff0000;
245 #endif
246 asm("sync;isync;msync");
247 udelay(500);
248 #if defined (CONFIG_DDR_ECC)
249 /* Enable ECC checking */
250 ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
251 #else
252 ddr->sdram_cfg = CFG_DDR_CONTROL;
253 #endif
254 asm("sync; isync; msync");
255 udelay(500);
256 #endif
wdenk0ac6f8b2004-07-09 23:27:13 +0000257 return CFG_SDRAM_SIZE * 1024 * 1024;
wdenk42d1f032003-10-15 23:53:47 +0000258}
259#endif /* !defined(CONFIG_SPD_EEPROM) */
wdenk9aea9532004-08-01 23:02:45 +0000260
261
262#if defined(CONFIG_PCI)
263/*
264 * Initialize PCI Devices, report devices found.
265 */
266
wdenk9aea9532004-08-01 23:02:45 +0000267
Matthew McClintock52c7a682006-06-28 10:45:41 -0500268static struct pci_controller hose;
wdenk9aea9532004-08-01 23:02:45 +0000269
270#endif /* CONFIG_PCI */
271
272
273void
274pci_init_board(void)
275{
276#ifdef CONFIG_PCI
wdenk9aea9532004-08-01 23:02:45 +0000277 pci_mpc85xx_init(&hose);
278#endif /* CONFIG_PCI */
279}
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500280
281
Kumar Gala0fd5ec62007-11-28 22:54:27 -0600282#if defined(CONFIG_OF_BOARD_SETUP)
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500283void
284ft_board_setup(void *blob, bd_t *bd)
285{
Kumar Gala0fd5ec62007-11-28 22:54:27 -0600286 int node, tmp[2];
287 const char *path;
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500288
289 ft_cpu_setup(blob, bd);
290
Kumar Gala0fd5ec62007-11-28 22:54:27 -0600291 node = fdt_path_offset(blob, "/aliases");
292 tmp[0] = 0;
293 if (node >= 0) {
294#ifdef CONFIG_PCI
295 path = fdt_getprop(blob, node, "pci0", NULL);
296 if (path) {
297 tmp[1] = hose.last_busno - hose.first_busno;
298 do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
299 }
300#endif
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500301 }
302}
303#endif