Skip to contentSkip to conversation

ddr: altera: arria10: Convert SDRAM driver to DM

PATCH New Ley Foon Tan 4 participants 11 messages Apr 20, 2020 – Apr 30, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover ddr: altera: arria10: Convert SDRAM driver to DM

This patchset mainly to covert Arria 10 SDRAM driver to device model and fixes few bugs in driver. It also added RAM size check function to check valid RAM.

v1->v2:
- Update Patch[1] commit description
- Change debug() to printf() if failed to probe SDRAM driver in SPL. [Patch 2]
- Change to use MACRO(n) to calculate register address. [Patch 2]
- Call to reset_assert_bulk() if failed in _probe(). [Patch 3]
- Change SZ_1G to full SDRAM size in get_ram_size() argument. [Patch 5]
- Patch 4, 6 and 7 unchanged.

Ley Foon Tan (7):
ddr: altera: arria10: Fix incorrect address for mpu1
ddr: altera: arria10: Move SDRAM driver to DM
ddr: altera: arria10: Change to use reset DM function
arm: socfpga: arria10: Move sdram_arria10.h to drivers/ddr/altera
ddr: altera: arria10: Add RAM size check
ddr: altera: arria10: Change %i to %u for printf
ddr: altera: arria10: Remove call to dram_init_banksize()

 arch/arm/dts/socfpga_arria10-u-boot.dtsi      |   8 +
 .../include/mach/reset_manager_arria10.h      |   1 -
 arch/arm/mach-socfpga/include/mach/sdram.h    |   2 +-
 arch/arm/mach-socfpga/misc_arria10.c          |   2 +-
 arch/arm/mach-socfpga/reset_manager_arria10.c |   7 -
 arch/arm/mach-socfpga/spl_a10.c               |  14 +-
 drivers/ddr/altera/Kconfig                    |   4 +-
 drivers/ddr/altera/sdram_arria10.c            | 382 ++++++++++--------
 .../ddr/altera}/sdram_arria10.h               | 225 ++---------
 9 files changed, 285 insertions(+), 360 deletions(-)
 rename {arch/arm/mach-socfpga/include/mach => drivers/ddr/altera}/sdram_arria10.h (72%)
Signature · 1 line
2.19.0
#1 lore raw

PATCH v2 1/7 ddr: altera: arria10: Fix incorrect address for mpu1

SOCFPGA_SDR_FIREWALL_MPU_FPGA_ADDRESS is added in SOCFPGA_SDR_FIREWALL_MPU_FPGA_ADDRESS_OFFSET() macro already. Remove extra SOCFPGA_SDR_FIREWALL_MPU_FPGA_ADDRESS in mpu1 address computation.

---
v2:
- Update commit description

---
 drivers/ddr/altera/sdram_arria10.c | 1 -
 1 file changed, 1 deletion(-)
drivers/ddr/altera/sdram_arria10.c +0 -1
index 2fd50b7ae550..e0779b810fdc 100644
@@ -470,7 +470,6 @@ const struct firewall_entry firewall_table[] = {
 	},
 	{
 		"mpu1",
-		SOCFPGA_SDR_FIREWALL_MPU_FPGA_ADDRESS +
 		SOCFPGA_SDR_FIREWALL_MPU_FPGA_ADDRESS_OFFSET(mpuregion1addr),
 		SOCFPGA_SDR_FIREWALL_MPU_FPGA_ADDRESS_OFFSET(enable),
 		ALT_NOC_FW_DDR_SCR_EN_MPUREG1EN_SET_MSK
Signature · 1 line
2.19.0
#2 lore raw

PATCH v2 2/7 ddr: altera: arria10: Move SDRAM driver to DM

In reply to Ley Foon Tan

Convert Arria 10 SDRAM driver to device model.

SPL is changed from calling function in SDRAM driver directly to just probing UCLASS_RAM.

---
v2:
- Change debug() to printf() if failed to probe SDRAM driver in SPL.
- Change to use MACRO(n) to calculate register address.

---
 arch/arm/dts/socfpga_arria10-u-boot.dtsi      |   8 +
 .../mach-socfpga/include/mach/sdram_arria10.h | 225 +++---------
 arch/arm/mach-socfpga/spl_a10.c               |  14 +-
 drivers/ddr/altera/Kconfig                    |   4 +-
 drivers/ddr/altera/sdram_arria10.c            | 334 ++++++++++--------
 5 files changed, 251 insertions(+), 334 deletions(-)
arch/arm/dts/socfpga_arria10-u-boot.dtsi +8 -0
index 6ff1ea6e5eb7..cb576f5288ea 100644
@@ -133,6 +133,14 @@
 	u-boot,dm-pre-reloc;
 };
 
