2009-06-20 09:01:53 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2009
|
|
|
|
* Marvell Semiconductor <www.marvell.com>
|
|
|
|
* Written-by: Prafulla Wadaskar <prafulla@marvell.com>
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
* MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2010-09-30 14:03:19 +00:00
|
|
|
#include <common.h>
|
2011-10-18 14:41:42 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/arch/cpu.h>
|
2009-06-20 09:01:53 +00:00
|
|
|
#include <asm/arch/kirkwood.h>
|
|
|
|
|
2010-09-30 14:03:19 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2012-07-20 02:34:24 +00:00
|
|
|
struct kw_sdram_bank {
|
|
|
|
u32 win_bar;
|
|
|
|
u32 win_sz;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct kw_sdram_addr_dec {
|
|
|
|
struct kw_sdram_bank sdram_bank[4];
|
|
|
|
};
|
|
|
|
|
2009-06-20 09:01:53 +00:00
|
|
|
/*
|
|
|
|
* kw_sdram_bar - reads SDRAM Base Address Register
|
|
|
|
*/
|
|
|
|
u32 kw_sdram_bar(enum memory_bank bank)
|
|
|
|
{
|
2012-07-20 02:34:24 +00:00
|
|
|
struct kw_sdram_addr_dec *base =
|
|
|
|
(struct kw_sdram_addr_dec *)KW_REGISTER(0x1500);
|
2009-06-20 09:01:53 +00:00
|
|
|
u32 result = 0;
|
2012-07-20 02:34:24 +00:00
|
|
|
u32 enable = 0x01 & readl(&base->sdram_bank[bank].win_sz);
|
2009-06-20 09:01:53 +00:00
|
|
|
|
|
|
|
if ((!enable) || (bank > BANK3))
|
|
|
|
return 0;
|
|
|
|
|
2012-07-20 02:34:24 +00:00
|
|
|
result = readl(&base->sdram_bank[bank].win_bar);
|
2009-06-20 09:01:53 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kw_sdram_bs - reads SDRAM Bank size
|
|
|
|
*/
|
|
|
|
u32 kw_sdram_bs(enum memory_bank bank)
|
|
|
|
{
|
2012-07-20 02:34:24 +00:00
|
|
|
struct kw_sdram_addr_dec *base =
|
|
|
|
(struct kw_sdram_addr_dec *)KW_REGISTER(0x1500);
|
2009-06-20 09:01:53 +00:00
|
|
|
u32 result = 0;
|
2012-07-20 02:34:24 +00:00
|
|
|
u32 enable = 0x01 & readl(&base->sdram_bank[bank].win_sz);
|
2009-06-20 09:01:53 +00:00
|
|
|
|
|
|
|
if ((!enable) || (bank > BANK3))
|
|
|
|
return 0;
|
2012-07-20 02:34:24 +00:00
|
|
|
result = 0xff000000 & readl(&base->sdram_bank[bank].win_sz);
|
2009-06-20 09:01:53 +00:00
|
|
|
result += 0x01000000;
|
|
|
|
return result;
|
|
|
|
}
|
2010-09-30 14:03:19 +00:00
|
|
|
|
|
|
|
#ifndef CONFIG_SYS_BOARD_DRAM_INIT
|
|
|
|
int dram_init(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
gd->ram_size = 0;
|
|
|
|
for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
|
|
|
|
gd->bd->bi_dram[i].start = kw_sdram_bar(i);
|
|
|
|
gd->bd->bi_dram[i].size = kw_sdram_bs(i);
|
|
|
|
/*
|
|
|
|
* It is assumed that all memory banks are consecutive
|
|
|
|
* and without gaps.
|
|
|
|
* If the gap is found, ram_size will be reported for
|
|
|
|
* consecutive memory only
|
|
|
|
*/
|
|
|
|
if (gd->bd->bi_dram[i].start != gd->ram_size)
|
|
|
|
break;
|
|
|
|
|
|
|
|
gd->ram_size += gd->bd->bi_dram[i].size;
|
|
|
|
|
|
|
|
}
|
2010-10-28 14:36:22 +00:00
|
|
|
|
|
|
|
for (; i < CONFIG_NR_DRAM_BANKS; i++) {
|
|
|
|
/* If above loop terminated prematurely, we need to set
|
|
|
|
* remaining banks' start address & size as 0. Otherwise other
|
|
|
|
* u-boot functions and Linux kernel gets wrong values which
|
|
|
|
* could result in crash */
|
|
|
|
gd->bd->bi_dram[i].start = 0;
|
|
|
|
gd->bd->bi_dram[i].size = 0;
|
|
|
|
}
|
|
|
|
|
2010-09-30 14:03:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this function is not defined here,
|
|
|
|
* board.c alters dram bank zero configuration defined above.
|
|
|
|
*/
|
|
|
|
void dram_init_banksize(void)
|
|
|
|
{
|
|
|
|
dram_init();
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_SYS_BOARD_DRAM_INIT */
|