Skip to contentSkip to conversation

Move Stratix 10 SDRAM driver to DM

PATCH Superseded Ley Foon Tan 3 participants 8 messages Apr 30, 2019 – May 2, 2019

Subsystems (4)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover Move Stratix 10 SDRAM driver to DM

Compile ALTERA_SDRAM driver in SPL only and move Stratix 10 SDRAM driver to DM.

v2->v3:
-------
- Compile ALTERA_SDRAM driver in SPL only
- Separate dts change to new patch
- Change to use #if CONFIG_IS_ENABLED(ALTERA_SDRAM)
- Add _remove()
- Remove #ifdef CONFIG_SPL_BUILD checking in sdram_s10.c

History:
--------
[v1]: https://patchwork.ozlabs.org/patch/1066765/
[v2]: https://patchwork.ozlabs.org/patch/1089957/

Ley Foon Tan (3):
ddr: altera: Compile ALTERA SDRAM in SPL only
arm: dts: Stratix10: Add SDRAM node
arm: socfpga: Move Stratix 10 SDRAM driver to DM

 Makefile                                      |   2 +-
 arch/arm/dts/socfpga_stratix10.dtsi           |   9 +
 arch/arm/mach-socfpga/Kconfig                 |   4 +-
 arch/arm/mach-socfpga/spl_s10.c               |  16 +-
 configs/socfpga_stratix10_defconfig           |   1 +
 drivers/Makefile                              |   2 +-
 drivers/ddr/altera/Kconfig                    |  11 +-
 drivers/ddr/altera/Makefile                   |   2 +-
 drivers/ddr/altera/sdram_s10.c                | 251 ++++++++++++------
 .../mach => drivers/ddr/altera}/sdram_s10.h   |   4 -
 include/configs/socfpga_stratix10_socdk.h     |   5 -
 11 files changed, 208 insertions(+), 99 deletions(-)
 rename {arch/arm/mach-socfpga/include/mach => drivers/ddr/altera}/sdram_s10.h (97%)
Signature · 1 line
2.19.0
#1 lore raw

PATCH v3 1/3 ddr: altera: Compile ALTERA SDRAM in SPL only

Compile ALTERA_SDRAM driver in SPL only.
Rename ALTERA_SDRAM to SPL_ALTERA_SDRAM.

---
 Makefile                                  | 2 +-
 arch/arm/mach-socfpga/Kconfig             | 4 ++--
 drivers/Makefile                          | 2 +-
 drivers/ddr/altera/Kconfig                | 5 +++--
 drivers/ddr/altera/Makefile               | 2 +-
 include/configs/socfpga_stratix10_socdk.h | 2 +-
 6 files changed, 9 insertions(+), 8 deletions(-)
Makefile +1 -1
index 66a09ac900..53c7709d22 100644
@@ -713,7 +713,7 @@ libs-y += drivers/spi/
 libs-$(CONFIG_FMAN_ENET) += drivers/net/fm/
 libs-$(CONFIG_SYS_FSL_DDR) += drivers/ddr/fsl/
 libs-$(CONFIG_SYS_FSL_MMDC) += drivers/ddr/fsl/
-libs-$(CONFIG_ALTERA_SDRAM) += drivers/ddr/altera/
+libs-$(CONFIG_$(SPL_)ALTERA_SDRAM) += drivers/ddr/altera/
 libs-y += drivers/serial/
 libs-y += drivers/usb/dwc3/
 libs-y += drivers/usb/common/
arch/arm/mach-socfpga/Kconfig +2 -2
index 5e87371f8c..d4d878d3be 100644
@@ -9,7 +9,7 @@ config TARGET_SOCFPGA_ARRIA5
 
 config TARGET_SOCFPGA_ARRIA10
 	bool
-	select ALTERA_SDRAM
+	select SPL_ALTERA_SDRAM
 	select SPL_BOARD_INIT if SPL
 	select CLK
 	select SPL_CLK if SPL
@@ -28,7 +28,7 @@ config TARGET_SOCFPGA_CYCLONE5
 
 config TARGET_SOCFPGA_GEN5
 	bool
-	select ALTERA_SDRAM
+	select SPL_ALTERA_SDRAM
 
 config TARGET_SOCFPGA_STRATIX10
 	bool
drivers/Makefile +1 -1
index a7bba3ed56..e501ae8d04 100644
@@ -34,7 +34,7 @@ obj-$(CONFIG_SPL_CRYPTO_SUPPORT) += crypto/
 obj-$(CONFIG_SPL_MPC8XXX_INIT_DDR_SUPPORT) += ddr/fsl/
 obj-$(CONFIG_ARMADA_38X) += ddr/marvell/a38x/
 obj-$(CONFIG_ARMADA_XP) += ddr/marvell/axp/