+&sdr {
+	reg = <0xffcfa000 0x11C>,
+	      <0xffcfb000 0x180>,
+	      <0xffd12400 0x1030>;
+	resets = <&rst DDRSCH_RESET>;
+	u-boot,dm-pre-reloc;
+};
+
 &sysmgr {
 	u-boot,dm-pre-reloc;
 };
arch/arm/mach-socfpga/include/mach/sdram_arria10.h +40 -185

237 lines not on this page · raw message

arch/arm/mach-socfpga/spl_a10.c +12 -2
index b10be3326803..273a89876ecb 100644
@@ -28,6 +28,7 @@
 #include <asm/arch/fpga_manager.h>
 #include <mmc.h>
 #include <memalign.h>
+#include <dm/uclass.h>
 
 #define FPGA_BUFSIZ	16 * 1024
 
@@ -104,6 +105,8 @@ u32 spl_boot_mode(const u32 boot_device)
 
 void spl_board_init(void)
 {
+	int ret;
+	struct udevice *dev;
 	ALLOC_CACHE_ALIGN_BUFFER(char, buf, FPGA_BUFSIZ);
 
 	/* enable console uart printing */
@@ -127,9 +130,16 @@ void spl_board_init(void)
 		fpgamgr_program(buf, FPGA_BUFSIZ, 0);
 	}
 
+#if CONFIG_IS_ENABLED(ALTERA_SDRAM)
 	/* If the IOSSM/full FPGA is already loaded, start DDR */
-	if (is_fpgamgr_early_user_mode() || is_fpgamgr_user_mode())
-		ddr_calibration_sequence();
+	if (is_fpgamgr_early_user_mode() || is_fpgamgr_user_mode()) {
+		ret = uclass_get_device(UCLASS_RAM, 0, &dev);
+		if (ret) {
+			printf("DRAM init failed: %d\n", ret);
+			hang();
+		}
+	}
+#endif
 
 	if (!is_fpgamgr_user_mode())
 		fpgamgr_program(buf, FPGA_BUFSIZ, 0);
drivers/ddr/altera/Kconfig +2 -2
index 8f590dc5f611..30ee884dcf47 100644
@@ -2,7 +2,7 @@ config SPL_ALTERA_SDRAM
 	bool "SoCFPGA DDR SDRAM driver in SPL"
 	depends on SPL
 	depends on TARGET_SOCFPGA_GEN5 || TARGET_SOCFPGA_ARRIA10 || TARGET_SOCFPGA_STRATIX10 || TARGET_SOCFPGA_AGILEX
-	select RAM if TARGET_SOCFPGA_GEN5 || TARGET_SOCFPGA_STRATIX10 || TARGET_SOCFPGA_AGILEX
-	select SPL_RAM if TARGET_SOCFPGA_GEN5 || TARGET_SOCFPGA_STRATIX10 || TARGET_SOCFPGA_AGILEX
+	select RAM
+	select SPL_RAM
 	help
 	  Enable DDR SDRAM controller for the SoCFPGA devices.
drivers/ddr/altera/sdram_arria10.c +189 -145

621 lines not on this page · raw message

Signature · 1 line
2.19.0
#3 lore raw

PATCH v2 3/7 ddr: altera: arria10: Change to use reset DM function

In reply to Ley Foon Tan

Change to use reset DM function and remove unused
socfpga_reset_deassert_noc_ddr_scheduler().

