1 // SPDX-License-Identifier: GPL-2.0+
3 * sbc8349.c -- WindRiver SBC8349 board support.
4 * Copyright (c) 2006-2007 Wind River Systems, Inc.
7 * Based on board/mpc8349emds/mpc8349emds.c (and previous 834x releases.)
11 #include <fdt_support.h>
15 #include <asm/mpc8349_pci.h>
17 #include <spd_sdram.h>
19 #if defined(CONFIG_OF_LIBFDT)
20 #include <linux/libfdt.h>
23 DECLARE_GLOBAL_DATA_PTR;
25 int fixed_sdram(void);
26 void sdram_init(void);
28 #if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83xx)
29 void ddr_enable_ecc(unsigned int dram_size);
32 #ifdef CONFIG_BOARD_EARLY_INIT_F
33 int board_early_init_f (void)
39 #define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
43 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
46 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
49 /* DDR SDRAM - Main SODIMM */
50 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR;
51 #if defined(CONFIG_SPD_EEPROM)
54 msize = fixed_sdram();
57 * Initialize SDRAM if it is on local bus.
61 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
63 * Initialize and enable DDR ECC.
65 ddr_enable_ecc(msize * 1024 * 1024);
67 /* set total bus SDRAM size(bytes) -- DDR */
68 gd->ram_size = msize * 1024 * 1024;
73 #if !defined(CONFIG_SPD_EEPROM)
74 /*************************************************************************
75 * fixed sdram init -- doesn't use serial presence detect.
76 ************************************************************************/
79 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
80 u32 msize = CONFIG_SYS_DDR_SIZE;
81 u32 ddr_size = msize << 20; /* DDR size in bytes */
82 u32 ddr_size_log2 = __ilog2(msize);
84 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & 0xfffff000;
85 im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
87 #if (CONFIG_SYS_DDR_SIZE != 256)
88 #warning Currently any ddr size other than 256 is not supported
91 #if ((CONFIG_SYS_SDRAM_BASE & 0x00FFFFFF) != 0)
92 #warning Chip select bounds is only configurable in 16MB increments
94 im->ddr.csbnds[2].csbnds =
95 ((CONFIG_SYS_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
96 (((CONFIG_SYS_SDRAM_BASE + ddr_size - 1) >>
97 CSBNDS_EA_SHIFT) & CSBNDS_EA);
98 im->ddr.cs_config[2] = CONFIG_SYS_DDR_CS2_CONFIG;
100 /* currently we use only one CS, so disable the other banks */
101 im->ddr.cs_config[0] = 0;
102 im->ddr.cs_config[1] = 0;
103 im->ddr.cs_config[3] = 0;
105 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
106 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
110 #if defined(CONFIG_DDR_2T_TIMING)
113 | SDRAM_CFG_SDRAM_TYPE_DDR1;
114 #if defined (CONFIG_DDR_32BIT)
115 /* for 32-bit mode burst length is 8 */
116 im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE);
118 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
120 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
123 /* enable DDR controller */
124 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
127 #endif/*!CONFIG_SYS_SPD_EEPROM*/
130 int checkboard (void)
132 puts("Board: Wind River SBC834x\n");
137 * if board is fitted with SDRAM
139 #if defined(CONFIG_SYS_BR2_PRELIM) \
140 && defined(CONFIG_SYS_OR2_PRELIM) \
141 && defined(CONFIG_SYS_LBLAWBAR2_PRELIM) \
142 && defined(CONFIG_SYS_LBLAWAR2_PRELIM)
144 * Initialize SDRAM memory on the Local Bus.
147 void sdram_init(void)
149 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
150 volatile fsl_lbc_t *lbc = &immap->im_lbc;
151 uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
152 const u32 lsdmr_common = LSDMR_RFEN | LSDMR_BSMA1516 | LSDMR_RFCR8 |
153 LSDMR_PRETOACT6 | LSDMR_ACTTORW3 | LSDMR_BL8 |
154 LSDMR_WRC3 | LSDMR_CL3;
156 puts("\n SDRAM on Local Bus: ");
157 print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
160 * Setup SDRAM Base and Option Registers, already done in cpu_init.c
163 /* setup mtrpt, lsrt and lbcr for LB bus */
164 lbc->lbcr = 0x00000000;
165 /* LB refresh timer prescal, 266MHz/32 */
166 lbc->mrtpr = 0x20000000;
167 /* LB sdram refresh timer, about 6us */
168 lbc->lsrt = 0x32000000;
172 * Configure the SDRAM controller Machine Mode Register.
174 /* 0x40636733; normal operation */
175 lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
177 /* 0x68636733; precharge all the banks */
178 lbc->lsdmr = lsdmr_common | LSDMR_OP_PCHALL;
183 /* 0x48636733; auto refresh */
184 lbc->lsdmr = lsdmr_common | LSDMR_OP_ARFRSH;
211 /* 0x58636733; mode register write operation */
212 lbc->lsdmr = lsdmr_common | LSDMR_OP_MRW;
217 /* 0x40636733; normal operation */
218 lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
224 void sdram_init(void)
226 puts(" SDRAM on Local Bus: Disabled in config\n");
230 #if defined(CONFIG_OF_BOARD_SETUP)
231 int ft_board_setup(void *blob, bd_t *bd)
233 ft_cpu_setup(blob, bd);
235 ft_pci_setup(blob, bd);