-obj-$(CONFIG_ALTERA_SDRAM) += ddr/altera/
+obj-$(CONFIG_$(SPL_)ALTERA_SDRAM) += ddr/altera/
 obj-$(CONFIG_ARCH_IMX8M) += ddr/imx/imx8m/
 obj-$(CONFIG_SPL_POWER_SUPPORT) += power/ power/pmic/
 obj-$(CONFIG_SPL_POWER_SUPPORT) += power/regulator/
drivers/ddr/altera/Kconfig +3 -2
index 8f60b56eb8..83c1ab5e07 100644
@@ -1,5 +1,6 @@
-config ALTERA_SDRAM
-	bool "SoCFPGA DDR SDRAM driver"
+config SPL_ALTERA_SDRAM
+	bool "SoCFPGA DDR SDRAM driver in SPL"
+	depends on SPL
 	depends on TARGET_SOCFPGA_GEN5 || TARGET_SOCFPGA_ARRIA10
 	select RAM if TARGET_SOCFPGA_GEN5
 	select SPL_RAM if TARGET_SOCFPGA_GEN5
drivers/ddr/altera/Makefile +1 -1
index 3615b617ec..341ac0d73b 100644
@@ -6,7 +6,7 @@
 # (C) Copyright 2010, Thomas Chou <[email protected]>
 # Copyright (C) 2014 Altera Corporation <www.altera.com>
 
-ifdef CONFIG_ALTERA_SDRAM
+ifdef CONFIG_$(SPL_)ALTERA_SDRAM
 obj-$(CONFIG_TARGET_SOCFPGA_GEN5) += sdram_gen5.o sequencer.o
 obj-$(CONFIG_TARGET_SOCFPGA_ARRIA10) += sdram_arria10.o
 obj-$(CONFIG_TARGET_SOCFPGA_STRATIX10) += sdram_s10.o
include/configs/socfpga_stratix10_socdk.h +1 -1
index 31c267f55d..9d1bc8e8d5 100644
@@ -132,7 +132,7 @@ unsigned int cm_get_qspi_controller_clk_hz(void);
 /*
  * SDRAM controller
  */
-#define CONFIG_ALTERA_SDRAM
+#define CONFIG_SPL_ALTERA_SDRAM
 
 /*
  * Serial / UART configurations
Signature · 1 line
2.19.0
#2 lore raw

PATCH v3 1/3 ddr: altera: Compile ALTERA SDRAM in SPL only

Quoted 13 lines · Ley Foon Tan

Compile ALTERA_SDRAM driver in SPL only.
Rename ALTERA_SDRAM to SPL_ALTERA_SDRAM.

---
 Makefile                                  | 2 +-
 arch/arm/mach-socfpga/Kconfig             | 4 ++--
 drivers/Makefile                          | 2 +-
 drivers/ddr/altera/Kconfig                | 5 +++--
 drivers/ddr/altera/Makefile               | 2 +-
 include/configs/socfpga_stratix10_socdk.h | 2 +-
 6 files changed, 9 insertions(+), 8 deletions(-)

[...]

include/configs/socfpga_stratix10_socdk.h unsigned int cm_get_qspi_controller_clk_hz(void); · line 135

Quoted 10 lines
include/configs/socfpga_stratix10_socdk.h +1 -1
index 31c267f55d..9d1bc8e8d5 100644
@@ -132,7 +132,7 @@ unsigned int cm_get_qspi_controller_clk_hz(void);
 /*
  * SDRAM controller
  */
-#define CONFIG_ALTERA_SDRAM
+#define CONFIG_SPL_ALTERA_SDRAM

I think this will trigger a build failure , since the CONFIG_SPL_ALTERA_SDRAM isn't in config whitelist.txt .

I guess the easiest way is to update the whitelist here too and then remove the new config option from it again in 3/3.

Signature · 2 lines
Best regards,
Marek Vasut
#3 lore raw

PATCH v3 1/3 ddr: altera: Compile ALTERA SDRAM in SPL only

Quoted 32 lines · Marek Vasut
Quoted 13 lines · Ley Foon Tan

Compile ALTERA_SDRAM driver in SPL only.
Rename ALTERA_SDRAM to SPL_ALTERA_SDRAM.

---
 Makefile                                  | 2 +-
 arch/arm/mach-socfpga/Kconfig             | 4 ++--
 drivers/Makefile                          | 2 +-
 drivers/ddr/altera/Kconfig                | 5 +++--
 drivers/ddr/altera/Makefile               | 2 +-
 include/configs/socfpga_stratix10_socdk.h | 2 +-
 6 files changed, 9 insertions(+), 8 deletions(-)

[...]

include/configs/socfpga_stratix10_socdk.h unsigned int cm_get_qspi_controller_clk_hz(void); · line 135

