xref: /rk3399_rockchip-uboot/board/sbc8349/sbc8349.c (revision b3458d2cd55d01732e30a76d898afd99e871cd67)
191e25769SPaul Gortmaker /*
291e25769SPaul Gortmaker  * sbc8349.c -- WindRiver SBC8349 board support.
391e25769SPaul Gortmaker  * Copyright (c) 2006-2007 Wind River Systems, Inc.
491e25769SPaul Gortmaker  *
591e25769SPaul Gortmaker  * Paul Gortmaker <paul.gortmaker@windriver.com>
691e25769SPaul Gortmaker  * Based on board/mpc8349emds/mpc8349emds.c (and previous 834x releases.)
791e25769SPaul Gortmaker  *
891e25769SPaul Gortmaker  * See file CREDITS for list of people who contributed to this
991e25769SPaul Gortmaker  * project.
1091e25769SPaul Gortmaker  *
1191e25769SPaul Gortmaker  * This program is free software; you can redistribute it and/or
1291e25769SPaul Gortmaker  * modify it under the terms of the GNU General Public License as
1391e25769SPaul Gortmaker  * published by the Free Software Foundation; either version 2 of
1491e25769SPaul Gortmaker  * the License, or (at your option) any later version.
1591e25769SPaul Gortmaker  *
1691e25769SPaul Gortmaker  * This program is distributed in the hope that it will be useful,
1791e25769SPaul Gortmaker  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1891e25769SPaul Gortmaker  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1991e25769SPaul Gortmaker  * GNU General Public License for more details.
2091e25769SPaul Gortmaker  *
2191e25769SPaul Gortmaker  * You should have received a copy of the GNU General Public License
2291e25769SPaul Gortmaker  * along with this program; if not, write to the Free Software
2391e25769SPaul Gortmaker  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
2491e25769SPaul Gortmaker  * MA 02111-1307 USA
2591e25769SPaul Gortmaker  *
2691e25769SPaul Gortmaker  */
2791e25769SPaul Gortmaker 
2891e25769SPaul Gortmaker #include <common.h>
2991e25769SPaul Gortmaker #include <ioports.h>
3091e25769SPaul Gortmaker #include <mpc83xx.h>
3191e25769SPaul Gortmaker #include <asm/mpc8349_pci.h>
3291e25769SPaul Gortmaker #include <i2c.h>
3391e25769SPaul Gortmaker #include <spd.h>
3491e25769SPaul Gortmaker #include <miiphy.h>
3591e25769SPaul Gortmaker #if defined(CONFIG_SPD_EEPROM)
3691e25769SPaul Gortmaker #include <spd_sdram.h>
3791e25769SPaul Gortmaker #endif
38*b3458d2cSKim Phillips #if defined(CONFIG_OF_LIBFDT)
392408b3f2SPaul Gortmaker #include <libfdt.h>
4091e25769SPaul Gortmaker #endif
4191e25769SPaul Gortmaker 
4291e25769SPaul Gortmaker int fixed_sdram(void);
4391e25769SPaul Gortmaker void sdram_init(void);
4491e25769SPaul Gortmaker 
4591e25769SPaul Gortmaker #if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83XX)
4691e25769SPaul Gortmaker void ddr_enable_ecc(unsigned int dram_size);
4791e25769SPaul Gortmaker #endif
4891e25769SPaul Gortmaker 
4991e25769SPaul Gortmaker #ifdef CONFIG_BOARD_EARLY_INIT_F
5091e25769SPaul Gortmaker int board_early_init_f (void)
5191e25769SPaul Gortmaker {
5291e25769SPaul Gortmaker 	return 0;
5391e25769SPaul Gortmaker }
5491e25769SPaul Gortmaker #endif
5591e25769SPaul Gortmaker 
5691e25769SPaul Gortmaker #define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
5791e25769SPaul Gortmaker 
5891e25769SPaul Gortmaker long int initdram (int board_type)
5991e25769SPaul Gortmaker {
6091e25769SPaul Gortmaker 	volatile immap_t *im = (immap_t *)CFG_IMMR;
6191e25769SPaul Gortmaker 	u32 msize = 0;
6291e25769SPaul Gortmaker 
6391e25769SPaul Gortmaker 	if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
6491e25769SPaul Gortmaker 		return -1;
6591e25769SPaul Gortmaker 
6691e25769SPaul Gortmaker 	/* DDR SDRAM - Main SODIMM */
6791e25769SPaul Gortmaker 	im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR;
6891e25769SPaul Gortmaker #if defined(CONFIG_SPD_EEPROM)
6991e25769SPaul Gortmaker 	msize = spd_sdram();
7091e25769SPaul Gortmaker #else
7191e25769SPaul Gortmaker 	msize = fixed_sdram();
7291e25769SPaul Gortmaker #endif
7391e25769SPaul Gortmaker 	/*
7491e25769SPaul Gortmaker 	 * Initialize SDRAM if it is on local bus.
7591e25769SPaul Gortmaker 	 */
7691e25769SPaul Gortmaker 	sdram_init();
7791e25769SPaul Gortmaker 
7891e25769SPaul Gortmaker #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
7991e25769SPaul Gortmaker 	/*
8091e25769SPaul Gortmaker 	 * Initialize and enable DDR ECC.
8191e25769SPaul Gortmaker 	 */
8291e25769SPaul Gortmaker 	ddr_enable_ecc(msize * 1024 * 1024);
8391e25769SPaul Gortmaker #endif
8491e25769SPaul Gortmaker 	/* return total bus SDRAM size(bytes)  -- DDR */
8591e25769SPaul Gortmaker 	return (msize * 1024 * 1024);
8691e25769SPaul Gortmaker }
8791e25769SPaul Gortmaker 
8891e25769SPaul Gortmaker #if !defined(CONFIG_SPD_EEPROM)
8991e25769SPaul Gortmaker /*************************************************************************
9091e25769SPaul Gortmaker  *  fixed sdram init -- doesn't use serial presence detect.
9191e25769SPaul Gortmaker  ************************************************************************/
9291e25769SPaul Gortmaker int fixed_sdram(void)
9391e25769SPaul Gortmaker {
9491e25769SPaul Gortmaker 	volatile immap_t *im = (immap_t *)CFG_IMMR;
9591e25769SPaul Gortmaker 	u32 msize = 0;
9691e25769SPaul Gortmaker 	u32 ddr_size;
9791e25769SPaul Gortmaker 	u32 ddr_size_log2;
9891e25769SPaul Gortmaker 
9991e25769SPaul Gortmaker 	msize = CFG_DDR_SIZE;
10091e25769SPaul Gortmaker 	for (ddr_size = msize << 20, ddr_size_log2 = 0;
10191e25769SPaul Gortmaker 	     (ddr_size > 1);
10291e25769SPaul Gortmaker 	     ddr_size = ddr_size>>1, ddr_size_log2++) {
10391e25769SPaul Gortmaker 		if (ddr_size & 1) {
10491e25769SPaul Gortmaker 			return -1;
10591e25769SPaul Gortmaker 		}
10691e25769SPaul Gortmaker 	}
10791e25769SPaul Gortmaker 	im->sysconf.ddrlaw[0].bar = ((CFG_DDR_SDRAM_BASE>>12) & 0xfffff);
10891e25769SPaul Gortmaker 	im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
10991e25769SPaul Gortmaker 
11091e25769SPaul Gortmaker #if (CFG_DDR_SIZE != 256)
11191e25769SPaul Gortmaker #warning Currently any ddr size other than 256 is not supported
11291e25769SPaul Gortmaker #endif
11391e25769SPaul Gortmaker 	im->ddr.csbnds[2].csbnds = 0x0000000f;
11491e25769SPaul Gortmaker 	im->ddr.cs_config[2] = CFG_DDR_CONFIG;
11591e25769SPaul Gortmaker 
11691e25769SPaul Gortmaker 	/* currently we use only one CS, so disable the other banks */
11791e25769SPaul Gortmaker 	im->ddr.cs_config[0] = 0;
11891e25769SPaul Gortmaker 	im->ddr.cs_config[1] = 0;
11991e25769SPaul Gortmaker 	im->ddr.cs_config[3] = 0;
12091e25769SPaul Gortmaker 
12191e25769SPaul Gortmaker 	im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
12291e25769SPaul Gortmaker 	im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
12391e25769SPaul Gortmaker 
12491e25769SPaul Gortmaker 	im->ddr.sdram_cfg =
12591e25769SPaul Gortmaker 		SDRAM_CFG_SREN
12691e25769SPaul Gortmaker #if defined(CONFIG_DDR_2T_TIMING)
12791e25769SPaul Gortmaker 		| SDRAM_CFG_2T_EN
12891e25769SPaul Gortmaker #endif
129bbea46f7SKim Phillips 		| SDRAM_CFG_SDRAM_TYPE_DDR1;
13091e25769SPaul Gortmaker #if defined (CONFIG_DDR_32BIT)
13191e25769SPaul Gortmaker 	/* for 32-bit mode burst length is 8 */
13291e25769SPaul Gortmaker 	im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE);
13391e25769SPaul Gortmaker #endif
13491e25769SPaul Gortmaker 	im->ddr.sdram_mode = CFG_DDR_MODE;
13591e25769SPaul Gortmaker 
13691e25769SPaul Gortmaker 	im->ddr.sdram_interval = CFG_DDR_INTERVAL;
13791e25769SPaul Gortmaker 	udelay(200);
13891e25769SPaul Gortmaker 
13991e25769SPaul Gortmaker 	/* enable DDR controller */
14091e25769SPaul Gortmaker 	im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
14191e25769SPaul Gortmaker 	return msize;
14291e25769SPaul Gortmaker }
14391e25769SPaul Gortmaker #endif/*!CFG_SPD_EEPROM*/
14491e25769SPaul Gortmaker 
14591e25769SPaul Gortmaker 
14691e25769SPaul Gortmaker int checkboard (void)
14791e25769SPaul Gortmaker {
14891e25769SPaul Gortmaker 	puts("Board: Wind River SBC834x\n");
14991e25769SPaul Gortmaker 	return 0;
15091e25769SPaul Gortmaker }
15191e25769SPaul Gortmaker 
15291e25769SPaul Gortmaker /*
15391e25769SPaul Gortmaker  * if board is fitted with SDRAM
15491e25769SPaul Gortmaker  */
15591e25769SPaul Gortmaker #if defined(CFG_BR2_PRELIM)  \
15691e25769SPaul Gortmaker 	&& defined(CFG_OR2_PRELIM) \
15791e25769SPaul Gortmaker 	&& defined(CFG_LBLAWBAR2_PRELIM) \
15891e25769SPaul Gortmaker 	&& defined(CFG_LBLAWAR2_PRELIM)
15991e25769SPaul Gortmaker /*
16091e25769SPaul Gortmaker  * Initialize SDRAM memory on the Local Bus.
16191e25769SPaul Gortmaker  */
16291e25769SPaul Gortmaker 
16391e25769SPaul Gortmaker void sdram_init(void)
16491e25769SPaul Gortmaker {
16591e25769SPaul Gortmaker 	volatile immap_t *immap = (immap_t *)CFG_IMMR;
16691e25769SPaul Gortmaker 	volatile lbus83xx_t *lbc= &immap->lbus;
16791e25769SPaul Gortmaker 	uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
16891e25769SPaul Gortmaker 
16991e25769SPaul Gortmaker 	puts("\n   SDRAM on Local Bus: ");
17091e25769SPaul Gortmaker 	print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
17191e25769SPaul Gortmaker 
17291e25769SPaul Gortmaker 	/*
17391e25769SPaul Gortmaker 	 * Setup SDRAM Base and Option Registers, already done in cpu_init.c
17491e25769SPaul Gortmaker 	 */
17591e25769SPaul Gortmaker 
17691e25769SPaul Gortmaker 	/* setup mtrpt, lsrt and lbcr for LB bus */
17791e25769SPaul Gortmaker 	lbc->lbcr = CFG_LBC_LBCR;
17891e25769SPaul Gortmaker 	lbc->mrtpr = CFG_LBC_MRTPR;
17991e25769SPaul Gortmaker 	lbc->lsrt = CFG_LBC_LSRT;
18091e25769SPaul Gortmaker 	asm("sync");
18191e25769SPaul Gortmaker 
18291e25769SPaul Gortmaker 	/*
18391e25769SPaul Gortmaker 	 * Configure the SDRAM controller Machine Mode Register.
18491e25769SPaul Gortmaker 	 */
18591e25769SPaul Gortmaker 	lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation */
18691e25769SPaul Gortmaker 
18791e25769SPaul Gortmaker 	lbc->lsdmr = CFG_LBC_LSDMR_1; /* 0x68636733; precharge all the banks */
18891e25769SPaul Gortmaker 	asm("sync");
18991e25769SPaul Gortmaker 	*sdram_addr = 0xff;
19091e25769SPaul Gortmaker 	udelay(100);
19191e25769SPaul Gortmaker 
19291e25769SPaul Gortmaker 	lbc->lsdmr = CFG_LBC_LSDMR_2; /* 0x48636733; auto refresh */
19391e25769SPaul Gortmaker 	asm("sync");
19491e25769SPaul Gortmaker 	/*1 times*/
19591e25769SPaul Gortmaker 	*sdram_addr = 0xff;
19691e25769SPaul Gortmaker 	udelay(100);
19791e25769SPaul Gortmaker 	/*2 times*/
19891e25769SPaul Gortmaker 	*sdram_addr = 0xff;
19991e25769SPaul Gortmaker 	udelay(100);
20091e25769SPaul Gortmaker 	/*3 times*/
20191e25769SPaul Gortmaker 	*sdram_addr = 0xff;
20291e25769SPaul Gortmaker 	udelay(100);
20391e25769SPaul Gortmaker 	/*4 times*/
20491e25769SPaul Gortmaker 	*sdram_addr = 0xff;
20591e25769SPaul Gortmaker 	udelay(100);
20691e25769SPaul Gortmaker 	/*5 times*/
20791e25769SPaul Gortmaker 	*sdram_addr = 0xff;
20891e25769SPaul Gortmaker 	udelay(100);
20991e25769SPaul Gortmaker 	/*6 times*/
21091e25769SPaul Gortmaker 	*sdram_addr = 0xff;
21191e25769SPaul Gortmaker 	udelay(100);
21291e25769SPaul Gortmaker 	/*7 times*/
21391e25769SPaul Gortmaker 	*sdram_addr = 0xff;
21491e25769SPaul Gortmaker 	udelay(100);
21591e25769SPaul Gortmaker 	/*8 times*/
21691e25769SPaul Gortmaker 	*sdram_addr = 0xff;
21791e25769SPaul Gortmaker 	udelay(100);
21891e25769SPaul Gortmaker 
21991e25769SPaul Gortmaker 	/* 0x58636733; mode register write operation */
22091e25769SPaul Gortmaker 	lbc->lsdmr = CFG_LBC_LSDMR_4;
22191e25769SPaul Gortmaker 	asm("sync");
22291e25769SPaul Gortmaker 	*sdram_addr = 0xff;
22391e25769SPaul Gortmaker 	udelay(100);
22491e25769SPaul Gortmaker 
22591e25769SPaul Gortmaker 	lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation */
22691e25769SPaul Gortmaker 	asm("sync");
22791e25769SPaul Gortmaker 	*sdram_addr = 0xff;
22891e25769SPaul Gortmaker 	udelay(100);
22991e25769SPaul Gortmaker }
23091e25769SPaul Gortmaker #else
23191e25769SPaul Gortmaker void sdram_init(void)
23291e25769SPaul Gortmaker {
23391e25769SPaul Gortmaker 	puts("   SDRAM on Local Bus: Disabled in config\n");
23491e25769SPaul Gortmaker }
23591e25769SPaul Gortmaker #endif
23691e25769SPaul Gortmaker 
2372408b3f2SPaul Gortmaker #if defined(CONFIG_OF_BOARD_SETUP)
2382408b3f2SPaul Gortmaker void ft_board_setup(void *blob, bd_t *bd)
23991e25769SPaul Gortmaker {
2402408b3f2SPaul Gortmaker 	ft_cpu_setup(blob, bd);
2412408b3f2SPaul Gortmaker #ifdef CONFIG_PCI
2422408b3f2SPaul Gortmaker 	ft_pci_setup(blob, bd);
2432408b3f2SPaul Gortmaker #endif
24491e25769SPaul Gortmaker }
24591e25769SPaul Gortmaker #endif
246