2006-02-21 23:43:16 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2003-2006
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
|
|
|
* (C) Copyright 2004
|
|
|
|
* Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2006-02-21 23:43:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <mpc5xxx.h>
|
|
|
|
#include <pci.h>
|
2006-11-06 16:06:36 +00:00
|
|
|
#include <asm/processor.h>
|
2006-02-21 23:43:16 +00:00
|
|
|
|
2006-06-14 14:48:18 +00:00
|
|
|
/* Two MT48LC8M32B2 for 32 MB */
|
|
|
|
/* #include "mt48lc8m32b2-6-7.h" */
|
|
|
|
|
|
|
|
/* One MT48LC16M32S2 for 64 MB */
|
2006-07-23 20:40:51 +00:00
|
|
|
/* #include "mt48lc16m32s2-75.h" */
|
|
|
|
#if defined (CONFIG_MCC200_SDRAM)
|
|
|
|
#include "mt48lc16m16a2-75.h"
|
|
|
|
#else
|
|
|
|
#include "mt46v16m16-75.h"
|
|
|
|
#endif
|
2006-02-21 23:43:16 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2006-02-28 14:33:28 +00:00
|
|
|
extern flash_info_t flash_info[]; /* FLASH chips info */
|
|
|
|
|
2006-12-08 15:23:08 +00:00
|
|
|
extern int do_auto_update(void);
|
2006-03-01 16:00:49 +00:00
|
|
|
ulong flash_get_size (ulong base, int banknum);
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifndef CONFIG_SYS_RAMBOOT
|
2006-02-21 23:43:16 +00:00
|
|
|
static void sdram_start (int hi_addr)
|
|
|
|
{
|
|
|
|
long hi_addr_bit = hi_addr ? 0x01000000 : 0;
|
|
|
|
|
|
|
|
/* unlock mode register */
|
|
|
|
*(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
|
|
|
|
__asm__ volatile ("sync");
|
|
|
|
|
|
|
|
/* precharge all banks */
|
|
|
|
*(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
|
|
|
|
__asm__ volatile ("sync");
|
|
|
|
|
|
|
|
#if SDRAM_DDR
|
|
|
|
/* set mode register: extended mode */
|
|
|
|
*(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
|
|
|
|
__asm__ volatile ("sync");
|
|
|
|
|
|
|
|
/* set mode register: reset DLL */
|
|
|
|
*(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
|
|
|
|
__asm__ volatile ("sync");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* precharge all banks */
|
|
|
|
*(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
|
|
|
|
__asm__ volatile ("sync");
|
|
|
|
|
|
|
|
/* auto refresh */
|
|
|
|
*(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
|
|
|
|
__asm__ volatile ("sync");
|
|
|
|
|
|
|
|
/* set mode register */
|
|
|
|
*(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
|
|
|
|
__asm__ volatile ("sync");
|
|
|
|
|
|
|
|
/* normal operation */
|
|
|
|
*(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
|
|
|
|
__asm__ volatile ("sync");
|
2006-06-14 14:48:18 +00:00
|
|
|
|
|
|
|
udelay(10);
|
2006-02-21 23:43:16 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ATTENTION: Although partially referenced initdram does NOT make real use
|
2008-10-16 13:01:15 +00:00
|
|
|
* use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
|
2007-01-15 12:41:04 +00:00
|
|
|
* is something else than 0x00000000.
|
2006-02-21 23:43:16 +00:00
|
|
|
*/
|
|
|
|
|
2008-06-09 21:03:40 +00:00
|
|
|
phys_size_t initdram (int board_type)
|
2006-02-21 23:43:16 +00:00
|
|
|
{
|
|
|
|
ulong dramsize = 0;
|
|
|
|
ulong dramsize2 = 0;
|
2006-11-06 16:06:36 +00:00
|
|
|
uint svr, pvr;
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifndef CONFIG_SYS_RAMBOOT
|
2006-02-21 23:43:16 +00:00
|
|
|
ulong test1, test2;
|
|
|
|
|
|
|
|
/* setup SDRAM chip selects */
|
|
|
|
*(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
|
|
|
|
*(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
|
|
|
|
__asm__ volatile ("sync");
|
|
|
|
|
|
|
|
/* setup config registers */
|
|
|
|
*(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
|
|
|
|
*(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
|
|
|
|
__asm__ volatile ("sync");
|
|
|
|
|
|
|
|
#if SDRAM_DDR
|
|
|
|
/* set tap delay */
|
|
|
|
*(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
|
|
|
|
__asm__ volatile ("sync");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* find RAM size using SDRAM CS0 only */
|
|
|
|
sdram_start(0);
|
2008-10-16 13:01:15 +00:00
|
|
|
test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
|
2006-02-21 23:43:16 +00:00
|
|
|
sdram_start(1);
|
2008-10-16 13:01:15 +00:00
|
|
|
test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
|
2006-02-21 23:43:16 +00:00
|
|
|
if (test1 > test2) {
|
|
|
|
sdram_start(0);
|
|
|
|
dramsize = test1;
|
|
|
|
} else {
|
|
|
|
dramsize = test2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* memory smaller than 1MB is impossible */
|
|
|
|
if (dramsize < (1 << 20)) {
|
|
|
|
dramsize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set SDRAM CS0 size according to the amount of RAM found */
|
|
|
|
if (dramsize > 0) {
|
|
|
|
*(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
|
|
|
|
} else {
|
|
|
|
*(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* let SDRAM CS1 start right after CS0 */
|
|
|
|
*(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
|
|
|
|
|
|
|
|
/* find RAM size using SDRAM CS1 only */
|
|
|
|
if (!dramsize)
|
|
|
|
sdram_start(0);
|
2008-10-16 13:01:15 +00:00
|
|
|
test2 = test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
|
2006-02-21 23:43:16 +00:00
|
|
|
if (!dramsize) {
|
|
|
|
sdram_start(1);
|
2008-10-16 13:01:15 +00:00
|
|
|
test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
|
2006-02-21 23:43:16 +00:00
|
|
|
}
|
|
|
|
if (test1 > test2) {
|
|
|
|
sdram_start(0);
|
|
|
|
dramsize2 = test1;
|
|
|
|
} else {
|
|
|
|
dramsize2 = test2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* memory smaller than 1MB is impossible */
|
|
|
|
if (dramsize2 < (1 << 20)) {
|
|
|
|
dramsize2 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set SDRAM CS1 size according to the amount of RAM found */
|
|
|
|
if (dramsize2 > 0) {
|
|
|
|
*(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
|
|
|
|
| (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
|
|
|
|
} else {
|
|
|
|
*(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
|
|
|
|
}
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#else /* CONFIG_SYS_RAMBOOT */
|
2006-02-21 23:43:16 +00:00
|
|
|
|
|
|
|
/* retrieve size of memory connected to SDRAM CS0 */
|
|
|
|
dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
|
|
|
|
if (dramsize >= 0x13) {
|
|
|
|
dramsize = (1 << (dramsize - 0x13)) << 20;
|
|
|
|
} else {
|
|
|
|
dramsize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* retrieve size of memory connected to SDRAM CS1 */
|
|
|
|
dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
|
|
|
|
if (dramsize2 >= 0x13) {
|
|
|
|
dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
|
|
|
|
} else {
|
|
|
|
dramsize2 = 0;
|
|
|
|
}
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#endif /* CONFIG_SYS_RAMBOOT */
|
2006-02-21 23:43:16 +00:00
|
|
|
|
2006-11-06 16:06:36 +00:00
|
|
|
/*
|
|
|
|
* On MPC5200B we need to set the special configuration delay in the
|
|
|
|
* DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
|
|
|
|
* Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
|
|
|
|
*
|
|
|
|
* "The SDelay should be written to a value of 0x00000004. It is
|
|
|
|
* required to account for changes caused by normal wafer processing
|
|
|
|
* parameters."
|
|
|
|
*/
|
|
|
|
svr = get_svr();
|
|
|
|
pvr = get_pvr();
|
2006-11-27 14:32:42 +00:00
|
|
|
if ((SVR_MJREV(svr) >= 2) && (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
|
2006-11-06 16:06:36 +00:00
|
|
|
*(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04;
|
|
|
|
__asm__ volatile ("sync");
|
|
|
|
}
|
|
|
|
|
2006-02-21 23:43:16 +00:00
|
|
|
return dramsize + dramsize2;
|
|
|
|
}
|
|
|
|
|
|
|
|
int checkboard (void)
|
|
|
|
{
|
2006-08-23 22:26:42 +00:00
|
|
|
#if defined(CONFIG_PRS200)
|
|
|
|
puts ("Board: PRS200\n");
|
|
|
|
#else
|
2006-02-24 00:42:40 +00:00
|
|
|
puts ("Board: MCC200\n");
|
2006-08-23 22:26:42 +00:00
|
|
|
#endif
|
2006-02-21 23:43:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-28 14:33:28 +00:00
|
|
|
int misc_init_r (void)
|
2006-02-21 23:43:16 +00:00
|
|
|
{
|
2006-08-16 22:50:26 +00:00
|
|
|
ulong flash_sup_end, snum;
|
|
|
|
|
2006-02-21 23:43:16 +00:00
|
|
|
/*
|
2006-02-28 14:33:28 +00:00
|
|
|
* Adjust flash start and offset to detected values
|
2006-02-21 23:43:16 +00:00
|
|
|
*/
|
2006-02-28 14:33:28 +00:00
|
|
|
gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
|
|
|
|
gd->bd->bi_flashoffset = 0;
|
2006-02-21 23:43:16 +00:00
|
|
|
|
2006-02-28 14:33:28 +00:00
|
|
|
/*
|
|
|
|
* Check if boot FLASH isn't max size
|
|
|
|
*/
|
2008-10-16 13:01:15 +00:00
|
|
|
if (gd->bd->bi_flashsize < (0 - CONFIG_SYS_FLASH_BASE)) {
|
2006-02-28 14:33:28 +00:00
|
|
|
/* adjust mapping */
|
|
|
|
*(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
|
|
|
|
START_REG(gd->bd->bi_flashstart);
|
|
|
|
*(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
|
|
|
|
STOP_REG(gd->bd->bi_flashstart, gd->bd->bi_flashsize);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Re-check to get correct base address
|
|
|
|
*/
|
2008-10-16 13:01:15 +00:00
|
|
|
flash_get_size(gd->bd->bi_flashstart, CONFIG_SYS_MAX_FLASH_BANKS - 1);
|
2006-02-28 14:33:28 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Re-do flash protection upon new addresses
|
|
|
|
*/
|
|
|
|
flash_protect (FLAG_PROTECT_CLEAR,
|
|
|
|
gd->bd->bi_flashstart, 0xffffffff,
|
2008-10-16 13:01:15 +00:00
|
|
|
&flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
|
2006-02-28 14:33:28 +00:00
|
|
|
|
|
|
|
/* Monitor protection ON by default */
|
|
|
|
flash_protect (FLAG_PROTECT_SET,
|
2008-10-16 13:01:15 +00:00
|
|
|
CONFIG_SYS_MONITOR_BASE, CONFIG_SYS_MONITOR_BASE + monitor_flash_len - 1,
|
|
|
|
&flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
|
2006-02-28 14:33:28 +00:00
|
|
|
|
|
|
|
/* Environment protection ON by default */
|
|
|
|
flash_protect (FLAG_PROTECT_SET,
|
2008-09-10 20:48:06 +00:00
|
|
|
CONFIG_ENV_ADDR,
|
|
|
|
CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
|
2008-10-16 13:01:15 +00:00
|
|
|
&flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
|
2006-02-28 14:33:28 +00:00
|
|
|
|
|
|
|
/* Redundant environment protection ON by default */
|
|
|
|
flash_protect (FLAG_PROTECT_SET,
|
2008-09-10 20:48:06 +00:00
|
|
|
CONFIG_ENV_ADDR_REDUND,
|
Redundant Environment: protect full sector size
Several boards used different ways to specify the size of the
protected area when enabling flash write protection for the sectors
holding the environment variables: some used CONFIG_ENV_SIZE and
CONFIG_ENV_SIZE_REDUND, some used CONFIG_ENV_SECT_SIZE, and some even
a mix of both for the "normal" and the "redundant" areas.
Normally, this makes no difference at all. However, things are
different when you have to deal with boards that can come with
different types of flash chips, which may have different sector
sizes.
Here we may have to chose CONFIG_ENV_SECT_SIZE such that it fits the
biggest sector size, which may include several sectors on boards using
the smaller sector flash types. In such a case, using CONFIG_ENV_SIZE
or CONFIG_ENV_SIZE_REDUND to enable the protection may lead to the
case that only the first of these sectors get protected, while the
following ones aren't.
This is no real problem, but it can be confusing for the user -
especially on boards that use CONFIG_ENV_SECT_SIZE to protect the
"normal" areas, while using CONFIG_ENV_SIZE_REDUND for the
"redundant" area.
To avoid such inconsistencies, I changed all sucn boards that I found
to consistently use CONFIG_ENV_SECT_SIZE for protection. This should
not cause any functional changes to the code.
Signed-off-by: Wolfgang Denk <wd@denx.de>
Cc: Paul Ruhland
Cc: Pantelis Antoniou <panto@intracom.gr>
Cc: Stefan Roese <sr@denx.de>
Cc: Gary Jennejohn <garyj@denx.de>
Cc: Dave Ellis <DGE@sixnetio.com>
Acked-by: Stefan Roese <sr@denx.de>
2009-05-14 22:16:03 +00:00
|
|
|
CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
|
2008-10-16 13:01:15 +00:00
|
|
|
&flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
|
2006-02-28 14:33:28 +00:00
|
|
|
}
|
2006-02-21 23:43:16 +00:00
|
|
|
|
2006-04-06 13:03:42 +00:00
|
|
|
if (gd->bd->bi_flashsize > (32 << 20)) {
|
|
|
|
/* Unprotect the upper bank of the Flash */
|
|
|
|
*(volatile int*)MPC5XXX_CS0_CFG |= (1 << 6);
|
|
|
|
flash_protect (FLAG_PROTECT_CLEAR,
|
2006-06-09 19:19:21 +00:00
|
|
|
flash_info[0].start[0] + flash_info[0].size / 2,
|
2006-07-10 21:22:43 +00:00
|
|
|
(flash_info[0].start[0] - 1) + flash_info[0].size,
|
2006-04-06 13:03:42 +00:00
|
|
|
&flash_info[0]);
|
|
|
|
*(volatile int*)MPC5XXX_CS0_CFG &= ~(1 << 6);
|
2006-08-16 22:50:26 +00:00
|
|
|
printf ("Warning: Only 32 of 64 MB of Flash are accessible from U-Boot\n");
|
|
|
|
flash_info[0].size = 32 << 20;
|
2006-08-27 16:10:01 +00:00
|
|
|
for (snum = 0, flash_sup_end = gd->bd->bi_flashstart + (32<<20);
|
|
|
|
flash_info[0].start[snum] < flash_sup_end;
|
2006-08-16 22:50:26 +00:00
|
|
|
snum++);
|
|
|
|
flash_info[0].sector_count = snum;
|
2006-04-06 13:03:42 +00:00
|
|
|
}
|
|
|
|
|
2007-01-10 00:28:39 +00:00
|
|
|
#ifdef CONFIG_AUTO_UPDATE
|
2007-01-15 12:41:04 +00:00
|
|
|
do_auto_update();
|
2007-01-10 00:28:39 +00:00
|
|
|
#endif
|
2006-02-21 23:43:16 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PCI
|
|
|
|
static struct pci_controller hose;
|
|
|
|
|
|
|
|
extern void pci_mpc5xxx_init(struct pci_controller *);
|
|
|
|
|
|
|
|
void pci_init_board(void)
|
|
|
|
{
|
|
|
|
pci_mpc5xxx_init(&hose);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-07-10 15:48:22 +00:00
|
|
|
#if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
|
2006-02-21 23:43:16 +00:00
|
|
|
|
|
|
|
void init_ide_reset (void)
|
|
|
|
{
|
|
|
|
debug ("init_ide_reset\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ide_set_reset (int idereset)
|
|
|
|
{
|
|
|
|
debug ("ide_reset(%d)\n", idereset);
|
|
|
|
|
|
|
|
}
|
2007-07-10 15:48:22 +00:00
|
|
|
#endif
|
2006-02-21 23:43:16 +00:00
|
|
|
|
2007-07-09 23:38:39 +00:00
|
|
|
#if defined(CONFIG_CMD_DOC)
|
2006-02-21 23:43:16 +00:00
|
|
|
void doc_init (void)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
doc_probe (CONFIG_SYS_DOC_BASE);
|
2006-02-21 23:43:16 +00:00
|
|
|
}
|
|
|
|
#endif
|