From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sean Anderson Date: Tue, 29 Sep 2020 10:18:33 -0400 Subject: [PATCH 08/10] riscv: Probe ram in dram_init In-Reply-To: <20200929141835.38435-1-seanga2@gmail.com> References: <20200929141835.38435-1-seanga2@gmail.com> Message-ID: <20200929141835.38435-9-seanga2@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de If CONFIG_RAM is enabled, use the ram device to get the base/size of memory. This provides an easy way for boards/cpus to hook into the dram_init logic, without needing to provide a second SYS_CPU. Signed-off-by: Sean Anderson --- arch/riscv/cpu/generic/dram.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/arch/riscv/cpu/generic/dram.c b/arch/riscv/cpu/generic/dram.c index 1dc77efeca..fbcd4ddf5f 100644 --- a/arch/riscv/cpu/generic/dram.c +++ b/arch/riscv/cpu/generic/dram.c @@ -4,15 +4,41 @@ */ #include +#include #include #include +#include +#include #include DECLARE_GLOBAL_DATA_PTR; int dram_init(void) { +#if CONFIG_IS_ENABLED(RAM) + int ret; + struct ram_info info; + struct udevice *dev; + + ret = uclass_get_device(UCLASS_RAM, 0, &dev); + if (ret) { + debug("DRAM init failed: %d\n", ret); + return ret; + } + + ret = ram_get_info(dev, &info); + if (ret) { + debug("Cannot get DRAM size: %d\n", ret); + return ret; + } + + gd->ram_base = info.base; + gd->ram_size = info.size; + + return 0; +#else return fdtdec_setup_mem_size_base(); +#endif } int dram_init_banksize(void) -- 2.28.0