blob: a275d3a074d8fb4fb4b490c8ec7333a06cfb2a73 [file] [log] [blame]
Kumar Gala9617c8d2008-06-06 13:12:18 -05001/*
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>
Kumar Gala9617c8d2008-06-06 13:12:18 -050031#include <asm/mmu.h>
wdenk42d1f032003-10-15 23:53:47 +000032#include <asm/immap_85xx.h>
Kumar Gala9617c8d2008-06-06 13:12:18 -050033#include <asm/fsl_ddr_sdram.h>
Kumar Gala0fd5ec62007-11-28 22:54:27 -060034#include <libfdt.h>
35#include <fdt_support.h>
Matthew McClintock40d5fa32006-06-28 10:43:36 -050036
Jon Loeligerd9b94f22005-07-25 14:05:07 -050037#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
wdenk0ac6f8b2004-07-09 23:27:13 +000038extern void ddr_enable_ecc(unsigned int dram_size);
wdenk97d80fc2004-06-09 00:34:46 +000039#endif
40
wdenk9aea9532004-08-01 23:02:45 +000041void local_bus_init(void);
wdenk0ac6f8b2004-07-09 23:27:13 +000042
wdenk42d1f032003-10-15 23:53:47 +000043int checkboard (void)
44{
wdenk97d80fc2004-06-09 00:34:46 +000045 puts("Board: ADS\n");
wdenk0ac6f8b2004-07-09 23:27:13 +000046
47#ifdef CONFIG_PCI
Peter Tyser8ca78f22010-10-29 17:59:24 -050048 printf("PCI1: 32 bit, %d MHz (compiled)\n",
wdenk0ac6f8b2004-07-09 23:27:13 +000049 CONFIG_SYS_CLK_FREQ / 1000000);
50#else
Peter Tyser8ca78f22010-10-29 17:59:24 -050051 printf("PCI1: disabled\n");
wdenk0ac6f8b2004-07-09 23:27:13 +000052#endif
53
wdenk9aea9532004-08-01 23:02:45 +000054 /*
55 * Initialize local bus.
56 */
57 local_bus_init();
58
wdenk97d80fc2004-06-09 00:34:46 +000059 return 0;
wdenk42d1f032003-10-15 23:53:47 +000060}
61
wdenk0ac6f8b2004-07-09 23:27:13 +000062/*
wdenk9aea9532004-08-01 23:02:45 +000063 * Initialize Local Bus
wdenk0ac6f8b2004-07-09 23:27:13 +000064 */
65
wdenk9aea9532004-08-01 23:02:45 +000066void
67local_bus_init(void)
wdenk0ac6f8b2004-07-09 23:27:13 +000068{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020069 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Becky Brucef51cdaf2010-06-17 11:37:20 -050070 volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
wdenk0ac6f8b2004-07-09 23:27:13 +000071
wdenk9aea9532004-08-01 23:02:45 +000072 uint clkdiv;
73 uint lbc_hz;
74 sys_info_t sysinfo;
wdenk0ac6f8b2004-07-09 23:27:13 +000075
76 /*
wdenk9aea9532004-08-01 23:02:45 +000077 * Errata LBC11.
78 * Fix Local Bus clock glitch when DLL is enabled.
wdenk0ac6f8b2004-07-09 23:27:13 +000079 *
Wolfgang Denk8ed44d92008-10-19 02:35:50 +020080 * If localbus freq is < 66MHz, DLL bypass mode must be used.
81 * If localbus freq is > 133MHz, DLL can be safely enabled.
wdenk9aea9532004-08-01 23:02:45 +000082 * Between 66 and 133, the DLL is enabled with an override workaround.
wdenk0ac6f8b2004-07-09 23:27:13 +000083 */
wdenk9aea9532004-08-01 23:02:45 +000084
85 get_sys_info(&sysinfo);
Trent Piephoa5d212a2008-12-03 15:16:34 -080086 clkdiv = lbc->lcrr & LCRR_CLKDIV;
wdenk9aea9532004-08-01 23:02:45 +000087 lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
88
89 if (lbc_hz < 66) {
Paul Gortmakera2af6a72012-08-13 13:48:57 +000090 lbc->lcrr = CONFIG_SYS_LBC_LCRR | LCRR_DBYP; /* DLL Bypass */
wdenk9aea9532004-08-01 23:02:45 +000091
92 } else if (lbc_hz >= 133) {
Paul Gortmakera2af6a72012-08-13 13:48:57 +000093 lbc->lcrr = CONFIG_SYS_LBC_LCRR & (~LCRR_DBYP); /* DLL Enabled */
wdenk0ac6f8b2004-07-09 23:27:13 +000094
wdenk42d1f032003-10-15 23:53:47 +000095 } else {
wdenk0ac6f8b2004-07-09 23:27:13 +000096 /*
97 * On REV1 boards, need to change CLKDIV before enable DLL.
98 * Default CLKDIV is 8, change it to 4 temporarily.
99 */
wdenk9aea9532004-08-01 23:02:45 +0000100 uint pvr = get_pvr();
wdenk0ac6f8b2004-07-09 23:27:13 +0000101 uint temp_lbcdll = 0;
wdenk97d80fc2004-06-09 00:34:46 +0000102
103 if (pvr == PVR_85xx_REV1) {
wdenk9aea9532004-08-01 23:02:45 +0000104 /* FIXME: Justify the high bit here. */
wdenk0ac6f8b2004-07-09 23:27:13 +0000105 lbc->lcrr = 0x10000004;
wdenk97d80fc2004-06-09 00:34:46 +0000106 }
wdenk0ac6f8b2004-07-09 23:27:13 +0000107
Paul Gortmakera2af6a72012-08-13 13:48:57 +0000108 lbc->lcrr = CONFIG_SYS_LBC_LCRR & (~LCRR_DBYP); /* DLL Enabled */
wdenk9aea9532004-08-01 23:02:45 +0000109 udelay(200);
110
111 /*
112 * Sample LBC DLL ctrl reg, upshift it to set the
113 * override bits.
114 */
wdenk42d1f032003-10-15 23:53:47 +0000115 temp_lbcdll = gur->lbcdllcr;
wdenk9aea9532004-08-01 23:02:45 +0000116 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
117 asm("sync;isync;msync");
wdenk42d1f032003-10-15 23:53:47 +0000118 }
wdenk9aea9532004-08-01 23:02:45 +0000119}
120
121
122/*
123 * Initialize SDRAM memory on the Local Bus.
124 */
Becky Bruce70961ba2010-12-17 17:17:57 -0600125void lbc_sdram_init(void)
wdenk9aea9532004-08-01 23:02:45 +0000126{
Becky Brucef51cdaf2010-06-17 11:37:20 -0500127 volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200128 uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
wdenk9aea9532004-08-01 23:02:45 +0000129
Becky Bruce7ea38712010-12-17 17:17:59 -0600130 puts("LBC SDRAM: ");
131 print_size(CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024,
132 "\n ");
wdenk0ac6f8b2004-07-09 23:27:13 +0000133
134 /*
135 * Setup SDRAM Base and Option Registers
136 */
Becky Brucef51cdaf2010-06-17 11:37:20 -0500137 set_lbc_or(2, CONFIG_SYS_OR2_PRELIM);
138 set_lbc_br(2, CONFIG_SYS_BR2_PRELIM);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200139 lbc->lbcr = CONFIG_SYS_LBC_LBCR;
wdenk9aea9532004-08-01 23:02:45 +0000140 asm("msync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000141
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200142 lbc->lsrt = CONFIG_SYS_LBC_LSRT;
143 lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
wdenk9aea9532004-08-01 23:02:45 +0000144 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000145
146 /*
147 * Configure the SDRAM controller.
148 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200149 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1;
wdenk9aea9532004-08-01 23:02:45 +0000150 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000151 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000152 ppcDcbf((unsigned long) sdram_addr);
153 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000154
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200155 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2;
wdenk9aea9532004-08-01 23:02:45 +0000156 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000157 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000158 ppcDcbf((unsigned long) sdram_addr);
159 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000160
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200161 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_3;
wdenk9aea9532004-08-01 23:02:45 +0000162 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000163 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000164 ppcDcbf((unsigned long) sdram_addr);
165 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000166
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200167 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4;
wdenk9aea9532004-08-01 23:02:45 +0000168 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000169 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000170 ppcDcbf((unsigned long) sdram_addr);
171 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000172
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200173 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5;
wdenk9aea9532004-08-01 23:02:45 +0000174 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000175 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000176 ppcDcbf((unsigned long) sdram_addr);
177 udelay(100);
wdenk42d1f032003-10-15 23:53:47 +0000178}
179
wdenk42d1f032003-10-15 23:53:47 +0000180#if !defined(CONFIG_SPD_EEPROM)
181/*************************************************************************
182 * fixed sdram init -- doesn't use serial presence detect.
183 ************************************************************************/
Becky Bruce38dba0c2010-12-17 17:17:56 -0600184phys_size_t fixed_sdram(void)
wdenk42d1f032003-10-15 23:53:47 +0000185{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200186 #ifndef CONFIG_SYS_RAMBOOT
187 volatile ccsr_ddr_t *ddr= (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
wdenk42d1f032003-10-15 23:53:47 +0000188
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200189 ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
190 ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
191 ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
192 ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
193 ddr->sdram_mode = CONFIG_SYS_DDR_MODE;
194 ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
wdenk42d1f032003-10-15 23:53:47 +0000195 #if defined (CONFIG_DDR_ECC)
196 ddr->err_disable = 0x0000000D;
197 ddr->err_sbe = 0x00ff0000;
198 #endif
199 asm("sync;isync;msync");
200 udelay(500);
201 #if defined (CONFIG_DDR_ECC)
202 /* Enable ECC checking */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200203 ddr->sdram_cfg = (CONFIG_SYS_DDR_CONTROL | 0x20000000);
wdenk42d1f032003-10-15 23:53:47 +0000204 #else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200205 ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
wdenk42d1f032003-10-15 23:53:47 +0000206 #endif
207 asm("sync; isync; msync");
208 udelay(500);
209 #endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200210 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
wdenk42d1f032003-10-15 23:53:47 +0000211}
212#endif /* !defined(CONFIG_SPD_EEPROM) */
wdenk9aea9532004-08-01 23:02:45 +0000213
214
215#if defined(CONFIG_PCI)
216/*
217 * Initialize PCI Devices, report devices found.
218 */
219
wdenk9aea9532004-08-01 23:02:45 +0000220
Matthew McClintock52c7a682006-06-28 10:45:41 -0500221static struct pci_controller hose;
wdenk9aea9532004-08-01 23:02:45 +0000222
223#endif /* CONFIG_PCI */
224
225
226void
227pci_init_board(void)
228{
229#ifdef CONFIG_PCI
wdenk9aea9532004-08-01 23:02:45 +0000230 pci_mpc85xx_init(&hose);
231#endif /* CONFIG_PCI */
232}
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500233
234
Kumar Gala0fd5ec62007-11-28 22:54:27 -0600235#if defined(CONFIG_OF_BOARD_SETUP)
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500236void
237ft_board_setup(void *blob, bd_t *bd)
238{
Kumar Gala0fd5ec62007-11-28 22:54:27 -0600239 int node, tmp[2];
240 const char *path;
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500241
242 ft_cpu_setup(blob, bd);
243
Kumar Gala0fd5ec62007-11-28 22:54:27 -0600244 node = fdt_path_offset(blob, "/aliases");
245 tmp[0] = 0;
246 if (node >= 0) {
247#ifdef CONFIG_PCI
248 path = fdt_getprop(blob, node, "pci0", NULL);
249 if (path) {
250 tmp[1] = hose.last_busno - hose.first_busno;
251 do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
252 }
253#endif
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500254 }
255}
256#endif