Lei Wen | 4301303 | 2011-02-09 18:06:58 +0530 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2011 |
| 3 | * Marvell Semiconductor <www.marvell.com> |
| 4 | * Written-by: Lei Wen <leiwen@marvell.com>, |
| 5 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Lei Wen | 4301303 | 2011-02-09 18:06:58 +0530 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Lei Wen | 24f41da | 2011-10-18 19:21:33 +0530 | [diff] [blame] | 10 | #include <asm/io.h> |
Lei Wen | 4301303 | 2011-02-09 18:06:58 +0530 | [diff] [blame] | 11 | #include <asm/arch/pantheon.h> |
| 12 | |
| 13 | DECLARE_GLOBAL_DATA_PTR; |
| 14 | |
| 15 | /* |
| 16 | * Pantheon DRAM controller supports upto 8 banks |
| 17 | * for chip select 0 and 1 |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * DDR Memory Control Registers |
| 22 | * Refer Datasheet 4.4 |
| 23 | */ |
| 24 | struct panthddr_map_registers { |
| 25 | u32 cs; /* Memory Address Map Register -CS */ |
| 26 | u32 pad[3]; |
| 27 | }; |
| 28 | |
| 29 | struct panthddr_registers { |
| 30 | u8 pad[0x100 - 0x000]; |
| 31 | struct panthddr_map_registers mmap[2]; |
| 32 | }; |
| 33 | |
| 34 | /* |
| 35 | * panth_sdram_base - reads SDRAM Base Address Register |
| 36 | */ |
| 37 | u32 panth_sdram_base(int chip_sel) |
| 38 | { |
| 39 | struct panthddr_registers *ddr_regs = |
| 40 | (struct panthddr_registers *)PANTHEON_DRAM_BASE; |
| 41 | u32 result = 0; |
| 42 | u32 CS_valid = 0x01 & readl(&ddr_regs->mmap[chip_sel].cs); |
| 43 | |
| 44 | if (!CS_valid) |
| 45 | return 0; |
| 46 | |
| 47 | result = readl(&ddr_regs->mmap[chip_sel].cs) & 0xFF800000; |
| 48 | return result; |
| 49 | } |
| 50 | |
| 51 | /* |
| 52 | * panth_sdram_size - reads SDRAM size |
| 53 | */ |
| 54 | u32 panth_sdram_size(int chip_sel) |
| 55 | { |
| 56 | struct panthddr_registers *ddr_regs = |
| 57 | (struct panthddr_registers *)PANTHEON_DRAM_BASE; |
| 58 | u32 result = 0; |
| 59 | u32 CS_valid = 0x01 & readl(&ddr_regs->mmap[chip_sel].cs); |
| 60 | |
| 61 | if (!CS_valid) |
| 62 | return 0; |
| 63 | |
| 64 | result = readl(&ddr_regs->mmap[chip_sel].cs); |
| 65 | result = (result >> 16) & 0xF; |
| 66 | if (result < 0x7) { |
| 67 | printf("Unknown DRAM Size\n"); |
| 68 | return -1; |
| 69 | } else { |
| 70 | return ((0x8 << (result - 0x7)) * 1024 * 1024); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | #ifndef CONFIG_SYS_BOARD_DRAM_INIT |
| 75 | int dram_init(void) |
| 76 | { |
| 77 | int i; |
| 78 | |
| 79 | gd->ram_size = 0; |
| 80 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 81 | gd->bd->bi_dram[i].start = panth_sdram_base(i); |
| 82 | gd->bd->bi_dram[i].size = panth_sdram_size(i); |
| 83 | /* |
| 84 | * It is assumed that all memory banks are consecutive |
| 85 | * and without gaps. |
| 86 | * If the gap is found, ram_size will be reported for |
| 87 | * consecutive memory only |
| 88 | */ |
| 89 | if (gd->bd->bi_dram[i].start != gd->ram_size) |
| 90 | break; |
| 91 | |
| 92 | gd->ram_size += gd->bd->bi_dram[i].size; |
| 93 | |
| 94 | } |
| 95 | |
| 96 | for (; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 97 | /* |
| 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 | */ |
| 103 | gd->bd->bi_dram[i].start = 0; |
| 104 | gd->bd->bi_dram[i].size = 0; |
| 105 | } |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | /* |
| 110 | * If this function is not defined here, |
| 111 | * board.c alters dram bank zero configuration defined above. |
| 112 | */ |
| 113 | void dram_init_banksize(void) |
| 114 | { |
| 115 | dram_init(); |
| 116 | } |
| 117 | #endif /* CONFIG_SYS_BOARD_DRAM_INIT */ |