xref: /OK3568_Linux_fs/u-boot/board/sbc8349/sbc8349.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * sbc8349.c -- WindRiver SBC8349 board support.
3*4882a593Smuzhiyun  * Copyright (c) 2006-2007 Wind River Systems, Inc.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Paul Gortmaker <paul.gortmaker@windriver.com>
6*4882a593Smuzhiyun  * Based on board/mpc8349emds/mpc8349emds.c (and previous 834x releases.)
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
9*4882a593Smuzhiyun  */
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include <common.h>
12*4882a593Smuzhiyun #include <ioports.h>
13*4882a593Smuzhiyun #include <mpc83xx.h>
14*4882a593Smuzhiyun #include <asm/mpc8349_pci.h>
15*4882a593Smuzhiyun #include <i2c.h>
16*4882a593Smuzhiyun #include <spd_sdram.h>
17*4882a593Smuzhiyun #include <miiphy.h>
18*4882a593Smuzhiyun #if defined(CONFIG_OF_LIBFDT)
19*4882a593Smuzhiyun #include <linux/libfdt.h>
20*4882a593Smuzhiyun #endif
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun DECLARE_GLOBAL_DATA_PTR;
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun int fixed_sdram(void);
25*4882a593Smuzhiyun void sdram_init(void);
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83xx)
28*4882a593Smuzhiyun void ddr_enable_ecc(unsigned int dram_size);
29*4882a593Smuzhiyun #endif
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #ifdef CONFIG_BOARD_EARLY_INIT_F
board_early_init_f(void)32*4882a593Smuzhiyun int board_early_init_f (void)
33*4882a593Smuzhiyun {
34*4882a593Smuzhiyun 	return 0;
35*4882a593Smuzhiyun }
36*4882a593Smuzhiyun #endif
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun #define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
39*4882a593Smuzhiyun 
dram_init(void)40*4882a593Smuzhiyun int dram_init(void)
41*4882a593Smuzhiyun {
42*4882a593Smuzhiyun 	volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
43*4882a593Smuzhiyun 	u32 msize = 0;
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun 	if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
46*4882a593Smuzhiyun 		return -1;
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun 	/* DDR SDRAM - Main SODIMM */
49*4882a593Smuzhiyun 	im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_BASE & LAWBAR_BAR;
50*4882a593Smuzhiyun #if defined(CONFIG_SPD_EEPROM)
51*4882a593Smuzhiyun 	msize = spd_sdram();
52*4882a593Smuzhiyun #else
53*4882a593Smuzhiyun 	msize = fixed_sdram();
54*4882a593Smuzhiyun #endif
55*4882a593Smuzhiyun 	/*
56*4882a593Smuzhiyun 	 * Initialize SDRAM if it is on local bus.
57*4882a593Smuzhiyun 	 */
58*4882a593Smuzhiyun 	sdram_init();
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
61*4882a593Smuzhiyun 	/*
62*4882a593Smuzhiyun 	 * Initialize and enable DDR ECC.
63*4882a593Smuzhiyun 	 */
64*4882a593Smuzhiyun 	ddr_enable_ecc(msize * 1024 * 1024);
65*4882a593Smuzhiyun #endif
66*4882a593Smuzhiyun 	/* set total bus SDRAM size(bytes)  -- DDR */
67*4882a593Smuzhiyun 	gd->ram_size = msize * 1024 * 1024;
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun 	return 0;
70*4882a593Smuzhiyun }
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun #if !defined(CONFIG_SPD_EEPROM)
73*4882a593Smuzhiyun /*************************************************************************
74*4882a593Smuzhiyun  *  fixed sdram init -- doesn't use serial presence detect.
75*4882a593Smuzhiyun  ************************************************************************/
fixed_sdram(void)76*4882a593Smuzhiyun int fixed_sdram(void)
77*4882a593Smuzhiyun {
78*4882a593Smuzhiyun 	volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
79*4882a593Smuzhiyun 	u32 msize = CONFIG_SYS_DDR_SIZE;
80*4882a593Smuzhiyun 	u32 ddr_size = msize << 20;	/* DDR size in bytes */
81*4882a593Smuzhiyun 	u32 ddr_size_log2 = __ilog2(msize);
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun 	im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
84*4882a593Smuzhiyun 	im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun #if (CONFIG_SYS_DDR_SIZE != 256)
87*4882a593Smuzhiyun #warning Currently any ddr size other than 256 is not supported
88*4882a593Smuzhiyun #endif
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun #if ((CONFIG_SYS_DDR_SDRAM_BASE & 0x00FFFFFF) != 0)
91*4882a593Smuzhiyun #warning Chip select bounds is only configurable in 16MB increments
92*4882a593Smuzhiyun #endif
93*4882a593Smuzhiyun 	im->ddr.csbnds[2].csbnds =
94*4882a593Smuzhiyun 		((CONFIG_SYS_DDR_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
95*4882a593Smuzhiyun 		(((CONFIG_SYS_DDR_SDRAM_BASE + ddr_size - 1) >>
96*4882a593Smuzhiyun 				CSBNDS_EA_SHIFT) & CSBNDS_EA);
97*4882a593Smuzhiyun 	im->ddr.cs_config[2] = CONFIG_SYS_DDR_CS2_CONFIG;
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun 	/* currently we use only one CS, so disable the other banks */
100*4882a593Smuzhiyun 	im->ddr.cs_config[0] = 0;
101*4882a593Smuzhiyun 	im->ddr.cs_config[1] = 0;
102*4882a593Smuzhiyun 	im->ddr.cs_config[3] = 0;
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun 	im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
105*4882a593Smuzhiyun 	im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun 	im->ddr.sdram_cfg =
108*4882a593Smuzhiyun 		SDRAM_CFG_SREN
109*4882a593Smuzhiyun #if defined(CONFIG_DDR_2T_TIMING)
110*4882a593Smuzhiyun 		| SDRAM_CFG_2T_EN
111*4882a593Smuzhiyun #endif
112*4882a593Smuzhiyun 		| SDRAM_CFG_SDRAM_TYPE_DDR1;
113*4882a593Smuzhiyun #if defined (CONFIG_DDR_32BIT)
114*4882a593Smuzhiyun 	/* for 32-bit mode burst length is 8 */
115*4882a593Smuzhiyun 	im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE);
116*4882a593Smuzhiyun #endif
117*4882a593Smuzhiyun 	im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun 	im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
120*4882a593Smuzhiyun 	udelay(200);
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun 	/* enable DDR controller */
123*4882a593Smuzhiyun 	im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
124*4882a593Smuzhiyun 	return msize;
125*4882a593Smuzhiyun }
126*4882a593Smuzhiyun #endif/*!CONFIG_SYS_SPD_EEPROM*/
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun 
checkboard(void)129*4882a593Smuzhiyun int checkboard (void)
130*4882a593Smuzhiyun {
131*4882a593Smuzhiyun 	puts("Board: Wind River SBC834x\n");
132*4882a593Smuzhiyun 	return 0;
133*4882a593Smuzhiyun }
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun /*
136*4882a593Smuzhiyun  * if board is fitted with SDRAM
137*4882a593Smuzhiyun  */
138*4882a593Smuzhiyun #if defined(CONFIG_SYS_BR2_PRELIM)  \
139*4882a593Smuzhiyun 	&& defined(CONFIG_SYS_OR2_PRELIM) \
140*4882a593Smuzhiyun 	&& defined(CONFIG_SYS_LBLAWBAR2_PRELIM) \
141*4882a593Smuzhiyun 	&& defined(CONFIG_SYS_LBLAWAR2_PRELIM)
142*4882a593Smuzhiyun /*
143*4882a593Smuzhiyun  * Initialize SDRAM memory on the Local Bus.
144*4882a593Smuzhiyun  */
145*4882a593Smuzhiyun 
sdram_init(void)146*4882a593Smuzhiyun void sdram_init(void)
147*4882a593Smuzhiyun {
148*4882a593Smuzhiyun 	volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
149*4882a593Smuzhiyun 	volatile fsl_lbc_t *lbc = &immap->im_lbc;
150*4882a593Smuzhiyun 	uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun 	puts("\n   SDRAM on Local Bus: ");
153*4882a593Smuzhiyun 	print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun 	/*
156*4882a593Smuzhiyun 	 * Setup SDRAM Base and Option Registers, already done in cpu_init.c
157*4882a593Smuzhiyun 	 */
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 	/* setup mtrpt, lsrt and lbcr for LB bus */
160*4882a593Smuzhiyun 	lbc->lbcr = CONFIG_SYS_LBC_LBCR;
161*4882a593Smuzhiyun 	lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
162*4882a593Smuzhiyun 	lbc->lsrt = CONFIG_SYS_LBC_LSRT;
163*4882a593Smuzhiyun 	asm("sync");
164*4882a593Smuzhiyun 
165*4882a593Smuzhiyun 	/*
166*4882a593Smuzhiyun 	 * Configure the SDRAM controller Machine Mode Register.
167*4882a593Smuzhiyun 	 */
168*4882a593Smuzhiyun 	lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5; /* 0x40636733; normal operation */
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun 	lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1; /* 0x68636733; precharge all the banks */
171*4882a593Smuzhiyun 	asm("sync");
172*4882a593Smuzhiyun 	*sdram_addr = 0xff;
173*4882a593Smuzhiyun 	udelay(100);
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun 	lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2; /* 0x48636733; auto refresh */
176*4882a593Smuzhiyun 	asm("sync");
177*4882a593Smuzhiyun 	/*1 times*/
178*4882a593Smuzhiyun 	*sdram_addr = 0xff;
179*4882a593Smuzhiyun 	udelay(100);
180*4882a593Smuzhiyun 	/*2 times*/
181*4882a593Smuzhiyun 	*sdram_addr = 0xff;
182*4882a593Smuzhiyun 	udelay(100);
183*4882a593Smuzhiyun 	/*3 times*/
184*4882a593Smuzhiyun 	*sdram_addr = 0xff;
185*4882a593Smuzhiyun 	udelay(100);
186*4882a593Smuzhiyun 	/*4 times*/
187*4882a593Smuzhiyun 	*sdram_addr = 0xff;
188*4882a593Smuzhiyun 	udelay(100);
189*4882a593Smuzhiyun 	/*5 times*/
190*4882a593Smuzhiyun 	*sdram_addr = 0xff;
191*4882a593Smuzhiyun 	udelay(100);
192*4882a593Smuzhiyun 	/*6 times*/
193*4882a593Smuzhiyun 	*sdram_addr = 0xff;
194*4882a593Smuzhiyun 	udelay(100);
195*4882a593Smuzhiyun 	/*7 times*/
196*4882a593Smuzhiyun 	*sdram_addr = 0xff;
197*4882a593Smuzhiyun 	udelay(100);
198*4882a593Smuzhiyun 	/*8 times*/
199*4882a593Smuzhiyun 	*sdram_addr = 0xff;
200*4882a593Smuzhiyun 	udelay(100);
201*4882a593Smuzhiyun 
202*4882a593Smuzhiyun 	/* 0x58636733; mode register write operation */
203*4882a593Smuzhiyun 	lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4;
204*4882a593Smuzhiyun 	asm("sync");
205*4882a593Smuzhiyun 	*sdram_addr = 0xff;
206*4882a593Smuzhiyun 	udelay(100);
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun 	lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5; /* 0x40636733; normal operation */
209*4882a593Smuzhiyun 	asm("sync");
210*4882a593Smuzhiyun 	*sdram_addr = 0xff;
211*4882a593Smuzhiyun 	udelay(100);
212*4882a593Smuzhiyun }
213*4882a593Smuzhiyun #else
sdram_init(void)214*4882a593Smuzhiyun void sdram_init(void)
215*4882a593Smuzhiyun {
216*4882a593Smuzhiyun 	puts("   SDRAM on Local Bus: Disabled in config\n");
217*4882a593Smuzhiyun }
218*4882a593Smuzhiyun #endif
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun #if defined(CONFIG_OF_BOARD_SETUP)
ft_board_setup(void * blob,bd_t * bd)221*4882a593Smuzhiyun int ft_board_setup(void *blob, bd_t *bd)
222*4882a593Smuzhiyun {
223*4882a593Smuzhiyun 	ft_cpu_setup(blob, bd);
224*4882a593Smuzhiyun #ifdef CONFIG_PCI
225*4882a593Smuzhiyun 	ft_pci_setup(blob, bd);
226*4882a593Smuzhiyun #endif
227*4882a593Smuzhiyun 
228*4882a593Smuzhiyun 	return 0;
229*4882a593Smuzhiyun }
230*4882a593Smuzhiyun #endif
231