From 7208a44d8bc6058a120d49b7061e2b9f9c0502c8 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Wed, 1 Jul 2020 11:11:18 +0200 Subject: ARM: at91: sama5d2: read back memory size from DDRAM controller We hard code memory size at three places: - In the configuration we use to initialize the DDRAM controller - In the minimal available size passed from PBL to barebox proper - In the device tree memory node override Remove the two latter ones and replace them with code that reads the size back from controller. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- arch/arm/mach-at91/ddramc.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 arch/arm/mach-at91/ddramc.c (limited to 'arch/arm/mach-at91/ddramc.c') diff --git a/arch/arm/mach-at91/ddramc.c b/arch/arm/mach-at91/ddramc.c new file mode 100644 index 0000000000..6dac794689 --- /dev/null +++ b/arch/arm/mach-at91/ddramc.c @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2020 Ahmad Fatoum + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static unsigned sama5_ramsize(void __iomem *base) +{ + return at91_get_ddram_size(base, true); +} + +void __noreturn sama5d2_barebox_entry(void *boarddata) +{ + barebox_arm_entry(SAMA5_DDRCS, sama5_ramsize(SAMA5D2_BASE_MPDDRC), + boarddata); +} + +static int sama5_ddr_probe(struct device_d *dev) +{ + struct resource *iores; + void __iomem *base; + + iores = dev_request_mem_resource(dev, 0); + if (IS_ERR(iores)) + return PTR_ERR(iores); + base = IOMEM(iores->start); + + arm_add_mem_device("ram0", SAMA5_DDRCS, sama5_ramsize(base)); + + return 0; +} + +static struct of_device_id sama5_ddr_dt_ids[] = { + { .compatible = "atmel,sama5d3-ddramc" }, + { /* sentinel */ } +}; + +static struct driver_d sama5_ddr_driver = { + .name = "sama5-ddramc", + .probe = sama5_ddr_probe, + .of_compatible = sama5_ddr_dt_ids, +}; + +static int sama5_ddr_init(void) +{ + return platform_driver_register(&sama5_ddr_driver); +} +mem_initcall(sama5_ddr_init); -- cgit v1.2.3 From 5991cb8eeb8a4eea2587be3b1d1b45d845bd3c68 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Wed, 1 Jul 2020 11:11:19 +0200 Subject: ARM: at91: sama5d2: populate $bootsource and $bootsource_instance The BootROM passes us information about the boot medium in r4 and we already use that in first stage and pass it along to second stage PBL already. To make use of it, we need to pass it to barebox proper, do this by writing it in the last 4 bytes of the SRAM. As second stage always run in DRAM, this is safe to do. We could also write to SRAM directly from first stage, but at91bootstrap passes info in r4 as well for the sama5d3 boards, so we do it likewise to maintain compatibility. Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- arch/arm/boards/sama5d27-giantboard/lowlevel.c | 6 +++--- arch/arm/boards/sama5d27-som1/lowlevel.c | 2 +- arch/arm/mach-at91/ddramc.c | 4 +++- arch/arm/mach-at91/include/mach/ddramc.h | 3 +-- arch/arm/mach-at91/include/mach/sama5_bootsource.h | 3 +++ arch/arm/mach-at91/sama5d2.c | 17 +++++++++++++++++ 6 files changed, 28 insertions(+), 7 deletions(-) (limited to 'arch/arm/mach-at91/ddramc.c') diff --git a/arch/arm/boards/sama5d27-giantboard/lowlevel.c b/arch/arm/boards/sama5d27-giantboard/lowlevel.c index 0bb3a7289c..3dada9baf2 100644 --- a/arch/arm/boards/sama5d27-giantboard/lowlevel.c +++ b/arch/arm/boards/sama5d27-giantboard/lowlevel.c @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include @@ -25,7 +25,7 @@ static void dbgu_init(void) extern char __dtb_z_at91_sama5d27_giantboard_start[]; -ENTRY_FUNCTION(start_sama5d27_giantboard, r0, r1, r2) +SAMA5_ENTRY_FUNCTION(start_sama5d27_giantboard, r4) { void *fdt; @@ -36,5 +36,5 @@ ENTRY_FUNCTION(start_sama5d27_giantboard, r0, r1, r2) fdt = __dtb_z_at91_sama5d27_giantboard_start + get_runtime_offset(); - sama5d2_barebox_entry(fdt); + sama5d2_barebox_entry(r4, fdt); } diff --git a/arch/arm/boards/sama5d27-som1/lowlevel.c b/arch/arm/boards/sama5d27-som1/lowlevel.c index 792e065076..b093711918 100644 --- a/arch/arm/boards/sama5d27-som1/lowlevel.c +++ b/arch/arm/boards/sama5d27-som1/lowlevel.c @@ -69,5 +69,5 @@ SAMA5_ENTRY_FUNCTION(start_sama5d27_som1_ek, r4) fdt = __dtb_z_at91_sama5d27_som1_ek_start + get_runtime_offset(); ek_turn_led(RGB_LED_GREEN); - sama5d2_barebox_entry(fdt); + sama5d2_barebox_entry(r4, fdt); } diff --git a/arch/arm/mach-at91/ddramc.c b/arch/arm/mach-at91/ddramc.c index 6dac794689..a241ea9f0a 100644 --- a/arch/arm/mach-at91/ddramc.c +++ b/arch/arm/mach-at91/ddramc.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -18,8 +19,9 @@ static unsigned sama5_ramsize(void __iomem *base) return at91_get_ddram_size(base, true); } -void __noreturn sama5d2_barebox_entry(void *boarddata) +void __noreturn sama5d2_barebox_entry(unsigned int r4, void *boarddata) { + __sama5d2_stashed_bootrom_r4 = r4; barebox_arm_entry(SAMA5_DDRCS, sama5_ramsize(SAMA5D2_BASE_MPDDRC), boarddata); } diff --git a/arch/arm/mach-at91/include/mach/ddramc.h b/arch/arm/mach-at91/include/mach/ddramc.h index cd85bb6eab..b929bf5f58 100644 --- a/arch/arm/mach-at91/include/mach/ddramc.h +++ b/arch/arm/mach-at91/include/mach/ddramc.h @@ -32,7 +32,6 @@ void at91_lpddr1_sdram_initialize(void __iomem *base_address, void __iomem *ram_address, struct at91_ddramc_register *ddramc_config); -void __noreturn sama5d2_barebox_entry(void *boarddata); - +void __noreturn sama5d2_barebox_entry(unsigned int r4, void *boarddata); #endif /* #ifndef __DDRAMC_H__ */ diff --git a/arch/arm/mach-at91/include/mach/sama5_bootsource.h b/arch/arm/mach-at91/include/mach/sama5_bootsource.h index 29354dcaf3..0f90afe902 100644 --- a/arch/arm/mach-at91/include/mach/sama5_bootsource.h +++ b/arch/arm/mach-at91/include/mach/sama5_bootsource.h @@ -43,4 +43,7 @@ static inline int sama5_bootsource_instance(u32 reg) return FIELD_GET(SAMA5_BOOTSOURCE_INSTANCE, reg); } +#define __sama5d2_stashed_bootrom_r4 \ + (*(volatile u32 *)(SAMA5D2_SRAM_BASE + SAMA5D2_SRAM_SIZE - 0x4)) + #endif diff --git a/arch/arm/mach-at91/sama5d2.c b/arch/arm/mach-at91/sama5d2.c index c498b09645..2ce6d7f36f 100644 --- a/arch/arm/mach-at91/sama5d2.c +++ b/arch/arm/mach-at91/sama5d2.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #define SFR_CAN 0x48 @@ -52,3 +53,19 @@ static int sama5d2_init(void) return 0; } postmmu_initcall(sama5d2_init); + +static int sama5d2_bootsource_init(void) +{ + u32 r4; + + if (!of_machine_is_compatible("atmel,sama5d2")) + return 0; + + r4 = __sama5d2_stashed_bootrom_r4; + + bootsource_set(sama5_bootsource(r4)); + bootsource_set_instance(sama5_bootsource_instance(r4)); + + return 0; +} +postcore_initcall(sama5d2_bootsource_init); -- cgit v1.2.3