2 * Copyright 2004 Freescale Semiconductor.
3 * (C) Copyright 2002,2003, Motorola Inc.
4 * Xianghua Xiao, (X.Xiao@motorola.com)
6 * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
8 * SPDX-License-Identifier: GPL-2.0+
14 #include <asm/processor.h>
16 #include <asm/immap_85xx.h>
17 #include <fsl_ddr_sdram.h>
19 #include <fdt_support.h>
21 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
22 extern void ddr_enable_ecc(unsigned int dram_size);
25 void local_bus_init(void);
32 printf("PCI1: 32 bit, %d MHz (compiled)\n",
33 CONFIG_SYS_CLK_FREQ / 1000000);
35 printf("PCI1: disabled\n");
39 * Initialize local bus.
47 * Initialize Local Bus
53 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
54 volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
62 * Fix Local Bus clock glitch when DLL is enabled.
64 * If localbus freq is < 66MHz, DLL bypass mode must be used.
65 * If localbus freq is > 133MHz, DLL can be safely enabled.
66 * Between 66 and 133, the DLL is enabled with an override workaround.
69 get_sys_info(&sysinfo);
70 clkdiv = lbc->lcrr & LCRR_CLKDIV;
71 lbc_hz = sysinfo.freq_systembus / 1000000 / clkdiv;
74 lbc->lcrr = CONFIG_SYS_LBC_LCRR | LCRR_DBYP; /* DLL Bypass */
76 } else if (lbc_hz >= 133) {
77 lbc->lcrr = CONFIG_SYS_LBC_LCRR & (~LCRR_DBYP); /* DLL Enabled */
81 * On REV1 boards, need to change CLKDIV before enable DLL.
82 * Default CLKDIV is 8, change it to 4 temporarily.
87 if (pvr == PVR_85xx_REV1) {
88 /* FIXME: Justify the high bit here. */
89 lbc->lcrr = 0x10000004;
92 lbc->lcrr = CONFIG_SYS_LBC_LCRR & (~LCRR_DBYP); /* DLL Enabled */
96 * Sample LBC DLL ctrl reg, upshift it to set the
99 temp_lbcdll = gur->lbcdllcr;
100 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
101 asm("sync;isync;msync");
107 * Initialize SDRAM memory on the Local Bus.
109 void lbc_sdram_init(void)
111 volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
112 uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
115 print_size(CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024,
119 * Setup SDRAM Base and Option Registers
121 set_lbc_or(2, CONFIG_SYS_OR2_PRELIM);
122 set_lbc_br(2, CONFIG_SYS_BR2_PRELIM);
123 lbc->lbcr = CONFIG_SYS_LBC_LBCR;
126 lbc->lsrt = CONFIG_SYS_LBC_LSRT;
127 lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
131 * Configure the SDRAM controller.
133 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1;
136 ppcDcbf((unsigned long) sdram_addr);
139 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2;
142 ppcDcbf((unsigned long) sdram_addr);
145 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_3;
148 ppcDcbf((unsigned long) sdram_addr);
151 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4;
154 ppcDcbf((unsigned long) sdram_addr);
157 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5;
160 ppcDcbf((unsigned long) sdram_addr);
164 #if !defined(CONFIG_SPD_EEPROM)
165 /*************************************************************************
166 * fixed sdram init -- doesn't use serial presence detect.
167 ************************************************************************/
168 phys_size_t fixed_sdram(void)
170 #ifndef CONFIG_SYS_RAMBOOT
171 struct ccsr_ddr __iomem *ddr =
172 (struct ccsr_ddr __iomem *)(CONFIG_SYS_FSL_DDR_ADDR);
174 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;
180 #if defined (CONFIG_DDR_ECC)
181 ddr->err_disable = 0x0000000D;
182 ddr->err_sbe = 0x00ff0000;
184 asm("sync;isync;msync");
186 #if defined (CONFIG_DDR_ECC)
187 /* Enable ECC checking */
188 ddr->sdram_cfg = (CONFIG_SYS_DDR_CONTROL | 0x20000000);
190 ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
192 asm("sync; isync; msync");
195 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
197 #endif /* !defined(CONFIG_SPD_EEPROM) */
200 #if defined(CONFIG_PCI)
202 * Initialize PCI Devices, report devices found.
206 static struct pci_controller hose;
208 #endif /* CONFIG_PCI */
215 pci_mpc85xx_init(&hose);
216 #endif /* CONFIG_PCI */
220 #if defined(CONFIG_OF_BOARD_SETUP)
221 int ft_board_setup(void *blob, bd_t *bd)
226 ft_cpu_setup(blob, bd);
228 node = fdt_path_offset(blob, "/aliases");
232 path = fdt_getprop(blob, node, "pci0", NULL);
234 tmp[1] = hose.last_busno - hose.first_busno;
235 do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);