blob: c97b5b1940a5eafd6a787e642ad6352480eb951f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prafulla Wadaskarc0c7a112010-10-12 16:31:40 +05302/*
3 * (C) Copyright 2010
4 * Marvell Semiconductor <www.marvell.com>
5 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>,
6 * Contributor: Mahavir Jain <mjain@marvell.com>
Prafulla Wadaskarc0c7a112010-10-12 16:31:40 +05307 */
8
9#include <common.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <asm/global_data.h>
Lei Wen35b130c2011-10-18 19:50:48 +053012#include <asm/io.h>
Prafulla Wadaskarc0c7a112010-10-12 16:31:40 +053013#include <asm/arch/armada100.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
17/*
18 * ARMADA100 DRAM controller supports upto 8 banks
19 * for chip select 0 and 1
20 */
21
22/*
23 * DDR Memory Control Registers
24 * Refer Datasheet Appendix A.17
25 */
26struct armd1ddr_map_registers {
27 u32 cs; /* Memory Address Map Register -CS */
28 u32 pad[3];
29};
30
31struct armd1ddr_registers {
32 u8 pad[0x100 - 0x000];
33 struct armd1ddr_map_registers mmap[2];
34};
35
36/*
37 * armd1_sdram_base - reads SDRAM Base Address Register
38 */
39u32 armd1_sdram_base(int chip_sel)
40{
41 struct armd1ddr_registers *ddr_regs =
42 (struct armd1ddr_registers *)ARMD1_DRAM_BASE;
43 u32 result = 0;
44 u32 CS_valid = 0x01 & readl(&ddr_regs->mmap[chip_sel].cs);
45
46 if (!CS_valid)
47 return 0;
48
49 result = readl(&ddr_regs->mmap[chip_sel].cs) & 0xFF800000;
50 return result;
51}
52
53/*
54 * armd1_sdram_size - reads SDRAM size
55 */
56u32 armd1_sdram_size(int chip_sel)
57{
58 struct armd1ddr_registers *ddr_regs =
59 (struct armd1ddr_registers *)ARMD1_DRAM_BASE;
60 u32 result = 0;
61 u32 CS_valid = 0x01 & readl(&ddr_regs->mmap[chip_sel].cs);
62
63 if (!CS_valid)
64 return 0;
65
66 result = readl(&ddr_regs->mmap[chip_sel].cs);
67 result = (result >> 16) & 0xF;
68 if (result < 0x7) {
69 printf("Unknown DRAM Size\n");
70 return -1;
71 } else {
72 return ((0x8 << (result - 0x7)) * 1024 * 1024);
73 }
74}
75
Prafulla Wadaskarc0c7a112010-10-12 16:31:40 +053076int dram_init(void)
77{
78 int i;
79
80 gd->ram_size = 0;
81 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
82 gd->bd->bi_dram[i].start = armd1_sdram_base(i);
83 gd->bd->bi_dram[i].size = armd1_sdram_size(i);
84 /*
85 * It is assumed that all memory banks are consecutive
86 * and without gaps.
87 * If the gap is found, ram_size will be reported for
88 * consecutive memory only
89 */
90 if (gd->bd->bi_dram[i].start != gd->ram_size)
91 break;
92
93 gd->ram_size += gd->bd->bi_dram[i].size;
94
95 }
96
97 for (; i < CONFIG_NR_DRAM_BANKS; i++) {
98 /* If above loop terminated prematurely, we need to set
99 * remaining banks' start address & size as 0. Otherwise other
100 * u-boot functions and Linux kernel gets wrong values which
101 * could result in crash */
102 gd->bd->bi_dram[i].start = 0;
103 gd->bd->bi_dram[i].size = 0;
104 }
105 return 0;
106}
107
108/*
109 * If this function is not defined here,
110 * board.c alters dram bank zero configuration defined above.
111 */
Simon Glass2f949c32017-03-31 08:40:32 -0600112int dram_init_banksize(void)
Prafulla Wadaskarc0c7a112010-10-12 16:31:40 +0530113{
114 dram_init();
Simon Glass2f949c32017-03-31 08:40:32 -0600115
116 return 0;
Prafulla Wadaskarc0c7a112010-10-12 16:31:40 +0530117}