---
v2:
- Call to reset_assert_bulk() if failed in _probe().

---
 .../include/mach/reset_manager_arria10.h      |  1 -
 arch/arm/mach-socfpga/reset_manager_arria10.c |  7 -----
 drivers/ddr/altera/sdram_arria10.c            | 26 ++++++++++---------
 3 files changed, 14 insertions(+), 20 deletions(-)
arch/arm/mach-socfpga/include/mach/reset_manager_arria10.h +0 -1
index 22e4eb33de88..a0fad7c1e2fc 100644
@@ -9,7 +9,6 @@
 #include <dt-bindings/reset/altr,rst-mgr-a10.h>
 
 void socfpga_watchdog_disable(void);
-void socfpga_reset_deassert_noc_ddr_scheduler(void);
 int socfpga_reset_deassert_bridges_handoff(void);
 void socfpga_reset_deassert_osc1wd0(void);
 int socfpga_bridges_reset(void);
arch/arm/mach-socfpga/reset_manager_arria10.c +0 -7
index aa5299415a74..edfe250ec0bc 100644
@@ -62,13 +62,6 @@ void socfpga_watchdog_disable(void)
 		     ALT_RSTMGR_PER1MODRST_WD0_SET_MSK);
 }
 
-/* Release NOC ddr scheduler from reset */
-void socfpga_reset_deassert_noc_ddr_scheduler(void)
-{
-	clrbits_le32(socfpga_get_rstmgr_addr() + RSTMGR_A10_BRGMODRST,
-		     ALT_RSTMGR_BRGMODRST_DDRSCH_SET_MSK);
-}
-
 static int get_bridge_init_val(const void *blob, int compat_id)
 {
 	int node;
drivers/ddr/altera/sdram_arria10.c +14 -12
index 5d092f1f3b73..3374efaae801 100644
@@ -10,19 +10,21 @@
 #include <fdtdec.h>
 #include <malloc.h>
 #include <ram.h>
+#include <reset.h>
 #include <wait_bit.h>
 #include <watchdog.h>
 #include <asm/io.h>
 #include <asm/arch/fpga_manager.h>
 #include <asm/arch/misc.h>
-#include <asm/arch/reset_manager.h>
 #include <asm/arch/sdram.h>
+#include <dm/device_compat.h>
 #include <linux/kernel.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
 struct altera_sdram_priv {
 	struct ram_info info;
+	struct reset_ctl_bulk resets;
 };
 
 struct altera_sdram_platdata {
@@ -152,7 +154,7 @@ static int emif_reset(struct altera_sdram_platdata *plat)
 	return 0;
 }
 
-static int ddr_setup(struct altera_sdram_platdata *plat)
+static int sdram_startup(struct altera_sdram_platdata *plat)
 {
 	int i, ret;
 
@@ -198,16 +200,6 @@ static void sdram_init_ecc_bits(u32 size)
 	dcache_disable();
 }
 
-/* Function to startup the SDRAM*/
-static int sdram_startup(struct altera_sdram_platdata *plat)
-{
-	/* Release NOC ddr scheduler from reset */
-	socfpga_reset_deassert_noc_ddr_scheduler();
-
-	/* Bringup the DDR (calibration and configuration) */
-	return ddr_setup(plat);
-}
-
 static u64 sdram_size_calc(struct altera_sdram_platdata *plat)
 {
 	u32 dramaddrw = readl(plat->iohmc + DRAMADDRW);
@@ -703,8 +695,17 @@ static int altera_sdram_ofdata_to_platdata(struct udevice *dev)
 
 static int altera_sdram_probe(struct udevice *dev)
 {
+	int ret;
 	struct altera_sdram_priv *priv = dev_get_priv(dev);
 
+	ret = reset_get_bulk(dev, &priv->resets);
+	if (ret) {
+		dev_err(dev, "Can't get reset: %d\n", ret);
+		return -ENODEV;
+	}
+
+	reset_deassert_bulk(&priv->resets);
+
 	if (ddr_calibration_sequence(dev->platdata) != 0) {
 		puts("SDRAM init failed.\n");
 		goto failed;
@@ -716,6 +717,7 @@ static int altera_sdram_probe(struct udevice *dev)
 	return 0;
 
 failed:
+	reset_assert_bulk(&priv->resets);
 	return -ENODEV;
 }
 
Signature · 1 line
2.19.0
#4 lore raw

PATCH v2 4/7 arm: socfpga: arria10: Move sdram_arria10.h to drivers/ddr/altera

In reply to Ley Foon Tan

Move sdram_arria10.h to drivers/ddr/altera directory. No functionality change.

---
 arch/arm/mach-socfpga/include/mach/sdram.h                     | 2 +-
 arch/arm/mach-socfpga/misc_arria10.c                           | 2 +-
 drivers/ddr/altera/sdram_arria10.c                             | 3 ++-
 .../include/mach => drivers/ddr/altera}/sdram_arria10.h        | 0
 4 files changed, 4 insertions(+), 3 deletions(-)
 rename {arch/arm/mach-socfpga/include/mach => drivers/ddr/altera}/sdram_arria10.h (100%)
arch/arm/mach-socfpga/include/mach/sdram.h +1 -1
index 79cb9e6064a2..0a52c1078b5f 100644
@@ -10,7 +10,7 @@
 #if defined(CONFIG_TARGET_SOCFPGA_GEN5)
 #include <asm/arch/sdram_gen5.h>
 #elif defined(CONFIG_TARGET_SOCFPGA_ARRIA10)
-#include <asm/arch/sdram_arria10.h>
+#include "../../../../../drivers/ddr/altera/sdram_arria10.h"
 #endif
 
 #endif
arch/arm/mach-socfpga/misc_arria10.c +1 -1
index d56349b7f3ea..1ddffaa0ac55 100644
@@ -15,7 +15,7 @@
 #include <asm/arch/pinmux.h>
 #include <asm/arch/reset_manager.h>
 #include <asm/arch/reset_manager_arria10.h>
-#include <asm/arch/sdram_arria10.h>
+#include <asm/arch/sdram.h>
 #include <asm/arch/system_manager.h>
 #include <asm/arch/nic301.h>
 #include <asm/io.h>
drivers/ddr/altera/sdram_arria10.c +2 -1
index 3374efaae801..6201dc277460 100644
@@ -16,10 +16,11 @@
 #include <asm/io.h>
 #include <asm/arch/fpga_manager.h>
 #include <asm/arch/misc.h>
-#include <asm/arch/sdram.h>
 #include <dm/device_compat.h>
 #include <linux/kernel.h>
 
+#include "sdram_arria10.h"
+
 DECLARE_GLOBAL_DATA_PTR;
 
 struct altera_sdram_priv {
drivers/ddr/altera/sdram_arria10.h renamed from arch/arm/mach-socfpga/include/mach/sdram_arria10.h +0 -0
similarity index 100%
rename from arch/arm/mach-socfpga/include/mach/sdram_arria10.h
rename to drivers/ddr/altera/sdram_arria10.h
Signature · 1 line
2.19.0
#5 lore raw

PATCH v2 5/7 ddr: altera: arria10: Add RAM size check

In reply to Ley Foon Tan

Add call to get_ram_size() function to check memory range for valid RAM.

---
v2:
- Change SZ_1G to full SDRAM size in get_ram_size() argument.

---
 drivers/ddr/altera/sdram_arria10.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
drivers/ddr/altera/sdram_arria10.c +18 -1
index 6201dc277460..3fa34a1ae390 100644
@@ -8,6 +8,7 @@
 #include <dm.h>
 #include <errno.h>
 #include <fdtdec.h>
+#include <hang.h>
 #include <malloc.h>
 #include <ram.h>
 #include <reset.h>
@@ -17,7 +18,7 @@
 #include <asm/arch/fpga_manager.h>
 #include <asm/arch/misc.h>
 #include <dm/device_compat.h>
-#include <linux/kernel.h>
+#include <linux/sizes.h>
 
 #include "sdram_arria10.h"
 
@@ -671,6 +672,21 @@ static int ddr_calibration_sequence(struct altera_sdram_platdata *plat)
 	return 0;
 }
 
+static void sdram_size_check(struct ram_info *ram)
+{
+	phys_size_t ram_check = 0;
+
+	debug("DDR: Running SDRAM size sanity check\n");
+
+	ram_check = get_ram_size((void *)(ram->base), ram->size);
+	if (ram_check != ram->size) {
+		puts("DDR: SDRAM size check failed!\n");
+		hang();
+	}
+
+	debug("DDR: SDRAM size check passed!\n");
+}
+
 static int altera_sdram_ofdata_to_platdata(struct udevice *dev)
 {
 	struct altera_sdram_platdata *plat = dev->platdata;
@@ -715,6 +731,7 @@ static int altera_sdram_probe(struct udevice *dev)
 	priv->info.base = gd->bd->bi_dram[0].start;
 	priv->info.size = gd->ram_size;
 
+	sdram_size_check(&priv->info);
 	return 0;
 
 failed:
Signature · 1 line
2.19.0
#6 lore raw

PATCH v2 6/7 ddr: altera: arria10: Change %i to %u for printf

In reply to Ley Foon Tan

Tiny printf doesn't support %i, change to %u.

---
 drivers/ddr/altera/sdram_arria10.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ddr/altera/sdram_arria10.c +1 -1
index 3fa34a1ae390..e4944ef95183 100644
@@ -195,7 +195,7 @@ static void sdram_init_ecc_bits(u32 size)
 
 	dcache_enable();
 
-	printf("DDRCAL: Scrubbing ECC RAM (%i MiB).\n", size >> 20);
+	printf("DDRCAL: Scrubbing ECC RAM (%u MiB).\n", size >> 20);
 	memset((void *)0x8000, 0, size - 0x8000);
 	flush_dcache_all();
 	printf("DDRCAL: Scrubbing ECC RAM done.\n");
Signature · 1 line
2.19.0
#7 lore raw

PATCH v2 7/7 ddr: altera: arria10: Remove call to dram_init_banksize()

In reply to Ley Foon Tan

dram_init_banksize() is called in board_init_f() boot sequences in Uboot, remove it from SDRAM driver.

---
 drivers/ddr/altera/sdram_arria10.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/ddr/altera/sdram_arria10.c +0 -3
index e4944ef95183..27fd393e6fe4 100644
@@ -660,9 +660,6 @@ static int ddr_calibration_sequence(struct altera_sdram_platdata *plat)
 	else
 		gd->ram_size = (u32)size;
 
-	/* setup the dram info within bd */
-	dram_init_banksize();
-
 	if (of_sdram_firewall_setup(gd->fdt_blob))
 		puts("FW: Error Configuring Firewall\n");
 
Signature · 1 line
2.19.0
#8 lore raw

PATCH v2 7/7 ddr: altera: arria10: Remove call to dram_init_banksize()

Quoted 14 lines · Ley Foon Tan

dram_init_banksize() is called in board_init_f() boot sequences in Uboot, remove it from SDRAM driver.

---
 drivers/ddr/altera/sdram_arria10.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/ddr/altera/sdram_arria10.c +0 -0
index e4944ef95183..27fd393e6fe4 100644

drivers/ddr/altera/sdram_arria10.c static int ddr_calibration_sequence(struct altera_sdram_platdata *plat) · line 665

Quoted 9 lines
drivers/ddr/altera/sdram_arria10.c +0 -3
@@ -660,9 +660,6 @@ static int ddr_calibration_sequence(struct altera_sdram_platdata *plat)
        else
                gd->ram_size = (u32)size;
 
-       /* setup the dram info within bd */
-       dram_init_banksize();
-
        if (of_sdram_firewall_setup(gd->fdt_blob))
                puts("FW: Error Configuring Firewall\n");
 

Hi

Need to drop this patch, Found that dcache_enable() needs gd->bd->bi_dram[]. I will send v3.

Thanks.

Regards
Ley Foon

#9 lore raw

PATCH v2 7/7 ddr: altera: arria10: Remove call to dram_init_banksize()

Quoted 26 lines · Ley Foon Tan
Quoted 14 lines · Ley Foon Tan

dram_init_banksize() is called in board_init_f() boot sequences in Uboot, remove it from SDRAM driver.

---
 drivers/ddr/altera/sdram_arria10.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/ddr/altera/sdram_arria10.c +0 -0
index e4944ef95183..27fd393e6fe4 100644

drivers/ddr/altera/sdram_arria10.c static int ddr_calibration_sequence(struct altera_sdram_platdata *plat) · line 665

Quoted 9 lines
drivers/ddr/altera/sdram_arria10.c +0 -3
@@ -660,9 +660,6 @@ static int ddr_calibration_sequence(struct altera_sdram_platdata *plat)
        else
                gd->ram_size = (u32)size;
 
-       /* setup the dram info within bd */
-       dram_init_banksize();
-
        if (of_sdram_firewall_setup(gd->fdt_blob))
                puts("FW: Error Configuring Firewall\n");
 

Hi

Quoted 2 lines

Need to drop this patch, Found that dcache_enable() needs gd->bd->bi_dram[]. I will send v3.

OK, thanks.

#10 lore raw

v2 cover ddr: altera: arria10: Convert SDRAM driver to DM

In reply to Ley Foon Tan
Quoted 43 lines

-----Original Message-----
From: Tan, Ley Foon <[email protected]>
Sent: Monday, April 20, 2020 4:46 PM
To: u-boot at lists.denx.de
Cc: Marek Vasut <[email protected]>; Ley Foon Tan <[email protected]>; See, Chin Liang <[email protected]>; Simon Goldschmidt <[email protected]>; Chee, Tien Fong <[email protected]>; Tan, Ley Foon <[email protected]>
Subject: [PATCH v2 0/7] ddr: altera: arria10: Convert SDRAM driver to DM

This patchset mainly to covert Arria 10 SDRAM driver to device model and fixes few bugs in driver. It also added RAM size check function to check valid RAM.

v1->v2:
- Update Patch[1] commit description
- Change debug() to printf() if failed to probe SDRAM driver in SPL. [Patch 2]
- Change to use MACRO(n) to calculate register address. [Patch 2]
- Call to reset_assert_bulk() if failed in _probe(). [Patch 3]
- Change SZ_1G to full SDRAM size in get_ram_size() argument. [Patch 5]
- Patch 4, 6 and 7 unchanged.

Ley Foon Tan (7):
ddr: altera: arria10: Fix incorrect address for mpu1
ddr: altera: arria10: Move SDRAM driver to DM
ddr: altera: arria10: Change to use reset DM function
arm: socfpga: arria10: Move sdram_arria10.h to drivers/ddr/altera
ddr: altera: arria10: Add RAM size check
ddr: altera: arria10: Change %i to %u for printf
ddr: altera: arria10: Remove call to dram_init_banksize()

 arch/arm/dts/socfpga_arria10-u-boot.dtsi      |   8 +
 .../include/mach/reset_manager_arria10.h      |   1 -
 arch/arm/mach-socfpga/include/mach/sdram.h    |   2 +-
 arch/arm/mach-socfpga/misc_arria10.c          |   2 +-
 arch/arm/mach-socfpga/reset_manager_arria10.c |   7 -
 arch/arm/mach-socfpga/spl_a10.c               |  14 +-
 drivers/ddr/altera/Kconfig                    |   4 +-
 drivers/ddr/altera/sdram_arria10.c            | 382 ++++++++++--------
 .../ddr/altera}/sdram_arria10.h               | 225 ++---------
 9 files changed, 285 insertions(+), 360 deletions(-)  rename {arch/arm/mach-
Quoted 4 lines

socfpga/include/mach => drivers/ddr/altera}/sdram_arria10.h (72%)

--
2.19.0

Hi

Any further comment on this patchset?

Thanks.

Regards
Ley Foon