Quoted 10 lines
include/configs/socfpga_stratix10_socdk.h +1 -1
index 31c267f55d..9d1bc8e8d5 100644
@@ -132,7 +132,7 @@ unsigned int cm_get_qspi_controller_clk_hz(void);
 /*
  * SDRAM controller
  */
-#define CONFIG_ALTERA_SDRAM
+#define CONFIG_SPL_ALTERA_SDRAM

I think this will trigger a build failure , since the CONFIG_SPL_ALTERA_SDRAM isn't in config whitelist.txt .

Quoted 3 lines

I guess the easiest way is to update the whitelist here too and then remove the new config option from it again in 3/3.

Okay, will add CONFIG_SPL_ALTERA_SDRAM to scripts/config_whitelist.txt

Regards
Ley Foon

#4 lore raw

PATCH v3 2/3 arm: dts: Stratix10: Add SDRAM node

In reply to Ley Foon Tan

Add SDRAM device tree node to support SDRAM DM driver.

---
 arch/arm/dts/socfpga_stratix10.dtsi | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm/dts/socfpga_stratix10.dtsi +9 -0
index d1ae2fabae..bd68a78a37 100755
@@ -258,6 +258,15 @@
 			u-boot,dm-pre-reloc;
 		};
 
+		sdr: sdr at f8000400 {
+			 compatible = "altr,sdr-ctl-s10";
+			 reg = <0xf8000400 0x80>,
+			       <0xf8010000 0x190>,
+			       <0xf8011000 0x500>;
+			 resets = <&rst DDRSCH_RESET>;
+			 u-boot,dm-pre-reloc;
+		 };
+
 		spi0: spi at ffda4000 {
 			compatible = "snps,dw-apb-ssi";
 			#address-cells = <1>;
Signature · 1 line
2.19.0
#5 lore raw

PATCH v3 2/3 arm: dts: Stratix10: Add SDRAM node

Quoted 1 line · Ley Foon Tan

Add SDRAM device tree node to support SDRAM DM driver.

DT is a hardware description, so you're adding the node to describe the hardware that's present, not to enable software feature.

Quoted 26 lines
---
 arch/arm/dts/socfpga_stratix10.dtsi | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm/dts/socfpga_stratix10.dtsi +9 -0
index d1ae2fabae..bd68a78a37 100755
@@ -258,6 +258,15 @@
 			u-boot,dm-pre-reloc;
 		};
 
+		sdr: sdr at f8000400 {
+			 compatible = "altr,sdr-ctl-s10";
+			 reg = <0xf8000400 0x80>,
+			       <0xf8010000 0x190>,
+			       <0xf8011000 0x500>;
+			 resets = <&rst DDRSCH_RESET>;
+			 u-boot,dm-pre-reloc;
+		 };
+
 		spi0: spi at ffda4000 {
 			compatible = "snps,dw-apb-ssi";
 			#address-cells = <1>;
Signature · 2 lines
Best regards,
Marek Vasut
#6 lore raw

PATCH v3 2/3 arm: dts: Stratix10: Add SDRAM node

Quoted 6 lines · Marek Vasut
Quoted 1 line · Ley Foon Tan

Add SDRAM device tree node to support SDRAM DM driver.

DT is a hardware description, so you're adding the node to describe the hardware that's present, not to enable software feature.

Okay, will update description.

Regards
Ley Foon

Quoted 32 lines
Quoted 17 lines
---
 arch/arm/dts/socfpga_stratix10.dtsi | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm/dts/socfpga_stratix10.dtsi +2 -0
index d1ae2fabae..bd68a78a37 100755
@@ -258,6 +258,15 @@
                      u-boot,dm-pre-reloc;
              };
 
+             sdr: sdr at f8000400 {
+                      compatible = "altr,sdr-ctl-s10";

arch/arm/dts/socfpga_stratix10.dtsi line 272

Quoted 10 lines
arch/arm/dts/socfpga_stratix10.dtsi +7 -0
+                      reg = <0xf8000400 0x80>,
+                            <0xf8010000 0x190>,
+                            <0xf8011000 0x500>;
+                      resets = <&rst DDRSCH_RESET>;
+                      u-boot,dm-pre-reloc;
+              };
+
              spi0: spi at ffda4000 {
                      compatible = "snps,dw-apb-ssi";
                      #address-cells = <1>;

--
Best regards,
Marek Vasut

#7 lore raw

PATCH v3 3/3 arm: socfpga: Move Stratix 10 SDRAM driver to DM

In reply to Ley Foon Tan

Convert Stratix 10 SDRAM driver to device model.

Get rid of call to socfpga_per_reset() and use reset framework.

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

Move sdram_s10.h from arch to driver/ddr/altera directory.

---
 arch/arm/mach-socfpga/spl_s10.c               |  16 +-
 configs/socfpga_stratix10_defconfig           |   1 +
 drivers/ddr/altera/Kconfig                    |   6 +-
 drivers/ddr/altera/sdram_s10.c                | 251 ++++++++++++------
 .../mach => drivers/ddr/altera}/sdram_s10.h   |   4 -
 include/configs/socfpga_stratix10_socdk.h     |   5 -
 6 files changed, 191 insertions(+), 92 deletions(-)
 rename {arch/arm/mach-socfpga/include/mach => drivers/ddr/altera}/sdram_s10.h (97%)
