blob: 93288c7e9ce0252f8a7ee1ecdaa3b2e9f9153919 [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 *
Wolfgang Denkbd8ec7e2013-10-07 13:07:26 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenk9c53f402003-10-15 23:53:47 +00009 */
10
11
wdenk9c53f402003-10-15 23:53:47 +000012#include <common.h>
wdenk492b9e72004-08-01 23:02:45 +000013#include <pci.h>
wdenk9c53f402003-10-15 23:53:47 +000014#include <asm/processor.h>
Kumar Galaaf5b3262008-06-06 13:12:18 -050015#include <asm/mmu.h>
wdenk9c53f402003-10-15 23:53:47 +000016#include <asm/immap_85xx.h>
York Sunf0626592013-09-30 09:22:09 -070017#include <fsl_ddr_sdram.h>
Kumar Gala6e578402007-11-28 22:54:27 -060018#include <libfdt.h>
19#include <fdt_support.h>
Matthew McClintock148e26a2006-06-28 10:43:36 -050020
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050021#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
wdenk13eb2212004-07-09 23:27:13 +000022extern void ddr_enable_ecc(unsigned int dram_size);
wdenka445ddf2004-06-09 00:34:46 +000023#endif
24
wdenk492b9e72004-08-01 23:02:45 +000025void local_bus_init(void);
wdenk13eb2212004-07-09 23:27:13 +000026
wdenk9c53f402003-10-15 23:53:47 +000027int checkboard (void)
28{
wdenka445ddf2004-06-09 00:34:46 +000029 puts("Board: ADS\n");
wdenk13eb2212004-07-09 23:27:13 +000030
31#ifdef CONFIG_PCI
Peter Tyser2b91f712010-10-29 17:59:24 -050032 printf("PCI1: 32 bit, %d MHz (compiled)\n",
wdenk13eb2212004-07-09 23:27:13 +000033 CONFIG_SYS_CLK_FREQ / 1000000);
34#else
Peter Tyser2b91f712010-10-29 17:59:24 -050035 printf("PCI1: disabled\n");
wdenk13eb2212004-07-09 23:27:13 +000036#endif
37
wdenk492b9e72004-08-01 23:02:45 +000038 /*
39 * Initialize local bus.
40 */
41 local_bus_init();
42
wdenka445ddf2004-06-09 00:34:46 +000043 return 0;
wdenk9c53f402003-10-15 23:53:47 +000044}
45
wdenk13eb2212004-07-09 23:27:13 +000046/*
wdenk492b9e72004-08-01 23:02:45 +000047 * Initialize Local Bus
wdenk13eb2212004-07-09 23:27:13 +000048 */
49
wdenk492b9e72004-08-01 23:02:45 +000050void
51local_bus_init(void)
wdenk13eb2212004-07-09 23:27:13 +000052{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020053 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Becky Bruce0d4cee12010-06-17 11:37:20 -050054 volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
wdenk13eb2212004-07-09 23:27:13 +000055
wdenk492b9e72004-08-01 23:02:45 +000056 uint clkdiv;
57 uint lbc_hz;
58 sys_info_t sysinfo;
wdenk13eb2212004-07-09 23:27:13 +000059
60 /*
wdenk492b9e72004-08-01 23:02:45 +000061 * Errata LBC11.
62 * Fix Local Bus clock glitch when DLL is enabled.
wdenk13eb2212004-07-09 23:27:13 +000063 *
Wolfgang Denkaf0501a2008-10-19 02:35:50 +020064 * If localbus freq is < 66MHz, DLL bypass mode must be used.
65 * If localbus freq is > 133MHz, DLL can be safely enabled.
wdenk492b9e72004-08-01 23:02:45 +000066 * Between 66 and 133, the DLL is enabled with an override workaround.
wdenk13eb2212004-07-09 23:27:13 +000067 */
wdenk492b9e72004-08-01 23:02:45 +000068
69 get_sys_info(&sysinfo);
Trent Piepho1b560ac2008-12-03 15:16:34 -080070 clkdiv = lbc->lcrr & LCRR_CLKDIV;
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053071 lbc_hz = sysinfo.freq_systembus / 1000000 / clkdiv;
wdenk492b9e72004-08-01 23:02:45 +000072
73 if (lbc_hz < 66) {
Paul Gortmakere5b89d52012-08-13 13:48:57 +000074 lbc->lcrr = CONFIG_SYS_LBC_LCRR | LCRR_DBYP; /* DLL Bypass */
wdenk492b9e72004-08-01 23:02:45 +000075
76 } else if (lbc_hz >= 133) {
Paul Gortmakere5b89d52012-08-13 13:48:57 +000077 lbc->lcrr = CONFIG_SYS_LBC_LCRR & (~LCRR_DBYP); /* DLL Enabled */
wdenk13eb2212004-07-09 23:27:13 +000078
wdenk9c53f402003-10-15 23:53:47 +000079 } else {
wdenk13eb2212004-07-09 23:27:13 +000080 /*
81 * On REV1 boards, need to change CLKDIV before enable DLL.
82 * Default CLKDIV is 8, change it to 4 temporarily.
83 */
wdenk492b9e72004-08-01 23:02:45 +000084 uint pvr = get_pvr();
wdenk13eb2212004-07-09 23:27:13 +000085 uint temp_lbcdll = 0;
wdenka445ddf2004-06-09 00:34:46 +000086
87 if (pvr == PVR_85xx_REV1) {
wdenk492b9e72004-08-01 23:02:45 +000088 /* FIXME: Justify the high bit here. */
wdenk13eb2212004-07-09 23:27:13 +000089 lbc->lcrr = 0x10000004;
wdenka445ddf2004-06-09 00:34:46 +000090 }
wdenk13eb2212004-07-09 23:27:13 +000091
Paul Gortmakere5b89d52012-08-13 13:48:57 +000092 lbc->lcrr = CONFIG_SYS_LBC_LCRR & (~LCRR_DBYP); /* DLL Enabled */
wdenk492b9e72004-08-01 23:02:45 +000093 udelay(200);
94
95 /*
96 * Sample LBC DLL ctrl reg, upshift it to set the
97 * override bits.
98 */
wdenk9c53f402003-10-15 23:53:47 +000099 temp_lbcdll = gur->lbcdllcr;
wdenk492b9e72004-08-01 23:02:45 +0000100 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
101 asm("sync;isync;msync");
wdenk9c53f402003-10-15 23:53:47 +0000102 }
wdenk492b9e72004-08-01 23:02:45 +0000103}
104
105
106/*
107 * Initialize SDRAM memory on the Local Bus.
108 */
Becky Bruceb88d3d02010-12-17 17:17:57 -0600109void lbc_sdram_init(void)
wdenk492b9e72004-08-01 23:02:45 +0000110{
Becky Bruce0d4cee12010-06-17 11:37:20 -0500111 volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200112 uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
wdenk492b9e72004-08-01 23:02:45 +0000113
Becky Bruce2d8ecac2010-12-17 17:17:59 -0600114 puts("LBC SDRAM: ");
115 print_size(CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024,
116 "\n ");
wdenk13eb2212004-07-09 23:27:13 +0000117
118 /*
119 * Setup SDRAM Base and Option Registers
120 */
Becky Bruce0d4cee12010-06-17 11:37:20 -0500121 set_lbc_or(2, CONFIG_SYS_OR2_PRELIM);
122 set_lbc_br(2, CONFIG_SYS_BR2_PRELIM);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200123 lbc->lbcr = CONFIG_SYS_LBC_LBCR;
wdenk492b9e72004-08-01 23:02:45 +0000124 asm("msync");
wdenk13eb2212004-07-09 23:27:13 +0000125
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200126 lbc->lsrt = CONFIG_SYS_LBC_LSRT;
127 lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
wdenk492b9e72004-08-01 23:02:45 +0000128 asm("sync");
wdenk9c53f402003-10-15 23:53:47 +0000129
wdenk13eb2212004-07-09 23:27:13 +0000130 /*
131 * Configure the SDRAM controller.
132 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200133 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1;
wdenk492b9e72004-08-01 23:02:45 +0000134 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000135 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000136 ppcDcbf((unsigned long) sdram_addr);
137 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000138
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200139 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2;
wdenk492b9e72004-08-01 23:02:45 +0000140 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000141 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000142 ppcDcbf((unsigned long) sdram_addr);
143 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000144
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200145 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_3;
wdenk492b9e72004-08-01 23:02:45 +0000146 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000147 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000148 ppcDcbf((unsigned long) sdram_addr);
149 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000150
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200151 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4;
wdenk492b9e72004-08-01 23:02:45 +0000152 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000153 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000154 ppcDcbf((unsigned long) sdram_addr);
155 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000156
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200157 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5;
wdenk492b9e72004-08-01 23:02:45 +0000158 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000159 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000160 ppcDcbf((unsigned long) sdram_addr);
161 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000162}
163
wdenk9c53f402003-10-15 23:53:47 +0000164#if !defined(CONFIG_SPD_EEPROM)
165/*************************************************************************
166 * fixed sdram init -- doesn't use serial presence detect.
167 ************************************************************************/
Becky Bruce5e35d8a2010-12-17 17:17:56 -0600168phys_size_t fixed_sdram(void)
wdenk9c53f402003-10-15 23:53:47 +0000169{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200170 #ifndef CONFIG_SYS_RAMBOOT
York Suna21803d2013-11-18 10:29:32 -0800171 struct ccsr_ddr __iomem *ddr =
172 (struct ccsr_ddr __iomem *)(CONFIG_SYS_FSL_DDR_ADDR);
wdenk9c53f402003-10-15 23:53:47 +0000173
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200174 ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
175 ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
176 ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
177 ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
178 ddr->sdram_mode = CONFIG_SYS_DDR_MODE;
179 ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
wdenk9c53f402003-10-15 23:53:47 +0000180 #if defined (CONFIG_DDR_ECC)
181 ddr->err_disable = 0x0000000D;
182 ddr->err_sbe = 0x00ff0000;
183 #endif
184 asm("sync;isync;msync");
185 udelay(500);
186 #if defined (CONFIG_DDR_ECC)
187 /* Enable ECC checking */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200188 ddr->sdram_cfg = (CONFIG_SYS_DDR_CONTROL | 0x20000000);
wdenk9c53f402003-10-15 23:53:47 +0000189 #else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200190 ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
wdenk9c53f402003-10-15 23:53:47 +0000191 #endif
192 asm("sync; isync; msync");
193 udelay(500);
194 #endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200195 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
wdenk9c53f402003-10-15 23:53:47 +0000196}
197#endif /* !defined(CONFIG_SPD_EEPROM) */
wdenk492b9e72004-08-01 23:02:45 +0000198
199
200#if defined(CONFIG_PCI)
201/*
202 * Initialize PCI Devices, report devices found.
203 */
204
wdenk492b9e72004-08-01 23:02:45 +0000205
Matthew McClintock8c0da862006-06-28 10:45:41 -0500206static struct pci_controller hose;
wdenk492b9e72004-08-01 23:02:45 +0000207
208#endif /* CONFIG_PCI */
209
210
211void
212pci_init_board(void)
213{
214#ifdef CONFIG_PCI
wdenk492b9e72004-08-01 23:02:45 +0000215 pci_mpc85xx_init(&hose);
216#endif /* CONFIG_PCI */
217}
Matthew McClintock148e26a2006-06-28 10:43:36 -0500218
219
Kumar Gala6e578402007-11-28 22:54:27 -0600220#if defined(CONFIG_OF_BOARD_SETUP)
Matthew McClintock148e26a2006-06-28 10:43:36 -0500221void
222ft_board_setup(void *blob, bd_t *bd)
223{
Kumar Gala6e578402007-11-28 22:54:27 -0600224 int node, tmp[2];
225 const char *path;
Matthew McClintock148e26a2006-06-28 10:43:36 -0500226
227 ft_cpu_setup(blob, bd);
228
Kumar Gala6e578402007-11-28 22:54:27 -0600229 node = fdt_path_offset(blob, "/aliases");
230 tmp[0] = 0;
231 if (node >= 0) {
232#ifdef CONFIG_PCI
233 path = fdt_getprop(blob, node, "pci0", NULL);
234 if (path) {
235 tmp[1] = hose.last_busno - hose.first_busno;
236 do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
237 }
238#endif
Matthew McClintock148e26a2006-06-28 10:43:36 -0500239 }
240}
241#endif