blob: d354a26f69a45f3fae22215df3ec12e3a5e535f9 [file] [log] [blame]
Kumar Galaaf5b3262008-06-06 13:12:18 -05001/*
wdenk13eb2212004-07-09 23:27:13 +00002 * Copyright 2004 Freescale Semiconductor.
wdenk9c53f402003-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
wdenk9c53f402003-10-15 23:53:47 +000028#include <common.h>
wdenk492b9e72004-08-01 23:02:45 +000029#include <pci.h>
wdenk9c53f402003-10-15 23:53:47 +000030#include <asm/processor.h>
Kumar Galaaf5b3262008-06-06 13:12:18 -050031#include <asm/mmu.h>
wdenk9c53f402003-10-15 23:53:47 +000032#include <asm/immap_85xx.h>
Kumar Galaaf5b3262008-06-06 13:12:18 -050033#include <asm/fsl_ddr_sdram.h>
Kumar Gala6e578402007-11-28 22:54:27 -060034#include <libfdt.h>
35#include <fdt_support.h>
Matthew McClintock148e26a2006-06-28 10:43:36 -050036
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050037#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
wdenk13eb2212004-07-09 23:27:13 +000038extern void ddr_enable_ecc(unsigned int dram_size);
wdenka445ddf2004-06-09 00:34:46 +000039#endif
40
wdenk492b9e72004-08-01 23:02:45 +000041void local_bus_init(void);
wdenk13eb2212004-07-09 23:27:13 +000042void sdram_init(void);
43long int fixed_sdram(void);
44
wdenk9c53f402003-10-15 23:53:47 +000045int checkboard (void)
46{
wdenka445ddf2004-06-09 00:34:46 +000047 puts("Board: ADS\n");
wdenk13eb2212004-07-09 23:27:13 +000048
49#ifdef CONFIG_PCI
Peter Tyser2b91f712010-10-29 17:59:24 -050050 printf("PCI1: 32 bit, %d MHz (compiled)\n",
wdenk13eb2212004-07-09 23:27:13 +000051 CONFIG_SYS_CLK_FREQ / 1000000);
52#else
Peter Tyser2b91f712010-10-29 17:59:24 -050053 printf("PCI1: disabled\n");
wdenk13eb2212004-07-09 23:27:13 +000054#endif
55
wdenk492b9e72004-08-01 23:02:45 +000056 /*
57 * Initialize local bus.
58 */
59 local_bus_init();
60
wdenka445ddf2004-06-09 00:34:46 +000061 return 0;
wdenk9c53f402003-10-15 23:53:47 +000062}
63
wdenka445ddf2004-06-09 00:34:46 +000064
Becky Brucebd99ae72008-06-09 16:03:40 -050065phys_size_t
wdenk13eb2212004-07-09 23:27:13 +000066initdram(int board_type)
wdenk9c53f402003-10-15 23:53:47 +000067{
68 long dram_size = 0;
wdenk13eb2212004-07-09 23:27:13 +000069
70 puts("Initializing\n");
wdenka445ddf2004-06-09 00:34:46 +000071
wdenk9c53f402003-10-15 23:53:47 +000072#if defined(CONFIG_DDR_DLL)
wdenk13eb2212004-07-09 23:27:13 +000073 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020074 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
wdenk492b9e72004-08-01 23:02:45 +000075 uint temp_ddrdll = 0;
wdenk9c53f402003-10-15 23:53:47 +000076
wdenk492b9e72004-08-01 23:02:45 +000077 /*
78 * Work around to stabilize DDR DLL
79 */
80 temp_ddrdll = gur->ddrdllcr;
81 gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
82 asm("sync;isync;msync");
wdenk13eb2212004-07-09 23:27:13 +000083 }
wdenk9c53f402003-10-15 23:53:47 +000084#endif
85
Kumar Galaaf5b3262008-06-06 13:12:18 -050086#ifdef CONFIG_SPD_EEPROM
87 dram_size = fsl_ddr_sdram();
88 dram_size = setup_ddr_tlbs(dram_size / 0x100000);
89
90 dram_size *= 0x100000;
wdenk9c53f402003-10-15 23:53:47 +000091#else
Kumar Galaaf5b3262008-06-06 13:12:18 -050092 dram_size = fixed_sdram();
wdenk9c53f402003-10-15 23:53:47 +000093#endif
94
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050095#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
wdenk13eb2212004-07-09 23:27:13 +000096 /*
97 * Initialize and enable DDR ECC.
98 */
99 ddr_enable_ecc(dram_size);
100#endif
101
102 /*
103 * Initialize SDRAM.
104 */
105 sdram_init();
106
107 puts(" DDR: ");
108 return dram_size;
109}
110
111
112/*
wdenk492b9e72004-08-01 23:02:45 +0000113 * Initialize Local Bus
wdenk13eb2212004-07-09 23:27:13 +0000114 */
115
wdenk492b9e72004-08-01 23:02:45 +0000116void
117local_bus_init(void)
wdenk13eb2212004-07-09 23:27:13 +0000118{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200119 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Becky Bruce0d4cee12010-06-17 11:37:20 -0500120 volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
wdenk13eb2212004-07-09 23:27:13 +0000121
wdenk492b9e72004-08-01 23:02:45 +0000122 uint clkdiv;
123 uint lbc_hz;
124 sys_info_t sysinfo;
wdenk13eb2212004-07-09 23:27:13 +0000125
126 /*
wdenk492b9e72004-08-01 23:02:45 +0000127 * Errata LBC11.
128 * Fix Local Bus clock glitch when DLL is enabled.
wdenk13eb2212004-07-09 23:27:13 +0000129 *
Wolfgang Denkaf0501a2008-10-19 02:35:50 +0200130 * If localbus freq is < 66MHz, DLL bypass mode must be used.
131 * If localbus freq is > 133MHz, DLL can be safely enabled.
wdenk492b9e72004-08-01 23:02:45 +0000132 * Between 66 and 133, the DLL is enabled with an override workaround.
wdenk13eb2212004-07-09 23:27:13 +0000133 */
wdenk492b9e72004-08-01 23:02:45 +0000134
135 get_sys_info(&sysinfo);
Trent Piepho1b560ac2008-12-03 15:16:34 -0800136 clkdiv = lbc->lcrr & LCRR_CLKDIV;
wdenk492b9e72004-08-01 23:02:45 +0000137 lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
138
139 if (lbc_hz < 66) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200140 lbc->lcrr = CONFIG_SYS_LBC_LCRR | 0x80000000; /* DLL Bypass */
wdenk492b9e72004-08-01 23:02:45 +0000141
142 } else if (lbc_hz >= 133) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200143 lbc->lcrr = CONFIG_SYS_LBC_LCRR & (~0x80000000); /* DLL Enabled */
wdenk13eb2212004-07-09 23:27:13 +0000144
wdenk9c53f402003-10-15 23:53:47 +0000145 } else {
wdenk13eb2212004-07-09 23:27:13 +0000146 /*
147 * On REV1 boards, need to change CLKDIV before enable DLL.
148 * Default CLKDIV is 8, change it to 4 temporarily.
149 */
wdenk492b9e72004-08-01 23:02:45 +0000150 uint pvr = get_pvr();
wdenk13eb2212004-07-09 23:27:13 +0000151 uint temp_lbcdll = 0;
wdenka445ddf2004-06-09 00:34:46 +0000152
153 if (pvr == PVR_85xx_REV1) {
wdenk492b9e72004-08-01 23:02:45 +0000154 /* FIXME: Justify the high bit here. */
wdenk13eb2212004-07-09 23:27:13 +0000155 lbc->lcrr = 0x10000004;
wdenka445ddf2004-06-09 00:34:46 +0000156 }
wdenk13eb2212004-07-09 23:27:13 +0000157
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200158 lbc->lcrr = CONFIG_SYS_LBC_LCRR & (~0x80000000); /* DLL Enabled */
wdenk492b9e72004-08-01 23:02:45 +0000159 udelay(200);
160
161 /*
162 * Sample LBC DLL ctrl reg, upshift it to set the
163 * override bits.
164 */
wdenk9c53f402003-10-15 23:53:47 +0000165 temp_lbcdll = gur->lbcdllcr;
wdenk492b9e72004-08-01 23:02:45 +0000166 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
167 asm("sync;isync;msync");
wdenk9c53f402003-10-15 23:53:47 +0000168 }
wdenk492b9e72004-08-01 23:02:45 +0000169}
170
171
172/*
173 * Initialize SDRAM memory on the Local Bus.
174 */
175
176void
177sdram_init(void)
178{
Becky Bruce0d4cee12010-06-17 11:37:20 -0500179 volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200180 uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
wdenk492b9e72004-08-01 23:02:45 +0000181
182 puts(" SDRAM: ");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200183 print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
wdenk13eb2212004-07-09 23:27:13 +0000184
185 /*
186 * Setup SDRAM Base and Option Registers
187 */
Becky Bruce0d4cee12010-06-17 11:37:20 -0500188 set_lbc_or(2, CONFIG_SYS_OR2_PRELIM);
189 set_lbc_br(2, CONFIG_SYS_BR2_PRELIM);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200190 lbc->lbcr = CONFIG_SYS_LBC_LBCR;
wdenk492b9e72004-08-01 23:02:45 +0000191 asm("msync");
wdenk13eb2212004-07-09 23:27:13 +0000192
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200193 lbc->lsrt = CONFIG_SYS_LBC_LSRT;
194 lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
wdenk492b9e72004-08-01 23:02:45 +0000195 asm("sync");
wdenk9c53f402003-10-15 23:53:47 +0000196
wdenk13eb2212004-07-09 23:27:13 +0000197 /*
198 * Configure the SDRAM controller.
199 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200200 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1;
wdenk492b9e72004-08-01 23:02:45 +0000201 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000202 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000203 ppcDcbf((unsigned long) sdram_addr);
204 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000205
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200206 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2;
wdenk492b9e72004-08-01 23:02:45 +0000207 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000208 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000209 ppcDcbf((unsigned long) sdram_addr);
210 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000211
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200212 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_3;
wdenk492b9e72004-08-01 23:02:45 +0000213 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000214 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000215 ppcDcbf((unsigned long) sdram_addr);
216 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000217
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200218 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4;
wdenk492b9e72004-08-01 23:02:45 +0000219 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000220 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000221 ppcDcbf((unsigned long) sdram_addr);
222 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000223
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200224 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5;
wdenk492b9e72004-08-01 23:02:45 +0000225 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000226 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000227 ppcDcbf((unsigned long) sdram_addr);
228 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000229}
230
wdenk9c53f402003-10-15 23:53:47 +0000231#if !defined(CONFIG_SPD_EEPROM)
232/*************************************************************************
233 * fixed sdram init -- doesn't use serial presence detect.
234 ************************************************************************/
235long int fixed_sdram (void)
236{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200237 #ifndef CONFIG_SYS_RAMBOOT
238 volatile ccsr_ddr_t *ddr= (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
wdenk9c53f402003-10-15 23:53:47 +0000239
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200240 ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
241 ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
242 ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
243 ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
244 ddr->sdram_mode = CONFIG_SYS_DDR_MODE;
245 ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
wdenk9c53f402003-10-15 23:53:47 +0000246 #if defined (CONFIG_DDR_ECC)
247 ddr->err_disable = 0x0000000D;
248 ddr->err_sbe = 0x00ff0000;
249 #endif
250 asm("sync;isync;msync");
251 udelay(500);
252 #if defined (CONFIG_DDR_ECC)
253 /* Enable ECC checking */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200254 ddr->sdram_cfg = (CONFIG_SYS_DDR_CONTROL | 0x20000000);
wdenk9c53f402003-10-15 23:53:47 +0000255 #else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200256 ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
wdenk9c53f402003-10-15 23:53:47 +0000257 #endif
258 asm("sync; isync; msync");
259 udelay(500);
260 #endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200261 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
wdenk9c53f402003-10-15 23:53:47 +0000262}
263#endif /* !defined(CONFIG_SPD_EEPROM) */
wdenk492b9e72004-08-01 23:02:45 +0000264
265
266#if defined(CONFIG_PCI)
267/*
268 * Initialize PCI Devices, report devices found.
269 */
270
wdenk492b9e72004-08-01 23:02:45 +0000271
Matthew McClintock8c0da862006-06-28 10:45:41 -0500272static struct pci_controller hose;
wdenk492b9e72004-08-01 23:02:45 +0000273
274#endif /* CONFIG_PCI */
275
276
277void
278pci_init_board(void)
279{
280#ifdef CONFIG_PCI
wdenk492b9e72004-08-01 23:02:45 +0000281 pci_mpc85xx_init(&hose);
282#endif /* CONFIG_PCI */
283}
Matthew McClintock148e26a2006-06-28 10:43:36 -0500284
285
Kumar Gala6e578402007-11-28 22:54:27 -0600286#if defined(CONFIG_OF_BOARD_SETUP)
Matthew McClintock148e26a2006-06-28 10:43:36 -0500287void
288ft_board_setup(void *blob, bd_t *bd)
289{
Kumar Gala6e578402007-11-28 22:54:27 -0600290 int node, tmp[2];
291 const char *path;
Matthew McClintock148e26a2006-06-28 10:43:36 -0500292
293 ft_cpu_setup(blob, bd);
294
Kumar Gala6e578402007-11-28 22:54:27 -0600295 node = fdt_path_offset(blob, "/aliases");
296 tmp[0] = 0;
297 if (node >= 0) {
298#ifdef CONFIG_PCI
299 path = fdt_getprop(blob, node, "pci0", NULL);
300 if (path) {
301 tmp[1] = hose.last_busno - hose.first_busno;
302 do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
303 }
304#endif
Matthew McClintock148e26a2006-06-28 10:43:36 -0500305 }
306}
307#endif