arch/arm/mach-socfpga/spl_s10.c +10 -6
index a141ffe82a..ec65e1ce64 100644
@@ -15,9 +15,9 @@
 #include <asm/arch/firewall_s10.h>
 #include <asm/arch/mailbox_s10.h>
 #include <asm/arch/reset_manager.h>
-#include <asm/arch/sdram_s10.h>
 #include <asm/arch/system_manager.h>
 #include <watchdog.h>
+#include <dm/uclass.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -175,11 +175,15 @@ void board_init_f(ulong dummy)
 	clrbits_le32(CCU_REG_ADDR(CCU_IOM_MPRT_ADMASK_MEM_RAM0),
 		     CCU_ADMASK_P_MASK | CCU_ADMASK_NS_MASK);
 
-	debug("DDR: Initializing Hard Memory Controller\n");
-	if (sdram_mmr_init_full(0)) {
-		puts("DDR: Initialization failed.\n");
-		hang();
-	}
+#if CONFIG_IS_ENABLED(ALTERA_SDRAM)
+		struct udevice *dev;
+
+		ret = uclass_get_device(UCLASS_RAM, 0, &dev);
+		if (ret) {
+			debug("DRAM init failed: %d\n", ret);
+			hang();
+		}
+#endif
 
 	mbox_init();
 
configs/socfpga_stratix10_defconfig +1 -0
index 4848013b21..c85a0f785a 100644
@@ -32,6 +32,7 @@ CONFIG_ENV_IS_IN_MMC=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_SPL_DM=y
 CONFIG_SPL_DM_SEQ_ALIAS=y
+CONFIG_SPL_ALTERA_SDRAM=y
 CONFIG_DM_GPIO=y
 CONFIG_DWAPB_GPIO=y
 CONFIG_DM_I2C=y
drivers/ddr/altera/Kconfig +3 -3
index 83c1ab5e07..2b1c1be3b5 100644
@@ -1,8 +1,8 @@
 config SPL_ALTERA_SDRAM
 	bool "SoCFPGA DDR SDRAM driver in SPL"
 	depends on SPL
-	depends on TARGET_SOCFPGA_GEN5 || TARGET_SOCFPGA_ARRIA10
-	select RAM if TARGET_SOCFPGA_GEN5
-	select SPL_RAM if TARGET_SOCFPGA_GEN5
+	depends on TARGET_SOCFPGA_GEN5 || TARGET_SOCFPGA_ARRIA10 || TARGET_SOCFPGA_STRATIX10
+	select RAM if TARGET_SOCFPGA_GEN5 || TARGET_SOCFPGA_STRATIX10
+	select SPL_RAM if TARGET_SOCFPGA_GEN5 || TARGET_SOCFPGA_STRATIX10
 	help
 	  Enable DDR SDRAM controller for the SoCFPGA devices.
drivers/ddr/altera/sdram_s10.c +177 -74

430 lines not on this page · raw message

drivers/ddr/altera/sdram_s10.h renamed from arch/arm/mach-socfpga/include/mach/sdram_s10.h +0 -4
similarity index 97%
rename from arch/arm/mach-socfpga/include/mach/sdram_s10.h
rename to drivers/ddr/altera/sdram_s10.h
index f39206ca1e..096c06cba2 100644
@@ -7,10 +7,6 @@
 #ifndef	_SDRAM_S10_H_
 #define	_SDRAM_S10_H_
 
-phys_size_t sdram_calculate_size(void);
-int sdram_mmr_init_full(unsigned int sdr_phy_reg);
-int sdram_calibration_full(void);
-
 #define DDR_TWR				15
 #define DDR_READ_LATENCY_DELAY		40
 #define DDR_ACTIVATE_FAWBANK		0x1
include/configs/socfpga_stratix10_socdk.h +0 -5
index 9d1bc8e8d5..2af808cadf 100644
@@ -129,11 +129,6 @@ unsigned int cm_get_qspi_controller_clk_hz(void);
 #define CONFIG_SYS_MEMTEST_START	0
 #define CONFIG_SYS_MEMTEST_END		PHYS_SDRAM_1_SIZE - 0x200000
 
-/*
- * SDRAM controller
- */
-#define CONFIG_SPL_ALTERA_SDRAM
-
 /*
  * Serial / UART configurations
  */
Signature · 1 line
2.19.0