blob: 1c5faabb4555e6a53a1826d90e706e403052a3ae [file] [log] [blame]
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +02001/*
2 * (C) Copyright 2009
3 * Marvell Semiconductor <www.marvell.com>
4 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 * MA 02110-1301 USA
23 */
24
25#include <config.h>
Prafulla Wadaskarbeeb2582010-09-30 19:33:19 +053026#include <common.h>
Lei Wena7efd712011-10-18 20:11:42 +053027#include <asm/io.h>
28#include <asm/arch/cpu.h>
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020029#include <asm/arch/kirkwood.h>
30
Prafulla Wadaskarbeeb2582010-09-30 19:33:19 +053031DECLARE_GLOBAL_DATA_PTR;
32
Holger Brunckcf37c5d2012-07-20 02:34:24 +000033struct kw_sdram_bank {
34 u32 win_bar;
35 u32 win_sz;
36};
37
38struct kw_sdram_addr_dec {
39 struct kw_sdram_bank sdram_bank[4];
40};
41
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020042/*
43 * kw_sdram_bar - reads SDRAM Base Address Register
44 */
45u32 kw_sdram_bar(enum memory_bank bank)
46{
Holger Brunckcf37c5d2012-07-20 02:34:24 +000047 struct kw_sdram_addr_dec *base =
48 (struct kw_sdram_addr_dec *)KW_REGISTER(0x1500);
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020049 u32 result = 0;
Holger Brunckcf37c5d2012-07-20 02:34:24 +000050 u32 enable = 0x01 & readl(&base->sdram_bank[bank].win_sz);
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020051
52 if ((!enable) || (bank > BANK3))
53 return 0;
54
Holger Brunckcf37c5d2012-07-20 02:34:24 +000055 result = readl(&base->sdram_bank[bank].win_bar);
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020056 return result;
57}
58
59/*
60 * kw_sdram_bs - reads SDRAM Bank size
61 */
62u32 kw_sdram_bs(enum memory_bank bank)
63{
Holger Brunckcf37c5d2012-07-20 02:34:24 +000064 struct kw_sdram_addr_dec *base =
65 (struct kw_sdram_addr_dec *)KW_REGISTER(0x1500);
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020066 u32 result = 0;
Holger Brunckcf37c5d2012-07-20 02:34:24 +000067 u32 enable = 0x01 & readl(&base->sdram_bank[bank].win_sz);
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020068
69 if ((!enable) || (bank > BANK3))
70 return 0;
Holger Brunckcf37c5d2012-07-20 02:34:24 +000071 result = 0xff000000 & readl(&base->sdram_bank[bank].win_sz);
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020072 result += 0x01000000;
73 return result;
74}
Prafulla Wadaskarbeeb2582010-09-30 19:33:19 +053075
76#ifndef CONFIG_SYS_BOARD_DRAM_INIT
77int dram_init(void)
78{
79 int i;
80
81 gd->ram_size = 0;
82 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
83 gd->bd->bi_dram[i].start = kw_sdram_bar(i);
84 gd->bd->bi_dram[i].size = kw_sdram_bs(i);
85 /*
86 * It is assumed that all memory banks are consecutive
87 * and without gaps.
88 * If the gap is found, ram_size will be reported for
89 * consecutive memory only
90 */
91 if (gd->bd->bi_dram[i].start != gd->ram_size)
92 break;
93
94 gd->ram_size += gd->bd->bi_dram[i].size;
95
96 }
Tanmay Upadhyay28e57102010-10-28 20:06:22 +053097
98 for (; i < CONFIG_NR_DRAM_BANKS; i++) {
99 /* If above loop terminated prematurely, we need to set
100 * remaining banks' start address & size as 0. Otherwise other
101 * u-boot functions and Linux kernel gets wrong values which
102 * could result in crash */
103 gd->bd->bi_dram[i].start = 0;
104 gd->bd->bi_dram[i].size = 0;
105 }
106
Prafulla Wadaskarbeeb2582010-09-30 19:33:19 +0530107 return 0;
108}
109
110/*
111 * If this function is not defined here,
112 * board.c alters dram bank zero configuration defined above.
113 */
114void dram_init_banksize(void)
115{
116 dram_init();
117}
118#endif /* CONFIG_SYS_BOARD_DRAM_INIT */