blob: 93288c7e9ce0252f8a7ee1ecdaa3b2e9f9153919 [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 *
Wolfgang Denk3765b3e2013-10-07 13:07:26 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenk42d1f032003-10-15 23:53:47 +00009 */
10
11
wdenk42d1f032003-10-15 23:53:47 +000012#include <common.h>
wdenk9aea9532004-08-01 23:02:45 +000013#include <pci.h>
wdenk42d1f032003-10-15 23:53:47 +000014#include <asm/processor.h>
Kumar Gala9617c8d2008-06-06 13:12:18 -050015#include <asm/mmu.h>
wdenk42d1f032003-10-15 23:53:47 +000016#include <asm/immap_85xx.h>
York Sun5614e712013-09-30 09:22:09 -070017#include <fsl_ddr_sdram.h>
Kumar Gala0fd5ec62007-11-28 22:54:27 -060018#include <libfdt.h>
19#include <fdt_support.h>
Matthew McClintock40d5fa32006-06-28 10:43:36 -050020
Jon Loeligerd9b94f22005-07-25 14:05:07 -050021#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
wdenk0ac6f8b2004-07-09 23:27:13 +000022extern void ddr_enable_ecc(unsigned int dram_size);
wdenk97d80fc2004-06-09 00:34:46 +000023#endif
24
wdenk9aea9532004-08-01 23:02:45 +000025void local_bus_init(void);
wdenk0ac6f8b2004-07-09 23:27:13 +000026
wdenk42d1f032003-10-15 23:53:47 +000027int checkboard (void)
28{
wdenk97d80fc2004-06-09 00:34:46 +000029 puts("Board: ADS\n");
wdenk0ac6f8b2004-07-09 23:27:13 +000030
31#ifdef CONFIG_PCI
Peter Tyser8ca78f22010-10-29 17:59:24 -050032 printf("PCI1: 32 bit, %d MHz (compiled)\n",
wdenk0ac6f8b2004-07-09 23:27:13 +000033 CONFIG_SYS_CLK_FREQ / 1000000);
34#else
Peter Tyser8ca78f22010-10-29 17:59:24 -050035 printf("PCI1: disabled\n");
wdenk0ac6f8b2004-07-09 23:27:13 +000036#endif
37
wdenk9aea9532004-08-01 23:02:45 +000038 /*
39 * Initialize local bus.
40 */
41 local_bus_init();
42
wdenk97d80fc2004-06-09 00:34:46 +000043 return 0;
wdenk42d1f032003-10-15 23:53:47 +000044}
45
wdenk0ac6f8b2004-07-09 23:27:13 +000046/*
wdenk9aea9532004-08-01 23:02:45 +000047 * Initialize Local Bus
wdenk0ac6f8b2004-07-09 23:27:13 +000048 */
49
wdenk9aea9532004-08-01 23:02:45 +000050void
51local_bus_init(void)
wdenk0ac6f8b2004-07-09 23:27:13 +000052{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020053 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Becky Brucef51cdaf2010-06-17 11:37:20 -050054 volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
wdenk0ac6f8b2004-07-09 23:27:13 +000055
wdenk9aea9532004-08-01 23:02:45 +000056 uint clkdiv;
57 uint lbc_hz;
58 sys_info_t sysinfo;
wdenk0ac6f8b2004-07-09 23:27:13 +000059
60 /*
wdenk9aea9532004-08-01 23:02:45 +000061 * Errata LBC11.
62 * Fix Local Bus clock glitch when DLL is enabled.
wdenk0ac6f8b2004-07-09 23:27:13 +000063 *
Wolfgang Denk8ed44d92008-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.
wdenk9aea9532004-08-01 23:02:45 +000066 * Between 66 and 133, the DLL is enabled with an override workaround.
wdenk0ac6f8b2004-07-09 23:27:13 +000067 */
wdenk9aea9532004-08-01 23:02:45 +000068
69 get_sys_info(&sysinfo);
Trent Piephoa5d212a2008-12-03 15:16:34 -080070 clkdiv = lbc->lcrr & LCRR_CLKDIV;
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053071 lbc_hz = sysinfo.freq_systembus / 1000000 / clkdiv;
wdenk9aea9532004-08-01 23:02:45 +000072
73 if (lbc_hz < 66) {
Paul Gortmakera2af6a72012-08-13 13:48:57 +000074 lbc->lcrr = CONFIG_SYS_LBC_LCRR | LCRR_DBYP; /* DLL Bypass */
wdenk9aea9532004-08-01 23:02:45 +000075
76 } else if (lbc_hz >= 133) {
Paul Gortmakera2af6a72012-08-13 13:48:57 +000077 lbc->lcrr = CONFIG_SYS_LBC_LCRR & (~LCRR_DBYP); /* DLL Enabled */
wdenk0ac6f8b2004-07-09 23:27:13 +000078
wdenk42d1f032003-10-15 23:53:47 +000079 } else {
wdenk0ac6f8b2004-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 */
wdenk9aea9532004-08-01 23:02:45 +000084 uint pvr = get_pvr();
wdenk0ac6f8b2004-07-09 23:27:13 +000085 uint temp_lbcdll = 0;
wdenk97d80fc2004-06-09 00:34:46 +000086
87 if (pvr == PVR_85xx_REV1) {
wdenk9aea9532004-08-01 23:02:45 +000088 /* FIXME: Justify the high bit here. */
wdenk0ac6f8b2004-07-09 23:27:13 +000089 lbc->lcrr = 0x10000004;
wdenk97d80fc2004-06-09 00:34:46 +000090 }
wdenk0ac6f8b2004-07-09 23:27:13 +000091
Paul Gortmakera2af6a72012-08-13 13:48:57 +000092 lbc->lcrr = CONFIG_SYS_LBC_LCRR & (~LCRR_DBYP); /* DLL Enabled */
wdenk9aea9532004-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 */
wdenk42d1f032003-10-15 23:53:47 +000099 temp_lbcdll = gur->lbcdllcr;
wdenk9aea9532004-08-01 23:02:45 +0000100 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
101 asm("sync;isync;msync");
wdenk42d1f032003-10-15 23:53:47 +0000102 }
wdenk9aea9532004-08-01 23:02:45 +0000103}
104
105
106/*
107 * Initialize SDRAM memory on the Local Bus.
108 */
Becky Bruce70961ba2010-12-17 17:17:57 -0600109void lbc_sdram_init(void)
wdenk9aea9532004-08-01 23:02:45 +0000110{
Becky Brucef51cdaf2010-06-17 11:37:20 -0500111 volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200112 uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
wdenk9aea9532004-08-01 23:02:45 +0000113
Becky Bruce7ea38712010-12-17 17:17:59 -0600114 puts("LBC SDRAM: ");
115 print_size(CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024,
116 "\n ");
wdenk0ac6f8b2004-07-09 23:27:13 +0000117
118 /*
119 * Setup SDRAM Base and Option Registers
120 */
Becky Brucef51cdaf2010-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-VILLARD6d0f6bc2008-10-16 15:01:15 +0200123 lbc->lbcr = CONFIG_SYS_LBC_LBCR;
wdenk9aea9532004-08-01 23:02:45 +0000124 asm("msync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000125
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200126 lbc->lsrt = CONFIG_SYS_LBC_LSRT;
127 lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
wdenk9aea9532004-08-01 23:02:45 +0000128 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000129
130 /*
131 * Configure the SDRAM controller.
132 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200133 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1;
wdenk9aea9532004-08-01 23:02:45 +0000134 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000135 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000136 ppcDcbf((unsigned long) sdram_addr);
137 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000138
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200139 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2;
wdenk9aea9532004-08-01 23:02:45 +0000140 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000141 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000142 ppcDcbf((unsigned long) sdram_addr);
143 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000144
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200145 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_3;
wdenk9aea9532004-08-01 23:02:45 +0000146 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000147 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000148 ppcDcbf((unsigned long) sdram_addr);
149 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000150
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200151 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4;
wdenk9aea9532004-08-01 23:02:45 +0000152 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000153 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000154 ppcDcbf((unsigned long) sdram_addr);
155 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000156
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200157 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5;
wdenk9aea9532004-08-01 23:02:45 +0000158 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000159 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000160 ppcDcbf((unsigned long) sdram_addr);
161 udelay(100);
wdenk42d1f032003-10-15 23:53:47 +0000162}
163
wdenk42d1f032003-10-15 23:53:47 +0000164#if !defined(CONFIG_SPD_EEPROM)
165/*************************************************************************
166 * fixed sdram init -- doesn't use serial presence detect.
167 ************************************************************************/
Becky Bruce38dba0c2010-12-17 17:17:56 -0600168phys_size_t fixed_sdram(void)
wdenk42d1f032003-10-15 23:53:47 +0000169{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200170 #ifndef CONFIG_SYS_RAMBOOT
York Sun9a17eb52013-11-18 10:29:32 -0800171 struct ccsr_ddr __iomem *ddr =
172 (struct ccsr_ddr __iomem *)(CONFIG_SYS_FSL_DDR_ADDR);
wdenk42d1f032003-10-15 23:53:47 +0000173
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-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;
wdenk42d1f032003-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-VILLARD6d0f6bc2008-10-16 15:01:15 +0200188 ddr->sdram_cfg = (CONFIG_SYS_DDR_CONTROL | 0x20000000);
wdenk42d1f032003-10-15 23:53:47 +0000189 #else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200190 ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
wdenk42d1f032003-10-15 23:53:47 +0000191 #endif
192 asm("sync; isync; msync");
193 udelay(500);
194 #endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200195 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
wdenk42d1f032003-10-15 23:53:47 +0000196}
197#endif /* !defined(CONFIG_SPD_EEPROM) */
wdenk9aea9532004-08-01 23:02:45 +0000198
199
200#if defined(CONFIG_PCI)
201/*
202 * Initialize PCI Devices, report devices found.
203 */
204
wdenk9aea9532004-08-01 23:02:45 +0000205
Matthew McClintock52c7a682006-06-28 10:45:41 -0500206static struct pci_controller hose;
wdenk9aea9532004-08-01 23:02:45 +0000207
208#endif /* CONFIG_PCI */
209
210
211void
212pci_init_board(void)
213{
214#ifdef CONFIG_PCI
wdenk9aea9532004-08-01 23:02:45 +0000215 pci_mpc85xx_init(&hose);
216#endif /* CONFIG_PCI */
217}
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500218
219
Kumar Gala0fd5ec62007-11-28 22:54:27 -0600220#if defined(CONFIG_OF_BOARD_SETUP)
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500221void
222ft_board_setup(void *blob, bd_t *bd)
223{
Kumar Gala0fd5ec62007-11-28 22:54:27 -0600224 int node, tmp[2];
225 const char *path;
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500226
227 ft_cpu_setup(blob, bd);
228
Kumar Gala0fd5ec62007-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 McClintock40d5fa32006-06-28 10:43:36 -0500239 }
240}
241#endif