1 // SPDX-License-Identifier: GPL-2.0+
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
8 #include <fdt_support.h>
12 #include <asm/bitops.h>
13 #include <asm/global_data.h>
14 #include <asm/mpc8349_pci.h>
18 #ifdef CONFIG_SYS_FSL_DDR2
19 #include <fsl_ddr_sdram.h>
21 #include <spd_sdram.h>
23 #include <linux/delay.h>
25 #if defined(CONFIG_OF_LIBFDT)
26 #include <linux/libfdt.h>
29 DECLARE_GLOBAL_DATA_PTR;
31 int fixed_sdram(void);
32 void sdram_init(void);
34 #if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83xx)
35 void ddr_enable_ecc(unsigned int dram_size);
38 int board_early_init_f (void)
40 volatile u8* bcsr = (volatile u8*)CONFIG_SYS_BCSR;
42 /* Enable flash write */
45 #ifdef CONFIG_SYS_USE_MPC834XSYS_USB_PHY
46 /* Use USB PHY on SYS board */
53 #define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
57 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
58 phys_size_t msize = 0;
60 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
63 /* DDR SDRAM - Main SODIMM */
64 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR;
65 #if defined(CONFIG_SPD_EEPROM)
66 #ifndef CONFIG_SYS_FSL_DDR2
67 msize = spd_sdram() * 1024 * 1024;
68 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
69 ddr_enable_ecc(msize);
72 msize = fsl_ddr_sdram();
75 msize = fixed_sdram() * 1024 * 1024;
78 * Initialize SDRAM if it is on local bus.
82 /* set total bus SDRAM size(bytes) -- DDR */
88 #if !defined(CONFIG_SPD_EEPROM)
89 /*************************************************************************
90 * fixed sdram init -- doesn't use serial presence detect.
91 ************************************************************************/
94 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
95 u32 msize = CONFIG_SYS_DDR_SIZE;
96 u32 ddr_size = msize << 20; /* DDR size in bytes */
97 u32 ddr_size_log2 = __ilog2(ddr_size);
99 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & 0xfffff000;
100 im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
102 #if (CONFIG_SYS_DDR_SIZE != 256)
103 #warning Currenly any ddr size other than 256 is not supported
106 im->ddr.csbnds[2].csbnds = CONFIG_SYS_DDR_CS2_BNDS;
107 im->ddr.cs_config[2] = CONFIG_SYS_DDR_CS2_CONFIG;
108 im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
109 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
110 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
111 im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
112 im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
113 im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
114 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
115 im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
116 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
117 im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CNTL;
120 #if ((CONFIG_SYS_SDRAM_BASE & 0x00FFFFFF) != 0)
121 #warning Chip select bounds is only configurable in 16MB increments
123 im->ddr.csbnds[2].csbnds =
124 ((CONFIG_SYS_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
125 (((CONFIG_SYS_SDRAM_BASE + ddr_size - 1) >>
126 CSBNDS_EA_SHIFT) & CSBNDS_EA);
127 im->ddr.cs_config[2] = CONFIG_SYS_DDR_CS2_CONFIG;
129 /* currently we use only one CS, so disable the other banks */
130 im->ddr.cs_config[0] = 0;
131 im->ddr.cs_config[1] = 0;
132 im->ddr.cs_config[3] = 0;
134 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
135 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
139 #if defined(CONFIG_DDR_2T_TIMING)
142 | 2 << SDRAM_CFG_SDRAM_TYPE_SHIFT;
143 #if defined (CONFIG_DDR_32BIT)
144 /* for 32-bit mode burst length is 8 */
145 im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE);
147 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
149 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
153 /* enable DDR controller */
154 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
157 #endif/*!CONFIG_SYS_SPD_EEPROM*/
160 int checkboard (void)
163 * Warning: do not read the BCSR registers here
165 * There is a timing bug in the 8349E and 8349EA BCSR code
166 * version 1.2 (read from BCSR 11) that will cause the CFI
167 * flash initialization code to overwrite BCSR 0, disabling
168 * the serial ports and gigabit ethernet
171 puts("Board: Freescale MPC8349EMDS\n");
176 * if MPC8349EMDS is soldered with SDRAM
178 #if defined(CONFIG_SYS_BR2_PRELIM) \
179 && defined(CONFIG_SYS_OR2_PRELIM) \
180 && defined(CONFIG_SYS_LBLAWBAR2_PRELIM) \
181 && defined(CONFIG_SYS_LBLAWAR2_PRELIM)
183 * Initialize SDRAM memory on the Local Bus.
186 void sdram_init(void)
188 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
189 volatile fsl_lbc_t *lbc = &immap->im_lbc;
190 uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
191 const u32 lsdmr_common = LSDMR_RFEN | LSDMR_BSMA1516 | LSDMR_RFCR8 |
192 LSDMR_PRETOACT6 | LSDMR_ACTTORW3 | LSDMR_BL8 |
193 LSDMR_WRC3 | LSDMR_CL3;
195 * Setup SDRAM Base and Option Registers, already done in cpu_init.c
198 /* setup mtrpt, lsrt and lbcr for LB bus */
199 lbc->lbcr = 0x00000000;
200 /* LB refresh timer prescal, 266MHz/32 */
201 lbc->mrtpr = 0x20000000;
202 /* LB sdram refresh timer, about 6us */
203 lbc->lsrt = 0x32000000;
207 * Configure the SDRAM controller Machine Mode Register.
210 /* 0x40636733; normal operation */
211 lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
213 /* 0x68636733; precharge all the banks */
214 lbc->lsdmr = lsdmr_common | LSDMR_OP_PCHALL;
219 /* 0x48636733; auto refresh */
220 lbc->lsdmr = lsdmr_common | LSDMR_OP_ARFRSH;
247 /* 0x58636733; mode register write operation */
248 lbc->lsdmr = lsdmr_common | LSDMR_OP_MRW;
253 /* 0x40636733; normal operation */
254 lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
260 void sdram_init(void)
266 * The following are used to control the SPI chip selects for the SPI command.
268 #ifdef CONFIG_MPC8XXX_SPI
270 #define SPI_CS_MASK 0x80000000
272 int spi_cs_is_valid(unsigned int bus, unsigned int cs)
274 return bus == 0 && cs == 0;
277 void spi_cs_activate(struct spi_slave *slave)
279 volatile gpio83xx_t *iopd = &((immap_t *)CONFIG_SYS_IMMR)->gpio[0];
281 iopd->dat &= ~SPI_CS_MASK;
284 void spi_cs_deactivate(struct spi_slave *slave)
286 volatile gpio83xx_t *iopd = &((immap_t *)CONFIG_SYS_IMMR)->gpio[0];
288 iopd->dat |= SPI_CS_MASK;
292 #if defined(CONFIG_OF_BOARD_SETUP)
293 int ft_board_setup(void *blob, struct bd_info *bd)
295 ft_cpu_setup(blob, bd);
297 ft_pci_setup(blob, bd);