]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/arm926ejs/pantheon/dram.c
mxc_ipuv3: fix memory alignment of framebuffer
[karo-tx-uboot.git] / arch / arm / cpu / arm926ejs / pantheon / dram.c
1 /*
2  * (C) Copyright 2011
3  * Marvell Semiconductor <www.marvell.com>
4  * Written-by: Lei Wen <leiwen@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 <common.h>
26 #include <asm/io.h>
27 #include <asm/arch/pantheon.h>
28
29 DECLARE_GLOBAL_DATA_PTR;
30
31 /*
32  * Pantheon DRAM controller supports upto 8 banks
33  * for chip select 0 and 1
34  */
35
36 /*
37  * DDR Memory Control Registers
38  * Refer Datasheet 4.4
39  */
40 struct panthddr_map_registers {
41         u32     cs;     /* Memory Address Map Register -CS */
42         u32     pad[3];
43 };
44
45 struct panthddr_registers {
46         u8      pad[0x100 - 0x000];
47         struct panthddr_map_registers mmap[2];
48 };
49
50 /*
51  * panth_sdram_base - reads SDRAM Base Address Register
52  */
53 u32 panth_sdram_base(int chip_sel)
54 {
55         struct panthddr_registers *ddr_regs =
56                 (struct panthddr_registers *)PANTHEON_DRAM_BASE;
57         u32 result = 0;
58         u32 CS_valid = 0x01 & readl(&ddr_regs->mmap[chip_sel].cs);
59
60         if (!CS_valid)
61                 return 0;
62
63         result = readl(&ddr_regs->mmap[chip_sel].cs) & 0xFF800000;
64         return result;
65 }
66
67 /*
68  * panth_sdram_size - reads SDRAM size
69  */
70 u32 panth_sdram_size(int chip_sel)
71 {
72         struct panthddr_registers *ddr_regs =
73                 (struct panthddr_registers *)PANTHEON_DRAM_BASE;
74         u32 result = 0;
75         u32 CS_valid = 0x01 & readl(&ddr_regs->mmap[chip_sel].cs);
76
77         if (!CS_valid)
78                 return 0;
79
80         result = readl(&ddr_regs->mmap[chip_sel].cs);
81         result = (result >> 16) & 0xF;
82         if (result < 0x7) {
83                 printf("Unknown DRAM Size\n");
84                 return -1;
85         } else {
86                 return ((0x8 << (result - 0x7)) * 1024 * 1024);
87         }
88 }
89
90 #ifndef CONFIG_SYS_BOARD_DRAM_INIT
91 int dram_init(void)
92 {
93         int i;
94
95         gd->ram_size = 0;
96         for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
97                 gd->bd->bi_dram[i].start = panth_sdram_base(i);
98                 gd->bd->bi_dram[i].size = panth_sdram_size(i);
99                 /*
100                  * It is assumed that all memory banks are consecutive
101                  * and without gaps.
102                  * If the gap is found, ram_size will be reported for
103                  * consecutive memory only
104                  */
105                 if (gd->bd->bi_dram[i].start != gd->ram_size)
106                         break;
107
108                 gd->ram_size += gd->bd->bi_dram[i].size;
109
110         }
111
112         for (; i < CONFIG_NR_DRAM_BANKS; i++) {
113                 /*
114                  * If above loop terminated prematurely, we need to set
115                  * remaining banks' start address & size as 0. Otherwise other
116                  * u-boot functions and Linux kernel gets wrong values which
117                  * could result in crash
118                  */
119                 gd->bd->bi_dram[i].start = 0;
120                 gd->bd->bi_dram[i].size = 0;
121         }
122         return 0;
123 }
124
125 /*
126  * If this function is not defined here,
127  * board.c alters dram bank zero configuration defined above.
128  */
129 void dram_init_banksize(void)
130 {
131         dram_init();
132 }
133 #endif /* CONFIG_SYS_BOARD_DRAM_INIT */