Skip to contentSkip to conversation

Add Intel N5X SoC support

PATCH Superseded Siew Chin Lim 4 participants 35 messages Apr 30, 2021 – Jun 25, 2021

Subsystems (5)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add Intel N5X SoC support

This is the 2nd version of patchset to add Intel N5X SoC[1] support.

Intel N5X SoC is with a 64-bit quad core ARM Cortex-A53 MPCore hard processor system (HPS). New IPs in N5X are clock manager and DDR subsystem, other IPs have minor changes compared to Agilex.

Intel N5X SoC supports legacy boot without ATF for debugging purpose, ATF boot, and ATF boot with VAB enabled.

[1]: https://www.intel.com/content/www/us/en/products/programmable/asic/easic-devices/diamond-mesa-soc-devices.html

Patch status:
Have changes: Patch 1, 4, 5, 7, 11, 12, 13, 15, 17 Other patches unchanged.

Detail changelog can find in commit message.

v1->v2:
--------
Patch 1:
- New patch in n5x series, the change is needed to execute 'linux_qspi_enable' correctly in ATF boot flow

Patch 4:
- Enabled auto detect the endianness from the magic word
- Merged and simplifying the big and little endian flow

Patch 5:
- common.h need to be included before clock_manager.h
- Remove unnecessary comment : write 1 to clear
- Remove unnecessary () in the code

Patch 7:
- common.h need to be included before clock_manager.h
- For consistency, use small letter fo 0x0c and 0x1c in macros

Patch 11:
- Renamed local variable ?total_size? to ?remaining_size?

Patch 12:
- Move is_ddr_init_skipped and its helper functions to DDR driver and converted function to positive checking
- Using GENMASK() macro
- Fixed typo
- Return status of subfunction
- Changed dm to n5x

Patch 13:
- No change on the file. Need review again for this patch. common.h need to be included before clock_manager.h.

Patch 15:
- Remove socfpga_n5x.dtsi
- Reuse socfpga_agilex.dtsi in socfpga_n5x_socdk.dts and update n5x data accordingly.

Patch 17:
- Move linux_qspi_enable from bootcommand

Siew Chin Lim (16):
arm: socfpga: Move linux_qspi_enable from bootcommand to
board_prep_linux function
arm: socfpga: Changed base_addr_s10.h to base_addr_soc64.h
arm: socfpga: Add base address for Intel N5X device
arm: socfpga: Add handoff data support for Intel N5X device
drivers: clk: Add clock driver for Intel N5X device
arm: socfpga: Get clock manager base address for Intel N5X device
drivers: clk: Add memory clock driver for Intel N5X device
arm: socfpga: Move cm_get_mpu_clk_hz function declaration to
clock_manager.h
arm: socfpga: Add clock manager for Intel N5X device
arm: socfpga: Changed misc_s10.c to misc_soc64.c
ddr: altera: Add SDRAM driver for Intel N5X device
arm: socfpga: Add SPL for Intel N5X device
board: intel: Add socdk board support for Intel N5X device
arm: dts: Add base dtsi and devkit dts for Intel N5X device
include: configs: Add Intel N5X device CONFIGs
arm: socfpga: Enable Intel N5X device build

Tien Fong Chee (1):
ddr: socfpga: Enable memory test on memory size less than 1GB

 arch/arm/dts/Makefile                         |    1 +
 arch/arm/dts/socfpga_n5x-u-boot.dtsi          |  101 +
 arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi    |   67 +
 arch/arm/dts/socfpga_n5x_socdk.dts            |  243 ++
 arch/arm/mach-socfpga/Kconfig                 |   21 +-
 arch/arm/mach-socfpga/Makefile                |   32 +-
 arch/arm/mach-socfpga/board.c                 |   17 +-
 arch/arm/mach-socfpga/clock_manager_n5x.c     |   80 +
 .../{base_addr_s10.h => base_addr_soc64.h}    |   11 +-
 .../mach-socfpga/include/mach/clock_manager.h |    3 +
 .../include/mach/clock_manager_agilex.h       |    2 -
 .../include/mach/clock_manager_arria10.h      |    1 -
 .../include/mach/clock_manager_gen5.h         |    1 -
 .../include/mach/clock_manager_n5x.h          |   12 +
 .../include/mach/clock_manager_s10.h          |    1 -
 arch/arm/mach-socfpga/include/mach/firewall.h |    6 +
 .../mach-socfpga/include/mach/handoff_soc64.h |   38 +-
 .../include/mach/system_manager_soc64.h       |   10 +-
 arch/arm/mach-socfpga/misc.c                  |    3 +
 .../mach-socfpga/{misc_s10.c => misc_soc64.c} |   12 +-
 arch/arm/mach-socfpga/spl_n5x.c               |   94 +
 arch/arm/mach-socfpga/system_manager_soc64.c  |   18 +-
 arch/arm/mach-socfpga/wrap_handoff_soc64.c    |  126 +-
 board/intel/n5x-socdk/MAINTAINERS             |    7 +
 board/intel/n5x-socdk/Makefile                |    7 +
 board/intel/n5x-socdk/socfpga.c               |    7 +
 configs/socfpga_agilex_atf_defconfig          |    2 +-
 ...tf_defconfig => socfpga_n5x_atf_defconfig} |   13 +-
 ...ex_atf_defconfig => socfpga_n5x_defconfig} |   29 +-
 ...tf_defconfig => socfpga_n5x_vab_defconfig} |   14 +-
 configs/socfpga_stratix10_atf_defconfig       |    2 +-
 drivers/clk/altera/Makefile                   |    4 +-
 drivers/clk/altera/clk-mem-n5x.c              |  136 +
 drivers/clk/altera/clk-mem-n5x.h              |   84 +
 drivers/clk/altera/clk-n5x.c                  |  489 ++++
 drivers/clk/altera/clk-n5x.h                  |  217 ++
 drivers/ddr/altera/Makefile                   |    3 +-
 drivers/ddr/altera/sdram_n5x.c                | 2299 +++++++++++++++++
 drivers/ddr/altera/sdram_soc64.c              |   94 +-
 drivers/ddr/altera/sdram_soc64.h              |    1 +
 include/configs/socfpga_n5x_socdk.h           |   45 +
 include/configs/socfpga_soc64_common.h        |    2 +-
 include/dt-bindings/clock/n5x-clock.h         |   71 +
 43 files changed, 4308 insertions(+), 118 deletions(-)
 create mode 100644 arch/arm/dts/socfpga_n5x-u-boot.dtsi
 create mode 100644 arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi
 create mode 100644 arch/arm/dts/socfpga_n5x_socdk.dts
 create mode 100644 arch/arm/mach-socfpga/clock_manager_n5x.c
 rename arch/arm/mach-socfpga/include/mach/{base_addr_s10.h => base_addr_soc64.h} (85%)
 create mode 100644 arch/arm/mach-socfpga/include/mach/clock_manager_n5x.h
 rename arch/arm/mach-socfpga/{misc_s10.c => misc_soc64.c} (100%)
 create mode 100644 arch/arm/mach-socfpga/spl_n5x.c
 create mode 100644 board/intel/n5x-socdk/MAINTAINERS
 create mode 100644 board/intel/n5x-socdk/Makefile
 create mode 100644 board/intel/n5x-socdk/socfpga.c
 copy configs/{socfpga_agilex_atf_defconfig => socfpga_n5x_atf_defconfig} (84%)
 copy configs/{socfpga_agilex_atf_defconfig => socfpga_n5x_defconfig} (63%)
 copy configs/{socfpga_agilex_atf_defconfig => socfpga_n5x_vab_defconfig} (82%)
 create mode 100644 drivers/clk/altera/clk-mem-n5x.c
 create mode 100644 drivers/clk/altera/clk-mem-n5x.h
 create mode 100644 drivers/clk/altera/clk-n5x.c
 create mode 100644 drivers/clk/altera/clk-n5x.h
 create mode 100644 drivers/ddr/altera/sdram_n5x.c
 create mode 100644 include/configs/socfpga_n5x_socdk.h
 create mode 100644 include/dt-bindings/clock/n5x-clock.h
Signature · 1 line
2.19.0
#1 lore raw

PATCH v2 1/17 arm: socfpga: Move linux_qspi_enable from bootcommand to board_prep_linux function

Move 'linux_qspi_enable' from bootcommand to board_prep_linux function when OS booted from FIT image for Stratix 10 and Agilex. This flow is common for all Intel SOC64 devices.

U-Boot will update 'fdt_addr' environment value based on FIT image in board_prep_linux function, and 'linux_qspi_enable' will refer to 'fdt_addr' environment value to retrieve the device tree node.

---
v2:
- New patch in n5x series, the change is needed to execute 'linux_qspi_enable' correctly in ATF boot flow

---
 arch/arm/mach-socfpga/board.c           | 17 +++++++++--------
 configs/socfpga_agilex_atf_defconfig    |  2 +-
 configs/socfpga_stratix10_atf_defconfig |  2 +-
 3 files changed, 11 insertions(+), 10 deletions(-)
arch/arm/mach-socfpga/board.c +9 -8
index 650122fcd4..f5a3f2ad62 100644
@@ -115,17 +115,18 @@ void board_fit_image_post_process(void **p_image, size_t *p_size)
 #if !IS_ENABLED(CONFIG_SPL_BUILD) && IS_ENABLED(CONFIG_FIT)
 void board_prep_linux(bootm_headers_t *images)
 {
-	if (IS_ENABLED(CONFIG_SOCFPGA_SECURE_VAB_AUTH) &&
-	    !IS_ENABLED(CONFIG_SOCFPGA_SECURE_VAB_AUTH_ALLOW_NON_FIT_IMAGE)) {
-		/*
-		 * Ensure the OS is always booted from FIT and with
-		 * VAB signed certificate
-		 */
-		if (!images->fit_uname_cfg) {
+	if (!images->fit_uname_cfg) {
+		if (IS_ENABLED(CONFIG_SOCFPGA_SECURE_VAB_AUTH) &&
+		    !IS_ENABLED(CONFIG_SOCFPGA_SECURE_VAB_AUTH_ALLOW_NON_FIT_IMAGE)) {
+			/*
+			 * Ensure the OS is always booted from FIT and with
+			 * VAB signed certificate
+			 */
 			printf("Please use FIT with VAB signed images!\n");
 			hang();
 		}
-
+	} else {
+		/* Update fdt_addr in enviroment variable */
 		env_set_hex("fdt_addr", (ulong)images->ft_addr);
 		debug("images->ft_addr = 0x%08lx\n", (ulong)images->ft_addr);
 	}
configs/socfpga_agilex_atf_defconfig +1 -1
index 0de65a22a0..e0a8714e3d 100644
@@ -22,7 +22,7 @@ CONFIG_BOOTDELAY=5
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="earlycon"
 CONFIG_USE_BOOTCOMMAND=y
-CONFIG_BOOTCOMMAND="run fatscript; run mmcfitload; run linux_qspi_enable; run mmcfitboot"
+CONFIG_BOOTCOMMAND="run fatscript; run mmcfitload; run mmcfitboot"
 CONFIG_SPL_CRC32_SUPPORT=y
 CONFIG_SPL_CACHE=y
 CONFIG_SPL_SPI_LOAD=y
configs/socfpga_stratix10_atf_defconfig +1 -1
index c187987dd8..d0bc5e7909 100644
@@ -22,7 +22,7 @@ CONFIG_BOOTDELAY=5
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="earlycon"
 CONFIG_USE_BOOTCOMMAND=y
-CONFIG_BOOTCOMMAND="run fatscript; run mmcfitload; run linux_qspi_enable; run mmcfitboot"
+CONFIG_BOOTCOMMAND="run fatscript; run mmcfitload; run mmcfitboot"
 CONFIG_SPL_CRC32_SUPPORT=y
 CONFIG_SPL_SPI_LOAD=y
 CONFIG_SPL_ATF=y
Signature · 1 line
2.19.0
Reviewed-by on v2 1/17
#2 lore raw

Re: [v2 01/17] arm: socfpga: Move linux_qspi_enable from bootcommand to board_prep_linux function

Quoted 15 lines · Siew Chin Lim

Move 'linux_qspi_enable' from bootcommand to board_prep_linux function when OS booted from FIT image for Stratix 10 and Agilex. This flow is common for all Intel SOC64 devices.

U-Boot will update 'fdt_addr' environment value based on FIT image in board_prep_linux function, and 'linux_qspi_enable' will refer to 'fdt_addr' environment value to retrieve the device tree node.

---
v2:
- New patch in n5x series, the change is needed to execute 'linux_qspi_enable' correctly in ATF boot flow

Quoted 6 lines
---
 arch/arm/mach-socfpga/board.c           | 17 +++++++++--------
 configs/socfpga_agilex_atf_defconfig    |  2 +-
 configs/socfpga_stratix10_atf_defconfig |  2 +-
 3 files changed, 11 insertions(+), 10 deletions(-)

Regards
Ley Foon

#3 lore raw

PATCH v2 2/17 arm: socfpga: Changed base_addr_s10.h to base_addr_soc64.h

In reply to Siew Chin Lim

Rename to common file name to used by all SOC64 devices and change "_S10_" to "_SOC64_" in base_addr_soc64.h.

---
 .../include/mach/{base_addr_s10.h => base_addr_soc64.h}   | 8 ++++----
 include/configs/socfpga_soc64_common.h                    | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
 rename arch/arm/mach-socfpga/include/mach/{base_addr_s10.h => base_addr_soc64.h} (89%)
arch/arm/mach-socfpga/include/mach/base_addr_soc64.h renamed from arch/arm/mach-socfpga/include/mach/base_addr_s10.h +4 -4
similarity index 89%
rename from arch/arm/mach-socfpga/include/mach/base_addr_s10.h
rename to arch/arm/mach-socfpga/include/mach/base_addr_soc64.h
index d3eca65e97..f89066d771 100644
@@ -1,10 +1,10 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 /*
- * Copyright (C) 2016-2017 Intel Corporation <www.intel.com>
+ * Copyright (C) 2016-2021 Intel Corporation <www.intel.com>
  */
 
-#ifndef _SOCFPGA_S10_BASE_HARDWARE_H_
-#define _SOCFPGA_S10_BASE_HARDWARE_H_
+#ifndef _SOCFPGA_SOC64_BASE_HARDWARE_H_
+#define _SOCFPGA_SOC64_BASE_HARDWARE_H_
 
 #define SOCFPGA_CCU_ADDRESS			0xf7000000
 #define SOCFPGA_SDR_SCHEDULER_ADDRESS		0xf8000400
@@ -44,4 +44,4 @@
 #define GICD_BASE				0xfffc1000
 #define GICC_BASE				0xfffc2000
 
-#endif /* _SOCFPGA_S10_BASE_HARDWARE_H_ */
+#endif /* _SOCFPGA_SOC64_BASE_HARDWARE_H_ */
include/configs/socfpga_soc64_common.h +1 -1
index 5afdb10454..f0b7884ebc 100644
@@ -7,7 +7,7 @@
 #ifndef __CONFIG_SOCFPGA_SOC64_COMMON_H__
 #define __CONFIG_SOCFPGA_SOC64_COMMON_H__
 
-#include <asm/arch/base_addr_s10.h>
+#include <asm/arch/base_addr_soc64.h>
 #include <asm/arch/handoff_soc64.h>
 #include <linux/stringify.h>
 
Signature · 1 line
2.19.0
#4 lore raw

PATCH v2 3/17 arm: socfpga: Add base address for Intel N5X device

In reply to Siew Chin Lim

Reuse base_addr_soc64.h for Intel N5X device, the address is the same as Agilex.

---
 arch/arm/mach-socfpga/include/mach/base_addr_soc64.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/mach-socfpga/include/mach/base_addr_soc64.h +2 -1
index f89066d771..3f899fcfa3 100644
@@ -10,7 +10,8 @@
 #define SOCFPGA_SDR_SCHEDULER_ADDRESS		0xf8000400
 #define SOCFPGA_HMC_MMR_IO48_ADDRESS		0xf8010000
 #define SOCFPGA_SDR_ADDRESS			0xf8011000
-#ifdef CONFIG_TARGET_SOCFPGA_AGILEX
+#if IS_ENABLED(CONFIG_TARGET_SOCFPGA_AGILEX) || \
+	IS_ENABLED(CONFIG_TARGET_SOCFPGA_N5X)
 #define SOCFPGA_FW_MPU_DDR_SCR_ADDRESS		0xf8020200
 #else
 #define SOCFPGA_FW_MPU_DDR_SCR_ADDRESS		0xf8020100
Signature · 1 line
2.19.0
#5 lore raw

PATCH v2 4/17 arm: socfpga: Add handoff data support for Intel N5X device

In reply to Siew Chin Lim

N5X support both HPS handoff data and DDR handoff data. Existing HPS handoff functions are restructured to support both existing devices and N5X device.

---
v2:
- Enabled auto detect the endianness from the magic word
- Merged and simplifying the big and little endian flow

---
 .../mach-socfpga/include/mach/handoff_soc64.h |  38 +++++-
 arch/arm/mach-socfpga/system_manager_soc64.c  |  18 +--
 arch/arm/mach-socfpga/wrap_handoff_soc64.c    | 126 +++++++++++++-----
 3 files changed, 136 insertions(+), 46 deletions(-)
arch/arm/mach-socfpga/include/mach/handoff_soc64.h +33 -5
index 3750216a9a..902fc6bfb5 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0
  *
- * Copyright (C) 2016-2020 Intel Corporation <www.intel.com>
+ * Copyright (C) 2016-2021 Intel Corporation <www.intel.com>
  *
  */
 
@@ -23,8 +23,36 @@
 #define SOC64_HANDOFF_OFFSET_DATA	0x10
 #define SOC64_HANDOFF_SIZE		4096
 
+#if IS_ENABLED(CONFIG_TARGET_SOCFPGA_STRATIX10) || \
+	IS_ENABLED(CONFIG_TARGET_SOCFPGA_AGILEX)
 #define SOC64_HANDOFF_BASE		0xFFE3F000
 #define SOC64_HANDOFF_MISC		(SOC64_HANDOFF_BASE + 0x610)
+#elif IS_ENABLED(CONFIG_TARGET_SOCFPGA_N5X)
+#define SOC64_HANDOFF_BASE		0xFFE5F000
+#define SOC64_HANDOFF_MISC		(SOC64_HANDOFF_BASE + 0x630)
+
+/* DDR handoff */
+#define SOC64_HANDOFF_DDR_BASE			0xFFE5C000
+#define SOC64_HANDOFF_DDR_MAGIC			0x48524444
+#define SOC64_HANDOFF_DDR_UMCTL2_MAGIC		0x4C54434D
+#define SOC64_HANDOFF_DDR_UMCTL2_DDR4_TYPE	0x34524444
+#define SOC64_HANDOFF_DDR_UMCTL2_LPDDR4_0_TYPE	0x3044504C
+#define SOC64_HANDOFF_DDR_UMCTL2_LPDDR4_1_TYPE	0x3144504C
+#define SOC64_HANDOFF_DDR_MEMRESET_BASE		(SOC64_HANDOFF_DDR_BASE + 0xC)
+#define SOC64_HANDOFF_DDR_UMCTL2_SECTION	(SOC64_HANDOFF_DDR_BASE + 0x10)
+#define SOC64_HANDOFF_DDR_PHY_MAGIC		0x43594850
+#define SOC64_HANDOFF_DDR_PHY_INIT_ENGINE_MAGIC	0x45594850
+#define SOC64_HANDOFF_DDR_PHY_BASE_OFFSET	0x8
+#define SOC64_HANDOFF_DDR_UMCTL2_TYPE_OFFSET	0x8
+#define SOC64_HANDOFF_DDR_UMCTL2_BASE_ADDR_OFFSET	0xC
+#define SOC64_HANDOFF_DDR_TRAIN_IMEM_1D_SECTION	0xFFE50000
+#define SOC64_HANDOFF_DDR_TRAIN_DMEM_1D_SECTION	0xFFE58000
+#define SOC64_HANDOFF_DDR_TRAIN_IMEM_2D_SECTION	0xFFE44000
+#define SOC64_HANDOFF_DDR_TRAIN_DMEM_2D_SECTION	0xFFE4C000
+#define SOC64_HANDOFF_DDR_TRAIN_IMEM_LENGTH	SZ_32K
+#define SOC64_HANDOFF_DDR_TRAIN_DMEM_LENGTH	SZ_16K
+#endif
+
 #define SOC64_HANDOFF_MUX		(SOC64_HANDOFF_BASE + 0x10)
 #define SOC64_HANDOFF_IOCTL		(SOC64_HANDOFF_BASE + 0x1A0)
 #define SOC64_HANDOFF_FPGA		(SOC64_HANDOFF_BASE + 0x330)
@@ -52,11 +80,11 @@
 #include <asm/types.h>
 enum endianness {
 	LITTLE_ENDIAN = 0,
-	BIG_ENDIAN
+	BIG_ENDIAN,
+	UNKNOWN_ENDIANNESS
 };
 
-int socfpga_get_handoff_size(void *handoff_address, enum endianness endian);
-int socfpga_handoff_read(void *handoff_address, void *table, u32 table_len,
-			 enum endianness big_endian);
+int socfpga_get_handoff_size(void *handoff_address);
+int socfpga_handoff_read(void *handoff_address, void *table, u32 table_len);
 #endif
 #endif /* _HANDOFF_SOC64_H_ */
arch/arm/mach-socfpga/system_manager_soc64.c +9 -9
index 3b5e774e2d..958bb5107b 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (C) 2016-2018 Intel Corporation <www.intel.com>
+ * Copyright (C) 2016-2021 Intel Corporation <www.intel.com>
  *
  */
 
@@ -66,10 +66,10 @@ void populate_sysmgr_fpgaintf_module(void)
 void populate_sysmgr_pinmux(void)
 {
 	u32 len, i;
-	u32 len_mux = socfpga_get_handoff_size((void *)SOC64_HANDOFF_MUX, BIG_ENDIAN);
-	u32 len_ioctl = socfpga_get_handoff_size((void *)SOC64_HANDOFF_IOCTL, BIG_ENDIAN);
-	u32 len_fpga = socfpga_get_handoff_size((void *)SOC64_HANDOFF_FPGA, BIG_ENDIAN);
-	u32 len_delay = socfpga_get_handoff_size((void *)SOC64_HANDOFF_DELAY, BIG_ENDIAN);
+	u32 len_mux = socfpga_get_handoff_size((void *)SOC64_HANDOFF_MUX);
+	u32 len_ioctl = socfpga_get_handoff_size((void *)SOC64_HANDOFF_IOCTL);
+	u32 len_fpga = socfpga_get_handoff_size((void *)SOC64_HANDOFF_FPGA);
+	u32 len_delay = socfpga_get_handoff_size((void *)SOC64_HANDOFF_DELAY);
 
 	len = (len_mux > len_ioctl) ? len_mux : len_ioctl;
 	len = (len > len_fpga) ? len : len_fpga;
@@ -79,7 +79,7 @@ void populate_sysmgr_pinmux(void)
 
 	/* setup the pin sel */
 	len = (len_mux < SOC64_HANDOFF_MUX_LEN) ? len_mux : SOC64_HANDOFF_MUX_LEN;
-	socfpga_handoff_read((void *)SOC64_HANDOFF_MUX, handoff_table, len, BIG_ENDIAN);
+	socfpga_handoff_read((void *)SOC64_HANDOFF_MUX, handoff_table, len);
 	for (i = 0; i < len; i = i + 2) {
 		writel(handoff_table[i + 1],
 		       handoff_table[i] +
@@ -89,7 +89,7 @@ void populate_sysmgr_pinmux(void)
 
 	/* setup the pin ctrl */
 	len = (len_ioctl < SOC64_HANDOFF_IOCTL_LEN) ? len_ioctl : SOC64_HANDOFF_IOCTL_LEN;
-	socfpga_handoff_read((void *)SOC64_HANDOFF_IOCTL, handoff_table, len, BIG_ENDIAN);
+	socfpga_handoff_read((void *)SOC64_HANDOFF_IOCTL, handoff_table, len);
 	for (i = 0; i < len; i = i + 2) {
 		writel(handoff_table[i + 1],
 		       handoff_table[i] +
@@ -99,7 +99,7 @@ void populate_sysmgr_pinmux(void)
 
 	/* setup the fpga use */
 	len = (len_fpga < SOC64_HANDOFF_FPGA_LEN) ? len_fpga : SOC64_HANDOFF_FPGA_LEN;
-	socfpga_handoff_read((void *)SOC64_HANDOFF_FPGA, handoff_table, len, BIG_ENDIAN);
+	socfpga_handoff_read((void *)SOC64_HANDOFF_FPGA, handoff_table, len);
 	for (i = 0; i < len; i = i + 2) {
 		writel(handoff_table[i + 1],
 		       handoff_table[i] +
@@ -109,7 +109,7 @@ void populate_sysmgr_pinmux(void)
 
 	/* setup the IO delay */
 	len = (len_delay < SOC64_HANDOFF_DELAY_LEN) ? len_delay : SOC64_HANDOFF_DELAY_LEN;
-	socfpga_handoff_read((void *)SOC64_HANDOFF_DELAY, handoff_table, len, BIG_ENDIAN);
+	socfpga_handoff_read((void *)SOC64_HANDOFF_DELAY, handoff_table, len);
 	for (i = 0; i < len; i = i + 2) {
 		writel(handoff_table[i + 1],
 		       handoff_table[i] +
arch/arm/mach-socfpga/wrap_handoff_soc64.c +94 -32

153 lines not on this page · raw message

Signature · 1 line
2.19.0
#6 lore raw

Re: [v2 04/17] arm: socfpga: Add handoff data support for Intel N5X device

Quoted 17 lines · Siew Chin Lim

N5X support both HPS handoff data and DDR handoff data. Existing HPS handoff functions are restructured to support both existing devices and N5X device.

---
v2:
- Enabled auto detect the endianness from the magic word
- Merged and simplifying the big and little endian flow

---
 .../mach-socfpga/include/mach/handoff_soc64.h |  38 +++++-
 arch/arm/mach-socfpga/system_manager_soc64.c  |  18 +--
 arch/arm/mach-socfpga/wrap_handoff_soc64.c    | 126 +++++++++++++-----
 3 files changed, 136 insertions(+), 46 deletions(-)

[...]

Quoted 17 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +11 -1
@@ -10,12 +10,54 @@
 #include <errno.h>
 #include "log.h"
 
-int socfpga_get_handoff_size(void *handoff_address, enum endianness endian)
+static enum endianness check_endianness(u32 handoff)
+{
+       switch (handoff) {
+       case SOC64_HANDOFF_MAGIC_BOOT:
+       case SOC64_HANDOFF_MAGIC_MUX:
+       case SOC64_HANDOFF_MAGIC_IOCTL:
+       case SOC64_HANDOFF_MAGIC_FPGA:
+       case SOC64_HANDOFF_MAGIC_DELAY:
+       case SOC64_HANDOFF_MAGIC_CLOCK:
+       case SOC64_HANDOFF_MAGIC_MISC:
+               return BIG_ENDIAN;

arch/arm/mach-socfpga/wrap_handoff_soc64.c line 33

Quoted 10 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +10 -0
+#if IS_ENABLED(CONFIG_TARGET_SOCFPGA_N5X)
+       case SOC64_HANDOFF_DDR_UMCTL2_MAGIC:
+               debug("%s: umctl2 handoff data\n", __func__);
+               return LITTLE_ENDIAN;
+       case SOC64_HANDOFF_DDR_PHY_MAGIC:
+               debug("%s: PHY handoff data\n", __func__);
+               return LITTLE_ENDIAN;
+       case SOC64_HANDOFF_DDR_PHY_INIT_ENGINE_MAGIC:
+               debug("%s: PHY engine handoff data\n", __func__);
+               return LITTLE_ENDIAN;

Can merge to one 'return' and print the 'handoff' if needed.

Quoted 37 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +23 -3
+#endif
+       default:
+               debug("%s: Unknown endianness!!\n", __func__);
+               return UNKNOWN_ENDIANNESS;
+       }
+}
+
+int socfpga_get_handoff_size(void *handoff_address)
 {
        u32 size;
+       enum endianness endian_t;
+
+       /* Checking handoff data is little endian ? */
+       endian_t = check_endianness(readl(handoff_address));
+
+       if (endian_t == UNKNOWN_ENDIANNESS) {
+               /* Trying to check handoff data is big endian? */
+               endian_t = check_endianness(swab32(readl(handoff_address)));
+               if (endian_t == UNKNOWN_ENDIANNESS) {
+                       debug("%s: Cannot find HANDOFF MAGIC ", __func__);
+                       debug("at addr 0x%p\n", (u32 *)handoff_address);
+                       return -EPERM;
+               }
+       }
 
        size = readl(handoff_address + SOC64_HANDOFF_OFFSET_LENGTH);
-       if (endian == BIG_ENDIAN)
+       if (endian_t == BIG_ENDIAN)
                size = swab32(size);
 
        size = (size - SOC64_HANDOFF_OFFSET_DATA) / sizeof(u32);
@@ -26,41 +68,61 @@ int socfpga_get_handoff_size(void *handoff_address, enum endianness endian)
        return size;
 }
 
-int socfpga_handoff_read(void *handoff_address, void *table, u32 table_len,
-                        enum endianness big_endian)

arch/arm/mach-socfpga/wrap_handoff_soc64.c int socfpga_get_handoff_size(void *handoff_address, enum endianness endian) · line 79

Quoted 10 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +7 -1
+int socfpga_handoff_read(void *handoff_address, void *table, u32 table_len)
 {
-       u32 temp, i;
+       u32 temp;
        u32 *table_x32 = table;
+       u32 i = 0;
+       enum endianness endian_t;
+
+       /* Checking handoff data is little endian ? */
+       endian_t = check_endianness(readl(handoff_address));

This code is similar in socfpga_get_handoff_size(). Can have a function to get the endianness.

Quoted 29 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +2 -26
-       debug("%s: handoff addr = 0x%p ", __func__, (u32 *)handoff_address);
-
-       if (big_endian) {
-               if (swab32(readl(SOC64_HANDOFF_BASE)) == SOC64_HANDOFF_MAGIC_BOOT) {
-                       debug("Handoff table address = 0x%p ", table_x32);
-                       debug("table length = 0x%x\n", table_len);
-                       debug("%s: handoff data =\n{\n", __func__);
-
-                       for (i = 0; i < table_len; i++) {
-                               temp = readl(handoff_address +
-                                            SOC64_HANDOFF_OFFSET_DATA +
-                                            (i * sizeof(u32)));
-                               *table_x32 = swab32(temp);
-
-                               if (!(i % 2))
-                                       debug(" No.%d Addr 0x%08x: ", i,
-                                             *table_x32);
-                               else
-                                       debug(" 0x%08x\n", *table_x32);
-
-                               table_x32++;
-                       }
-                       debug("\n}\n");
-               } else {
-                       debug("%s: Cannot find SOC64_HANDOFF_MAGIC_BOOT ", __func__);
-                       debug("at addr  0x%p\n", (u32 *)handoff_address);
+       if (endian_t == UNKNOWN_ENDIANNESS) {
+               /* Trying to check handoff data is big endian? */

arch/arm/mach-socfpga/wrap_handoff_soc64.c int socfpga_get_handoff_size(void *handoff_address, enum endianness endian) · line 92

Quoted 10 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +6 -0
+               endian_t = check_endianness(swab32(readl(handoff_address)));
+               if (endian_t == UNKNOWN_ENDIANNESS) {
+                       debug("%s: Cannot find HANDOFF MAGIC ", __func__);
+                       debug("at addr 0x%p\n", (u32 *)handoff_address);
                        return -EPERM;
                }
        }
 
+       temp = readl(handoff_address + SOC64_HANDOFF_OFFSET_DATA +
+                   (i * sizeof(u32)));

When this can't be done in the 'for' loop below?

Quoted 26 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +26 -0
+
+       if (endian_t == BIG_ENDIAN) {
+               debug("%s: Handoff addr = 0x%p ", __func__, (u32 *)handoff_address);
+               debug("Handoff table address = 0x%p ", table_x32);
+               debug("table length = 0x%x\n", table_len);
+               debug("%s: handoff data =\n{\n", __func__);
+               *table_x32 = swab32(temp);
+       } else if (endian_t == LITTLE_ENDIAN) {
+               debug(" {\n");
+               *table_x32 = temp;
+       }
+
+       debug(" No.%d Addr 0x%08x: ", i, *table_x32);
+
+       for (i = 1; i < table_len; i++) {
+               table_x32++;
+
+               temp = readl(handoff_address +
+                            SOC64_HANDOFF_OFFSET_DATA +
+                            (i * sizeof(u32)));
+
+               if (endian_t == BIG_ENDIAN)
+                       *table_x32 = swab32(temp);
+               else if (endian_t == LITTLE_ENDIAN)
+                       *table_x32 = temp;
+

arch/arm/mach-socfpga/wrap_handoff_soc64.c int socfpga_get_handoff_size(void *handoff_address, enum endianness endian) · line 128

Quoted 10 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +8 -0
+               if (!(i % 2))
+                       debug(" No.%d Addr 0x%08x: ", i,
+                             *table_x32);
+               else
+                       debug(" 0x%08x\n", *table_x32);
+       }
+       debug("\n}\n");
+
        return 0;
 }

Regards
Ley Foon

#7 lore raw

RE: [v2 04/17] arm: socfpga: Add handoff data support for Intel N5X device

Hi Ley Foon,

Quoted 57 lines

-----Original Message-----
From: Ley Foon Tan <[email protected]>
Sent: Friday, 14 May, 2021 5:13 PM
To: Lim, Elly Siew Chin <[email protected]>
Cc: ZY - u-boot <[email protected]>; Marek Vasut <[email protected]>; Tan, Ley Foon <[email protected]>; See, Chin Liang <[email protected]>; Simon Goldschmidt <[email protected]>; Chee, Tien Fong <[email protected]>; Westergreen, Dalon <[email protected]>; Simon Glass <[email protected]>; Gan, Yau Wai <[email protected]>
Subject: Re: [v2 04/17] arm: socfpga: Add handoff data support for Intel N5X device

Quoted 8 lines · Siew Chin Lim

N5X support both HPS handoff data and DDR handoff data. Existing HPS handoff functions are restructured to support both existing devices and N5X device.

Quoted 8 lines

---
v2:
- Enabled auto detect the endianness from the magic word
- Merged and simplifying the big and little endian flow

---
 .../mach-socfpga/include/mach/handoff_soc64.h |  38 +++++-
arch/arm/mach-socfpga/system_manager_soc64.c  |  18 +--
 arch/arm/mach-socfpga/wrap_handoff_soc64.c    | 126 +++++++++++++--

---

Quoted 1 line
 3 files changed, 136 insertions(+), 46 deletions(-)

[...]

Quoted 20 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +13 -1
@@ -10,12 +10,54 @@
 #include <errno.h>
 #include "log.h"
 
-int socfpga_get_handoff_size(void *handoff_address, enum endianness
 endian)
+static enum endianness check_endianness(u32 handoff) {
+       switch (handoff) {
+       case SOC64_HANDOFF_MAGIC_BOOT:
+       case SOC64_HANDOFF_MAGIC_MUX:
+       case SOC64_HANDOFF_MAGIC_IOCTL:
+       case SOC64_HANDOFF_MAGIC_FPGA:
+       case SOC64_HANDOFF_MAGIC_DELAY:
+       case SOC64_HANDOFF_MAGIC_CLOCK:
+       case SOC64_HANDOFF_MAGIC_MISC:
+               return BIG_ENDIAN;
+#if IS_ENABLED(CONFIG_TARGET_SOCFPGA_N5X)
+       case SOC64_HANDOFF_DDR_UMCTL2_MAGIC:
+               debug("%s: umctl2 handoff data\n", __func__);
Quoted 8 lines

arch/arm/mach-socfpga/wrap_handoff_soc64.c line 33

Quoted 7 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +7 -0
+               return LITTLE_ENDIAN;
+       case SOC64_HANDOFF_DDR_PHY_MAGIC:
+               debug("%s: PHY handoff data\n", __func__);
+               return LITTLE_ENDIAN;
+       case SOC64_HANDOFF_DDR_PHY_INIT_ENGINE_MAGIC:
+               debug("%s: PHY engine handoff data\n", __func__);
+               return LITTLE_ENDIAN;

Can merge to one 'return' and print the 'handoff' if needed.

I can merge to one 'return' but has to compromise accuracy of DDR handoff type debug print out. So, I don’t see any benefit of doing these. Do you have any suggestion?

Quoted 39 lines
Quoted 23 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +20 -0
+#endif
+       default:
+               debug("%s: Unknown endianness!!\n", __func__);
+               return UNKNOWN_ENDIANNESS;
+       }
+}
+
+int socfpga_get_handoff_size(void *handoff_address)
 {
        u32 size;
+       enum endianness endian_t;
+
+       /* Checking handoff data is little endian ? */
+       endian_t = check_endianness(readl(handoff_address));
+
+       if (endian_t == UNKNOWN_ENDIANNESS) {
+               /* Trying to check handoff data is big endian? */
+               endian_t = check_endianness(swab32(readl(handoff_address)));
+               if (endian_t == UNKNOWN_ENDIANNESS) {
+                       debug("%s: Cannot find HANDOFF MAGIC ", __func__);
+                       debug("at addr 0x%p\n", (u32 *)handoff_address);
+                       return -EPERM;

arch/arm/mach-socfpga/wrap_handoff_soc64.c

Quoted 10 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +3 -2
+               }
+       }
 
        size = readl(handoff_address + SOC64_HANDOFF_OFFSET_LENGTH);
-       if (endian == BIG_ENDIAN)
+       if (endian_t == BIG_ENDIAN)
                size = swab32(size);
 
        size = (size - SOC64_HANDOFF_OFFSET_DATA) / sizeof(u32); @@
-26,41 +68,61 @@ int socfpga_get_handoff_size(void *handoff_address,

enum endianness endian)

Quoted 4 lines
        return size;

}

-int socfpga_handoff_read(void *handoff_address, void *table, u32

table_len,

Quoted 14 lines

arch/arm/mach-socfpga/wrap_handoff_soc64.c int socfpga_get_handoff_size(void *handoff_address, enum endianness endian) · line 79

Quoted 12 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +8 -2
-                        enum endianness big_endian)
+int socfpga_handoff_read(void *handoff_address, void *table, u32
+table_len)
 {
-       u32 temp, i;
+       u32 temp;
        u32 *table_x32 = table;
+       u32 i = 0;
+       enum endianness endian_t;
+
+       /* Checking handoff data is little endian ? */
+       endian_t = check_endianness(readl(handoff_address));

This code is similar in socfpga_get_handoff_size(). Can have a function to get the endianness.

Okay.

Quoted 42 lines
Quoted 3 lines

- debug("%s: handoff addr = 0x%p ", __func__, (u32

*)handoff_address);

arch/arm/mach-socfpga/wrap_handoff_soc64.c int socfpga_get_handoff_size(void *handoff_address, enum endianness endian)

Quoted 3 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +0 -3
-
-       if (big_endian) {
-               if (swab32(readl(SOC64_HANDOFF_BASE)) ==

SOC64_HANDOFF_MAGIC_BOOT) {

Quoted 11 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +0 -11
-                       debug("Handoff table address = 0x%p ", table_x32);
-                       debug("table length = 0x%x\n", table_len);
-                       debug("%s: handoff data =\n{\n", __func__);
-
-                       for (i = 0; i < table_len; i++) {
-                               temp = readl(handoff_address +
-                                            SOC64_HANDOFF_OFFSET_DATA +
-                                            (i * sizeof(u32)));
-                               *table_x32 = swab32(temp);
-
-                               if (!(i % 2))

arch/arm/mach-socfpga/wrap_handoff_soc64.c int socfpga_get_handoff_size(void *handoff_address, enum endianness endian)

Quoted 10 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +0 -10
-                                       debug(" No.%d Addr 0x%08x: ", i,
-                                             *table_x32);
-                               else
-                                       debug(" 0x%08x\n", *table_x32);
-
-                               table_x32++;
-                       }
-                       debug("\n}\n");
-               } else {
-                       debug("%s: Cannot find SOC64_HANDOFF_MAGIC_BOOT ",

__func__);

Quoted 12 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +7 -1
-                       debug("at addr  0x%p\n", (u32 *)handoff_address);
+       if (endian_t == UNKNOWN_ENDIANNESS) {
+               /* Trying to check handoff data is big endian? */
+               endian_t = check_endianness(swab32(readl(handoff_address)));
+               if (endian_t == UNKNOWN_ENDIANNESS) {
+                       debug("%s: Cannot find HANDOFF MAGIC ", __func__);
+                       debug("at addr 0x%p\n", (u32
+ *)handoff_address);
                        return -EPERM;
                }
        }
Quoted 3 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+       temp = readl(handoff_address + SOC64_HANDOFF_OFFSET_DATA +
+                   (i * sizeof(u32)));

When this can't be done in the 'for' loop below?

The first iteration is moved out from below loop for supporting correct debug message format and also to avoid reading the same thing twice.

Quoted 41 lines

arch/arm/mach-socfpga/wrap_handoff_soc64.c int socfpga_get_handoff_size(void *handoff_address, enum endianness endian)

Quoted 4 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +3 -0
+
+       if (endian_t == BIG_ENDIAN) {
+               debug("%s: Handoff addr = 0x%p ", __func__, (u32

*)handoff_address);

Quoted 23 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +23 -0
+               debug("Handoff table address = 0x%p ", table_x32);
+               debug("table length = 0x%x\n", table_len);
+               debug("%s: handoff data =\n{\n", __func__);
+               *table_x32 = swab32(temp);
+       } else if (endian_t == LITTLE_ENDIAN) {
+               debug(" {\n");
+               *table_x32 = temp;
+       }
+
+       debug(" No.%d Addr 0x%08x: ", i, *table_x32);
+
+       for (i = 1; i < table_len; i++) {
+               table_x32++;
+
+               temp = readl(handoff_address +
+                            SOC64_HANDOFF_OFFSET_DATA +
+                            (i * sizeof(u32)));
+
+               if (endian_t == BIG_ENDIAN)
+                       *table_x32 = swab32(temp);
+               else if (endian_t == LITTLE_ENDIAN)
+                       *table_x32 = temp;
+

arch/arm/mach-socfpga/wrap_handoff_soc64.c int socfpga_get_handoff_size(void *handoff_address, enum endianness endian) · line 128

Quoted 10 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c +8 -0
+               if (!(i % 2))
+                       debug(" No.%d Addr 0x%08x: ", i,
+                             *table_x32);
+               else
+                       debug(" 0x%08x\n", *table_x32);
+       }
+       debug("\n}\n");
+
        return 0;
 }

Regards
Ley Foon

#8 lore raw

Re: [v2 04/17] arm: socfpga: Add handoff data support for Intel N5X device

Hi,

Quoted 37 lines · Tien Fong

Hi Ley Foon,

Quoted 34 lines

-----Original Message-----
From: Ley Foon Tan <[email protected]>
Sent: Friday, 14 May, 2021 5:13 PM
To: Lim, Elly Siew Chin <[email protected]>
Cc: ZY - u-boot <[email protected]>; Marek Vasut <[email protected]>; Tan, Ley Foon <[email protected]>; See, Chin Liang <[email protected]>; Simon Goldschmidt <[email protected]>; Chee, Tien Fong <[email protected]>; Westergreen, Dalon <[email protected]>; Simon Glass <[email protected]>; Gan, Yau Wai <[email protected]>
Subject: Re: [v2 04/17] arm: socfpga: Add handoff data support for Intel N5X device

Quoted 8 lines · Siew Chin Lim

N5X support both HPS handoff data and DDR handoff data. Existing HPS handoff functions are restructured to support both existing devices and N5X device.

Quoted 8 lines

---
v2:
- Enabled auto detect the endianness from the magic word
- Merged and simplifying the big and little endian flow

---
 .../mach-socfpga/include/mach/handoff_soc64.h |  38 +++++-
arch/arm/mach-socfpga/system_manager_soc64.c  |  18 +--
 arch/arm/mach-socfpga/wrap_handoff_soc64.c    | 126 +++++++++++++--

---

Quoted 1 line
 3 files changed, 136 insertions(+), 46 deletions(-)

I'm not too clear on what is happening here, but have you looked at SPL_HANDOFF or BLOBLIST?

Regards,
Simon

#9 lore raw

RE: [v2 04/17] arm: socfpga: Add handoff data support for Intel N5X device

Hi Simon,

Quoted 53 lines

-----Original Message-----
From: Simon Glass <[email protected]>
Sent: Tuesday, 22 June, 2021 9:32 PM
To: Chee, Tien Fong <[email protected]>
Cc: Ley Foon Tan <[email protected]>; Lim, Elly Siew Chin <[email protected]>; ZY - u-boot <[email protected]>; Marek Vasut <[email protected]>; Tan, Ley Foon <[email protected]>; See, Chin Liang <[email protected]>; Simon Goldschmidt <[email protected]>; Westergreen, Dalon <[email protected]>; Gan, Yau Wai <[email protected]>
Subject: Re: [v2 04/17] arm: socfpga: Add handoff data support for Intel N5X device

Hi,

Quoted 36 lines · Tien Fong

Hi Ley Foon,

Quoted 33 lines

-----Original Message-----
From: Ley Foon Tan <[email protected]>
Sent: Friday, 14 May, 2021 5:13 PM
To: Lim, Elly Siew Chin <[email protected]>
Cc: ZY - u-boot <[email protected]>; Marek Vasut <[email protected]>; Tan, Ley Foon <[email protected]>; See, Chin Liang <[email protected]>; Simon Goldschmidt <[email protected]>; Chee, Tien Fong <[email protected]>; Westergreen, Dalon <[email protected]>; Simon Glass <[email protected]>; Gan, Yau Wai <[email protected]>
Subject: Re: [v2 04/17] arm: socfpga: Add handoff data support for Intel N5X device

Quoted 16 lines · Siew Chin Lim

N5X support both HPS handoff data and DDR handoff data. Existing HPS handoff functions are restructured to support both existing devices and N5X device.

---
v2:
- Enabled auto detect the endianness from the magic word
- Merged and simplifying the big and little endian flow

---
 .../mach-socfpga/include/mach/handoff_soc64.h |  38 +++++-
arch/arm/mach-socfpga/system_manager_soc64.c  |  18 +--
 arch/arm/mach-socfpga/wrap_handoff_soc64.c    | 126 +++++++++++++--
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

---

Quoted 1 line
 3 files changed, 136 insertions(+), 46 deletions(-)

I'm not too clear on what is happening here, but have you looked at SPL_HANDOFF or BLOBLIST?

Yeah, but these are not for our use case here. Our handoff are generated from the tool, which having user settings. Our secure device manager will pass these handoff to SPL, this driver is mainly for parsing our handoff format to consistent format in the table, which will be consumed and checking other drivers.

Quoted 3 lines

Regards,
Simon

Regards,
Tien Fong

#10 lore raw

PATCH v2 5/17 drivers: clk: Add clock driver for Intel N5X device

In reply to Siew Chin Lim

Add clock manager driver for N5X. Provides clock initialization and get_rate functions.

---
v2:
- common.h need to be included before clock_manager.h
- Remove unnecessary comment : write 1 to clear
- Remove unnecessary () in the code

---
 drivers/clk/altera/Makefile           |   3 +-
 drivers/clk/altera/clk-n5x.c          | 489 ++++++++++++++++++++++++++
 drivers/clk/altera/clk-n5x.h          | 217 ++++++++++++
 include/dt-bindings/clock/n5x-clock.h |  71 ++++
 4 files changed, 779 insertions(+), 1 deletion(-)
 create mode 100644 drivers/clk/altera/clk-n5x.c
 create mode 100644 drivers/clk/altera/clk-n5x.h
 create mode 100644 include/dt-bindings/clock/n5x-clock.h
drivers/clk/altera/Makefile +2 -1
index 96215ad5c4..38cd730685 100644
@@ -1,7 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0+
 #
-# Copyright (C) 2018 Marek Vasut <[email protected]>
+# Copyright (C) 2018-2021 Marek Vasut <[email protected]>
 #
 
 obj-$(CONFIG_TARGET_SOCFPGA_AGILEX) += clk-agilex.o
 obj-$(CONFIG_TARGET_SOCFPGA_ARRIA10) += clk-arria10.o
+obj-$(CONFIG_TARGET_SOCFPGA_N5X) += clk-n5x.o
drivers/clk/altera/clk-n5x.c new file +489 -0

489 lines not on this page · raw message

drivers/clk/altera/clk-n5x.h new file +217 -0

217 lines not on this page · raw message

include/dt-bindings/clock/n5x-clock.h new file +71 -0

71 lines not on this page · raw message

Signature · 1 line
2.19.0
#11 lore raw

Re: [v2 05/17] drivers: clk: Add clock driver for Intel N5X device

Quoted 11 lines · Siew Chin Lim

Add clock manager driver for N5X. Provides clock initialization and get_rate functions.

---
v2:
- common.h need to be included before clock_manager.h
- Remove unnecessary comment : write 1 to clear
- Remove unnecessary () in the code

Quoted 10 lines
---
 drivers/clk/altera/Makefile           |   3 +-
 drivers/clk/altera/clk-n5x.c          | 489 ++++++++++++++++++++++++++
 drivers/clk/altera/clk-n5x.h          | 217 ++++++++++++
 include/dt-bindings/clock/n5x-clock.h |  71 ++++
 4 files changed, 779 insertions(+), 1 deletion(-)
 create mode 100644 drivers/clk/altera/clk-n5x.c
 create mode 100644 drivers/clk/altera/clk-n5x.h
 create mode 100644 include/dt-bindings/clock/n5x-clock.h

[...]

+

drivers/clk/altera/clk-n5x.h line 135

Quoted 4 lines
drivers/clk/altera/clk-n5x.h new file +4 -0
+#define CLKMGR_INTER_MAINPLLLOCKED_MASK                        0x00000001
+#define CLKMGR_INTER_PERPLLLOCKED_MASK                 0x00000002
+#define CLKMGR_INTER_MAINPLLLOST_MASK                  0x00000004
+#define CLKMGR_INTER_PERPLLLOST_MASK                   0x00000008

Use BIT() macro for these mask bits.

Regards
Ley Foon

#12 lore raw

PATCH v2 6/17 arm: socfpga: Get clock manager base address for Intel N5X device

In reply to Siew Chin Lim

Add N5X clock manager to socfpga_get_managers_addr function.

---
 arch/arm/mach-socfpga/misc.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mach-socfpga/misc.c +3 -0
index 64a7c9d652..9305bec38a 100644
@@ -254,6 +254,9 @@ void socfpga_get_managers_addr(void)
 #ifdef CONFIG_TARGET_SOCFPGA_AGILEX
 	ret = socfpga_get_base_addr("intel,agilex-clkmgr",
 				    &socfpga_clkmgr_base);
+#elif IS_ENABLED(CONFIG_TARGET_SOCFPGA_N5X)
+	ret = socfpga_get_base_addr("intel,n5x-clkmgr",
+				    &socfpga_clkmgr_base);
 #else
 	ret = socfpga_get_base_addr("altr,clk-mgr", &socfpga_clkmgr_base);
 #endif
Signature · 1 line
2.19.0
#13 lore raw

PATCH v2 7/17 drivers: clk: Add memory clock driver for Intel N5X device

In reply to Siew Chin Lim

Add memory clock manager driver for N5X. Provides memory clock initialization and enable functions.

---
v2:
- common.h need to be included before clock_manager.h
- For consistency, use small letter fo 0x0c and 0x1c in macros

---
 drivers/clk/altera/Makefile      |   1 +
 drivers/clk/altera/clk-mem-n5x.c | 136 +++++++++++++++++++++++++++++++
 drivers/clk/altera/clk-mem-n5x.h |  84 +++++++++++++++++++
 3 files changed, 221 insertions(+)
 create mode 100644 drivers/clk/altera/clk-mem-n5x.c
 create mode 100644 drivers/clk/altera/clk-mem-n5x.h
drivers/clk/altera/Makefile +1 -0
index 38cd730685..33db092918 100644
@@ -6,3 +6,4 @@
 obj-$(CONFIG_TARGET_SOCFPGA_AGILEX) += clk-agilex.o
 obj-$(CONFIG_TARGET_SOCFPGA_ARRIA10) += clk-arria10.o
 obj-$(CONFIG_TARGET_SOCFPGA_N5X) += clk-n5x.o
+obj-$(CONFIG_TARGET_SOCFPGA_N5X) += clk-mem-n5x.o
drivers/clk/altera/clk-mem-n5x.c new file +136 -0

136 lines not on this page · raw message

drivers/clk/altera/clk-mem-n5x.h new file +84 -0

84 lines not on this page · raw message

Signature · 1 line
2.19.0
#14 lore raw

Re: [v2 07/17] drivers: clk: Add memory clock driver for Intel N5X device

Quoted 10 lines · Siew Chin Lim

Add memory clock manager driver for N5X. Provides memory clock initialization and enable functions.

---
v2:
- common.h need to be included before clock_manager.h
- For consistency, use small letter fo 0x0c and 0x1c in macros

Quoted 8 lines
---
 drivers/clk/altera/Makefile      |   1 +
 drivers/clk/altera/clk-mem-n5x.c | 136 +++++++++++++++++++++++++++++++
 drivers/clk/altera/clk-mem-n5x.h |  84 +++++++++++++++++++
 3 files changed, 221 insertions(+)
 create mode 100644 drivers/clk/altera/clk-mem-n5x.c
 create mode 100644 drivers/clk/altera/clk-mem-n5x.h

[...]

+

Quoted 22 lines
drivers/clk/altera/clk-mem-n5x.h new file +22 -0
+/* Clock Manager registers */
+#define MEMCLKMGR_STAT                                 4
+#define MEMCLKMGR_INTRGEN                              8
+#define MEMCLKMGR_INTRMSK                              0x0c
+#define MEMCLKMGR_INTRCLR                              0x10
+#define MEMCLKMGR_INTRSTS                              0x14
+#define MEMCLKMGR_INTRSTK                              0x18
+#define MEMCLKMGR_INTRRAW                              0x1c
+
+/* Memory Clock Manager PPL group registers */
+#define MEMCLKMGR_MEMPLL_EN                            0x20
+#define MEMCLKMGR_MEMPLL_ENS                           0x24
+#define MEMCLKMGR_MEMPLL_ENR                           0x28
+#define MEMCLKMGR_MEMPLL_BYPASS                                0x2c
+#define MEMCLKMGR_MEMPLL_BYPASSS                       0x30
+#define MEMCLKMGR_MEMPLL_BYPASSR                       0x34
+#define MEMCLKMGR_MEMPLL_MEMDIV                                0x38
+#define MEMCLKMGR_MEMPLL_PLLGLOB                       0x3c
+#define MEMCLKMGR_MEMPLL_PLLCTRL                       0x40
+#define MEMCLKMGR_MEMPLL_PLLDIV                                0x44
+#define MEMCLKMGR_MEMPLL_PLLOUTDIV                     0x48
+#define MEMCLKMGR_MEMPLL_EXTCNTRST                     0x4c

drivers/clk/altera/clk-mem-n5x.h line 44

Quoted 10 lines
drivers/clk/altera/clk-mem-n5x.h new file +10 -0
+
+#define MEMCLKMGR_CTRL_BOOTMODE                                BIT(0)
+
+#define MEMCLKMGR_STAT_MEMPLL_LOCKED                   BIT(8)
+
+#define MEMCLKMGR_STAT_ALLPLL_LOCKED_MASK              \
+       (MEMCLKMGR_STAT_MEMPLL_LOCKED)
+
+#define MEMCLKMGR_INTER_MEMPLLLOCKED_MASK              0x00000001
+#define MEMCLKMGR_INTER_MEMPLLLOST_MASK                        0x00000004

Use BIT() macro.

drivers/clk/altera/clk-mem-n5x.h line 52

Quoted 8 lines
drivers/clk/altera/clk-mem-n5x.h new file +8 -0
+
+#define MEMCLKMGR_BYPASS_MEMPLL_ALL                    0x1
+
+#define MEMCLKMGR_MEMDIV_MPFEDIV_OFFSET                        0
+#define MEMCLKMGR_MEMDIV_APBDIV_OFFSET                 4
+#define MEMCLKMGR_MEMDIV_DFICTRLDIV_OFFSET             8
+#define MEMCLKMGR_MEMDIV_DFIDIV_OFFSET                 12
+#define MEMCLKMGR_MEMDIV_DFICTRLDIV_MASK               0x1

Use BIT() macro.

Quoted 1 line

+#define MEMCLKMGR_MEMDIV_DIVIDER_MASK 0x3

Use GENMASK().

Quoted 34 lines
drivers/clk/altera/clk-mem-n5x.h new file +31 -1
+
+#define MEMCLKMGR_PLLGLOB_PSRC_MASK                    GENMASK(17, 16)
+#define MEMCLKMGR_PLLGLOB_PSRC_OFFSET                  16
+#define MEMCLKMGR_PLLGLOB_LOSTLOCK_BYPASS_EN_MASK      BIT(28)
+#define MEMCLKMGR_PLLGLOB_CLR_LOSTLOCK_BYPASS_MASK     BIT(29)
+
+#define MEMCLKMGR_PSRC_EOSC1                           0
+#define MEMCLKMGR_PSRC_INTOSC                          1
+#define MEMCLKMGR_PSRC_F2S                             2
+
+#define MEMCLKMGR_PLLCTRL_BYPASS_MASK                  BIT(0)
+#define MEMCLKMGR_PLLCTRL_RST_N_MASK                   BIT(1)
+
+#define MEMCLKMGR_PLLDIV_DIVR_MASK                     GENMASK(5, 0)
+#define MEMCLKMGR_PLLDIV_DIVF_MASK                     GENMASK(16, 8)
+#define MEMCLKMGR_PLLDIV_DIVQ_MASK                     GENMASK(26, 24)
+#define MEMCLKMGR_PLLDIV_RANGE_MASK                    GENMASK(30, 28)
+
+#define MEMCLKMGR_PLLDIV_DIVR_OFFSET                   0
+#define MEMCLKMGR_PLLDIV_DIVF_OFFSET                   8
+#define MEMCLKMGR_PLLDIV_DIVQ_QDIV_OFFSET              24
+#define MEMCLKMGR_PLLDIV_RANGE_OFFSET                  28
+
+#define MEMCLKMGR_PLLOUTDIV_C0CNT_MASK                 GENMASK(4, 0)
+#define MEMCLKMGR_PLLOUTDIV_C0CNT_OFFSET               0
+
+#define MEMCLKMGR_EXTCNTRST_C0CNTRST                   BIT(7)
+#define MEMCLKMGR_EXTCNTRST_ALLCNTRST                  \
+       (MEMCLKMGR_EXTCNTRST_C0CNTRST)
+
+#endif /* _CLK_MEM_N5X_ */
--

2.19.0

#15 lore raw

PATCH v2 8/17 arm: socfpga: Move cm_get_mpu_clk_hz function declaration to clock_manager.h

In reply to Siew Chin Lim

Move cm_get_mpu_clk_hz function declaration from individual device's clock manager header file to common clock_manager.h.

---
 arch/arm/mach-socfpga/include/mach/clock_manager.h         | 1 +
 arch/arm/mach-socfpga/include/mach/clock_manager_agilex.h  | 2 --
 arch/arm/mach-socfpga/include/mach/clock_manager_arria10.h | 1 -
 arch/arm/mach-socfpga/include/mach/clock_manager_gen5.h    | 1 -
 arch/arm/mach-socfpga/include/mach/clock_manager_s10.h     | 1 -
 5 files changed, 1 insertion(+), 5 deletions(-)
arch/arm/mach-socfpga/include/mach/clock_manager.h +1 -0
index 2f9b471af3..d0b172a30e 100644
@@ -12,6 +12,7 @@ phys_addr_t socfpga_get_clkmgr_addr(void);
 void cm_wait_for_lock(u32 mask);
 int cm_wait_for_fsm(void);
 void cm_print_clock_quick_summary(void);
+unsigned long cm_get_mpu_clk_hz(void);
 unsigned int cm_get_qspi_controller_clk_hz(void);
 
 #if defined(CONFIG_TARGET_SOCFPGA_SOC64)
arch/arm/mach-socfpga/include/mach/clock_manager_agilex.h +0 -2
index 386e82a4e3..4feae3dda9 100644
@@ -6,8 +6,6 @@
 #ifndef _CLOCK_MANAGER_AGILEX_
 #define _CLOCK_MANAGER_AGILEX_
 
-unsigned long cm_get_mpu_clk_hz(void);
-
 #include <asm/arch/clock_manager_soc64.h>
 #include "../../../../../drivers/clk/altera/clk-agilex.h"
 
arch/arm/mach-socfpga/include/mach/clock_manager_arria10.h +0 -1
index 798d3741bd..553ebe660d 100644
@@ -68,7 +68,6 @@ int cm_basic_init(const void *blob);
 
 #include <linux/bitops.h>
 unsigned int cm_get_l4_sp_clk_hz(void);
-unsigned long cm_get_mpu_clk_hz(void);
 
 #endif /* __ASSEMBLY__ */
 
arch/arm/mach-socfpga/include/mach/clock_manager_gen5.h +0 -1
index 4cc1268b4c..d53095a7da 100644
@@ -96,7 +96,6 @@ struct cm_config {
 #define CLKMGR_PERPLL_EN			CLKMGR_GEN5_PERPLL_EN
 
 /* Clock speed accessors */
-unsigned long cm_get_mpu_clk_hz(void);
 unsigned long cm_get_sdram_clk_hz(void);
 unsigned int cm_get_l4_sp_clk_hz(void);
 unsigned int cm_get_mmc_controller_clk_hz(void);
arch/arm/mach-socfpga/include/mach/clock_manager_s10.h +0 -1
index 98c3bf1b03..7f10296dc7 100644
@@ -11,7 +11,6 @@
 #include <linux/bitops.h>
 
 /* Clock speed accessors */
-unsigned long cm_get_mpu_clk_hz(void);
 unsigned long cm_get_sdram_clk_hz(void);
 unsigned int cm_get_l4_sp_clk_hz(void);
 unsigned int cm_get_mmc_controller_clk_hz(void);
Signature · 1 line
2.19.0
#16 lore raw

PATCH v2 9/17 arm: socfpga: Add clock manager for Intel N5X device

In reply to Siew Chin Lim

Add clock manager for N5X.

---
 ...k_manager_agilex.c => clock_manager_n5x.c} | 32 +++++++++----------
 .../mach-socfpga/include/mach/clock_manager.h |  2 ++
 .../include/mach/clock_manager_n5x.h          | 12 +++++++
 3 files changed, 29 insertions(+), 17 deletions(-)
 copy arch/arm/mach-socfpga/{clock_manager_agilex.c => clock_manager_n5x.c} (64%)
 create mode 100644 arch/arm/mach-socfpga/include/mach/clock_manager_n5x.h
arch/arm/mach-socfpga/clock_manager_n5x.c renamed from arch/arm/mach-socfpga/clock_manager_agilex.c +15 -17
similarity index 64%
copy from arch/arm/mach-socfpga/clock_manager_agilex.c
copy to arch/arm/mach-socfpga/clock_manager_n5x.c
index e035c09aae..4f098533e7 100644
@@ -1,19 +1,18 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (C) 2019 Intel Corporation <www.intel.com>
+ * Copyright (C) 2020-2021 Intel Corporation <www.intel.com>
  *
  */
 
-#include <clk.h>
 #include <common.h>
-#include <dm.h>
-#include <log.h>
-#include <malloc.h>
 #include <asm/arch/clock_manager.h>
 #include <asm/arch/system_manager.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
-#include <dt-bindings/clock/agilex-clock.h>
+#include <clk.h>
+#include <dm.h>
+#include <dt-bindings/clock/n5x-clock.h>
+#include <malloc.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -25,7 +24,7 @@ static ulong cm_get_rate_dm(u32 id)
 	int ret;
 
 	ret = uclass_get_device_by_driver(UCLASS_CLK,
-					  DM_DRIVER_GET(socfpga_agilex_clk),
+					  DM_DRIVER_GET(socfpga_n5x_clk),
 					  &dev);
 	if (ret)
 		return 0;
@@ -39,8 +38,7 @@ static ulong cm_get_rate_dm(u32 id)
 
 	clk_free(&clk);
 
-	if ((rate == (unsigned long)-ENOSYS) ||
-	    (rate == (unsigned long)-ENXIO) ||
+	if ((rate == (unsigned long)-ENXIO) ||
 	    (rate == (unsigned long)-EIO)) {
 		debug("%s id %u: clk_get_rate err: %ld\n",
 		      __func__, id, rate);
@@ -57,26 +55,26 @@ static u32 cm_get_rate_dm_khz(u32 id)
 
 unsigned long cm_get_mpu_clk_hz(void)
 {
-	return cm_get_rate_dm(AGILEX_MPU_CLK);
+	return cm_get_rate_dm(N5X_MPU_CLK);
 }
 
 unsigned int cm_get_l4_sys_free_clk_hz(void)
 {
-	return cm_get_rate_dm(AGILEX_L4_SYS_FREE_CLK);
+	return cm_get_rate_dm(N5X_L4_SYS_FREE_CLK);
 }
 
 void cm_print_clock_quick_summary(void)
 {
 	printf("MPU       %10d kHz\n",
-	       cm_get_rate_dm_khz(AGILEX_MPU_CLK));
+	       cm_get_rate_dm_khz(N5X_MPU_CLK));
 	printf("L4 Main	    %8d kHz\n",
-	       cm_get_rate_dm_khz(AGILEX_L4_MAIN_CLK));
+	       cm_get_rate_dm_khz(N5X_L4_MAIN_CLK));
 	printf("L4 sys free %8d kHz\n",
-	       cm_get_rate_dm_khz(AGILEX_L4_SYS_FREE_CLK));
+	       cm_get_rate_dm_khz(N5X_L4_SYS_FREE_CLK));
 	printf("L4 MP       %8d kHz\n",
-	       cm_get_rate_dm_khz(AGILEX_L4_MP_CLK));
+	       cm_get_rate_dm_khz(N5X_L4_MP_CLK));
 	printf("L4 SP       %8d kHz\n",
-	       cm_get_rate_dm_khz(AGILEX_L4_SP_CLK));
+	       cm_get_rate_dm_khz(N5X_L4_SP_CLK));
 	printf("SDMMC       %8d kHz\n",
-	       cm_get_rate_dm_khz(AGILEX_SDMMC_CLK));
+	       cm_get_rate_dm_khz(N5X_SDMMC_CLK));
 }
arch/arm/mach-socfpga/include/mach/clock_manager.h +2 -0
index d0b172a30e..a8cb07a1c4 100644
@@ -28,6 +28,8 @@ int cm_set_qspi_controller_clk_hz(u32 clk_hz);
 #include <asm/arch/clock_manager_s10.h>
 #elif defined(CONFIG_TARGET_SOCFPGA_AGILEX)
 #include <asm/arch/clock_manager_agilex.h>
+#elif IS_ENABLED(CONFIG_TARGET_SOCFPGA_N5X)
+#include <asm/arch/clock_manager_n5x.h>
 #endif
 
 #endif /* _CLOCK_MANAGER_H_ */
arch/arm/mach-socfpga/include/mach/clock_manager_n5x.h new file +12 -0
new file mode 100644
index 0000000000..54615ae8f7
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020-2021 Intel Corporation <www.intel.com>
+ */
+
+#ifndef _CLOCK_MANAGER_N5X_
+#define _CLOCK_MANAGER_N5X_
+
+#include <asm/arch/clock_manager_soc64.h>
+#include "../../../../../drivers/clk/altera/clk-n5x.h"
+
+#endif /* _CLOCK_MANAGER_N5X_ */
Signature · 1 line
2.19.0
#17 lore raw

PATCH v2 10/17 arm: socfpga: Changed misc_s10.c to misc_soc64.c

In reply to Siew Chin Lim

Rename to common file name to used by all SOC64 devices. No functionality change.

---
 arch/arm/mach-socfpga/Makefile                     |  4 ++--
 arch/arm/mach-socfpga/{misc_s10.c => misc_soc64.c} | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)
 rename arch/arm/mach-socfpga/{misc_s10.c => misc_soc64.c} (100%)
arch/arm/mach-socfpga/Makefile +2 -2
index 5779c55621..58afde950f 100644
@@ -32,7 +32,7 @@ ifdef CONFIG_TARGET_SOCFPGA_STRATIX10
 obj-y	+= clock_manager_s10.o
 obj-y	+= lowlevel_init_soc64.o
 obj-y	+= mailbox_s10.o
-obj-y	+= misc_s10.o
+obj-y	+= misc_soc64.o
 obj-y	+= mmu-arm64_s10.o
 obj-y	+= reset_manager_s10.o
 obj-y	+= system_manager_soc64.o
@@ -45,7 +45,7 @@ ifdef CONFIG_TARGET_SOCFPGA_AGILEX
 obj-y	+= clock_manager_agilex.o
 obj-y	+= lowlevel_init_soc64.o
 obj-y	+= mailbox_s10.o
-obj-y	+= misc_s10.o
+obj-y	+= misc_soc64.o
 obj-y	+= mmu-arm64_s10.o
 obj-y	+= reset_manager_s10.o
 obj-$(CONFIG_SOCFPGA_SECURE_VAB_AUTH)	+= secure_vab.o
arch/arm/mach-socfpga/misc_soc64.c renamed from arch/arm/mach-socfpga/misc_s10.c +6 -6
similarity index 100%
rename from arch/arm/mach-socfpga/misc_s10.c
rename to arch/arm/mach-socfpga/misc_soc64.c
index 50c7f19ae1..7b973a79e8 100644
@@ -6,16 +6,16 @@
 
 #include <altera.h>
 #include <common.h>
-#include <env.h>
-#include <errno.h>
-#include <init.h>
-#include <log.h>
-#include <asm/global_data.h>
-#include <asm/io.h>
 #include <asm/arch/mailbox_s10.h>
 #include <asm/arch/misc.h>
 #include <asm/arch/reset_manager.h>
 #include <asm/arch/system_manager.h>
+#include <asm/io.h>
+#include <asm/global_data.h>
+#include <env.h>
+#include <errno.h>
+#include <init.h>
+#include <log.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
Signature · 1 line
2.19.0
#18 lore raw

PATCH v2 11/17 ddr: socfpga: Enable memory test on memory size less than 1GB

In reply to Siew Chin Lim

From: Tien Fong Chee <[email protected]>

Minimum 1GB memory size is required in current memory test, so this patch improves the memory test for processing memory size less than 1GB, and the size in power of two.

---
v2:
- Renamed local variable ?total_size? to ?remaining_size?

---
 drivers/ddr/altera/sdram_soc64.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
drivers/ddr/altera/sdram_soc64.c +21 -3
index a08f0953e5..cc656db97c 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (C) 2016-2019 Intel Corporation <www.intel.com>
+ * Copyright (C) 2016-2021 Intel Corporation <www.intel.com>
  *
  */
 
@@ -182,6 +182,7 @@ void sdram_size_check(struct bd_info *bd)
 	phys_size_t total_ram_check = 0;
 	phys_size_t ram_check = 0;
 	phys_addr_t start = 0;
+	phys_size_t size, remaining_size;
 	int bank;
 
 	/* Sanity check ensure correct SDRAM size specified */
@@ -189,10 +190,27 @@ void sdram_size_check(struct bd_info *bd)
 
 	for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
 		start = bd->bi_dram[bank].start;
+		remaining_size = bd->bi_dram[bank].size;
 		while (ram_check < bd->bi_dram[bank].size) {
-			ram_check += get_ram_size((void *)(start + ram_check),
-						 (phys_size_t)SZ_1G);
+			size = min((phys_addr_t)SZ_1G,
+				   (phys_addr_t)remaining_size);
+
+			/*
+			 * Ensure the size is power of two, this is requirement
+			 * to run get_ram_size() / memory test
+			 */
+			if (size != 0 && ((size & (size - 1)) == 0)) {
+				ram_check += get_ram_size((void *)
+						(start + ram_check), size);
+				remaining_size = bd->bi_dram[bank].size -
+							ram_check;
+			} else {
+				puts("DDR: Memory test requires SDRAM size ");
+				puts("in power of two!\n");
+				hang();
+			}
 		}
+
 		total_ram_check += ram_check;
 		ram_check = 0;
 	}
Signature · 1 line
2.19.0
Reviewed-by on v2 11/17
#19 lore raw

Re: [v2 11/17] ddr: socfpga: Enable memory test on memory size less than 1GB

Quoted 67 lines · Siew Chin Lim

From: Tien Fong Chee <[email protected]>

Minimum 1GB memory size is required in current memory test, so this patch improves the memory test for processing memory size less than 1GB, and the size in power of two.

---
v2:
- Renamed local variable “total_size” to “remaining_size”

---
 drivers/ddr/altera/sdram_soc64.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
drivers/ddr/altera/sdram_soc64.c +21 -4
index a08f0953e5..cc656db97c 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (C) 2016-2019 Intel Corporation <www.intel.com>
+ * Copyright (C) 2016-2021 Intel Corporation <www.intel.com>
  *
  */
 
@@ -182,6 +182,7 @@ void sdram_size_check(struct bd_info *bd)
        phys_size_t total_ram_check = 0;
        phys_size_t ram_check = 0;
        phys_addr_t start = 0;
+       phys_size_t size, remaining_size;
        int bank;
 
        /* Sanity check ensure correct SDRAM size specified */
@@ -189,10 +190,27 @@ void sdram_size_check(struct bd_info *bd)
 
        for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
                start = bd->bi_dram[bank].start;
+               remaining_size = bd->bi_dram[bank].size;
                while (ram_check < bd->bi_dram[bank].size) {
-                       ram_check += get_ram_size((void *)(start + ram_check),
-                                                (phys_size_t)SZ_1G);
+                       size = min((phys_addr_t)SZ_1G,
+                                  (phys_addr_t)remaining_size);
+
+                       /*
+                        * Ensure the size is power of two, this is requirement
+                        * to run get_ram_size() / memory test
+                        */
+                       if (size != 0 && ((size & (size - 1)) == 0)) {
+                               ram_check += get_ram_size((void *)
+                                               (start + ram_check), size);
+                               remaining_size = bd->bi_dram[bank].size -
+                                                       ram_check;
+                       } else {
+                               puts("DDR: Memory test requires SDRAM size ");
+                               puts("in power of two!\n");
+                               hang();
+                       }
                }
+
                total_ram_check += ram_check;
                ram_check = 0;
        }
--
Quoted 2 lines

2.19.0

Regards
Ley Foon

#20 lore raw

PATCH v2 12/17 ddr: altera: Add SDRAM driver for Intel N5X device

In reply to Siew Chin Lim

The DDR subsystem in Diamond Mesa is consisted of controller, PHY, memory reset manager and memory clock manager.

Configuration settings of controller, PHY and memory reset manager is come from DDR handoff data in bitstream, which contain the register base addresses and user settings from tool.

Configuration settings of memory clock manager is come from the HPS handoff data in bitstream, however the register base address is defined in device tree.

The calibration is fully done in HPS, which requires IMEM and DMEM binaries loading to PHY SRAM for running this calibration, both IMEM and DMEM binaries are also part of bitstream, this bitstream would be loaded to OCRAM by SDM, and configured by DDR driver.

---
v2:
- Move is_ddr_init_skipped and its helper functions to DDR driver and converted function to positive checking
- Using GENMASK() macro
- Fixed typo
- Return status of subfunction
- Changed dm to n5x

---
 arch/arm/mach-socfpga/include/mach/firewall.h |    6 +
 .../include/mach/system_manager_soc64.h       |   10 +-
 drivers/ddr/altera/Makefile                   |    3 +-
 drivers/ddr/altera/sdram_n5x.c                | 2299 +++++++++++++++++
 drivers/ddr/altera/sdram_soc64.c              |   70 +
 drivers/ddr/altera/sdram_soc64.h              |    1 +
 6 files changed, 2387 insertions(+), 2 deletions(-)
 create mode 100644 drivers/ddr/altera/sdram_n5x.c
arch/arm/mach-socfpga/include/mach/firewall.h +6 -0
index adab65bc96..5cb7f23f8f 100644
@@ -115,10 +115,16 @@ struct socfpga_firwall_l4_sys {
 /* Firewall MPU DDR SCR registers */
 #define FW_MPU_DDR_SCR_EN				0x00
 #define FW_MPU_DDR_SCR_EN_SET				0x04
+#define FW_MPU_DDR_SCR_MPUREGION0ADDR_BASE		0x10
+#define FW_MPU_DDR_SCR_MPUREGION0ADDR_BASEEXT		0x14
 #define FW_MPU_DDR_SCR_MPUREGION0ADDR_LIMIT		0x18
 #define FW_MPU_DDR_SCR_MPUREGION0ADDR_LIMITEXT		0x1c
+
+#define FW_MPU_DDR_SCR_NONMPUREGION0ADDR_BASE		0x90
+#define FW_MPU_DDR_SCR_NONMPUREGION0ADDR_BASEEXT	0x94
 #define FW_MPU_DDR_SCR_NONMPUREGION0ADDR_LIMIT		0x98
 #define FW_MPU_DDR_SCR_NONMPUREGION0ADDR_LIMITEXT	0x9c
+#define FW_MPU_DDR_SCR_NONMPUREGION0ADDR_LIMITEXT_FIELD	0xff
 
 #define MPUREGION0_ENABLE				BIT(0)
 #define NONMPUREGION0_ENABLE				BIT(8)
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +9 -1
index fc4e17821b..a8009664fe 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 /*
- * Copyright (C) 2019 Intel Corporation <www.intel.com>
+ * Copyright (C) 2019-2021 Intel Corporation <www.intel.com>
  */
 
 #ifndef _SYSTEM_MANAGER_SOC64_H_
@@ -28,8 +28,12 @@ void populate_sysmgr_pinmux(void);
 #define SYSMGR_SOC64_FPGAINTF_EN2		0x6c
 #define SYSMGR_SOC64_FPGAINTF_EN3		0x70
 #define SYSMGR_SOC64_DMA_L3MASTER		0x74
+#if IS_ENABLED(CONFIG_TARGET_SOCFPGA_N5X)
+#define SYSMGR_SOC64_DDR_MODE			0xb8
+#else
 #define SYSMGR_SOC64_HMC_CLK			0xb4
 #define SYSMGR_SOC64_IO_PA_CTRL			0xb8
+#endif
 #define SYSMGR_SOC64_NOC_TIMEOUT		0xc0
 #define SYSMGR_SOC64_NOC_IDLEREQ_SET		0xc4
 #define SYSMGR_SOC64_NOC_IDLEREQ_CLR		0xc8
@@ -143,4 +147,8 @@ void populate_sysmgr_pinmux(void);
 
 #define SYSMGR_WDDBG_PAUSE_ALL_CPU	0x0F0F0F0F
 
+#if IS_ENABLED(CONFIG_TARGET_SOCFPGA_N5X)
+#define	SYSMGR_SOC64_DDR_MODE_MSK	BIT(0)
+#endif
+
 #endif /* _SYSTEM_MANAGER_SOC64_H_ */
drivers/ddr/altera/Makefile +2 -1
index 39dfee5d5a..9fa5d85a27 100644
@@ -4,11 +4,12 @@
 # Wolfgang Denk, DENX Software Engineering, wd at denx.de.
 #
 # (C) Copyright 2010, Thomas Chou <[email protected]>
-# Copyright (C) 2014 Altera Corporation <www.altera.com>
+# Copyright (C) 2014-2021 Altera Corporation <www.altera.com>
 
 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_soc64.o sdram_s10.o
 obj-$(CONFIG_TARGET_SOCFPGA_AGILEX) += sdram_soc64.o sdram_agilex.o
+obj-$(CONFIG_TARGET_SOCFPGA_N5X) += sdram_soc64.o sdram_n5x.o
 endif
drivers/ddr/altera/sdram_n5x.c new file +2299 -0

2,299 lines not on this page · raw message

drivers/ddr/altera/sdram_soc64.c +70 -0

99 lines not on this page · raw message

drivers/ddr/altera/sdram_soc64.h +1 -0
index 8af0afc410..7460f8c220 100644
@@ -180,6 +180,7 @@ int emif_reset(struct altera_sdram_plat *plat);
 int poll_hmc_clock_status(void);
 void sdram_clear_mem(phys_addr_t addr, phys_size_t size);
 void sdram_init_ecc_bits(struct bd_info *bd);
+void sdram_set_firewall(struct bd_info *bd);
 void sdram_size_check(struct bd_info *bd);
 phys_size_t sdram_calculate_size(struct altera_sdram_plat *plat);
 int sdram_mmr_init_full(struct udevice *dev);
Signature · 1 line
2.19.0
#21 lore raw

Re: [v2 12/17] ddr: altera: Add SDRAM driver for Intel N5X device

Quoted 38 lines · Siew Chin Lim

The DDR subsystem in Diamond Mesa is consisted of controller, PHY, memory reset manager and memory clock manager.

Configuration settings of controller, PHY and memory reset manager is come from DDR handoff data in bitstream, which contain the register base addresses and user settings from tool.

Configuration settings of memory clock manager is come from the HPS handoff data in bitstream, however the register base address is defined in device tree.

The calibration is fully done in HPS, which requires IMEM and DMEM binaries loading to PHY SRAM for running this calibration, both IMEM and DMEM binaries are also part of bitstream, this bitstream would be loaded to OCRAM by SDM, and configured by DDR driver.

---
v2:
- Move is_ddr_init_skipped and its helper functions to DDR driver and converted function to positive checking
- Using GENMASK() macro
- Fixed typo
- Return status of subfunction
- Changed dm to n5x

---
 arch/arm/mach-socfpga/include/mach/firewall.h |    6 +
 .../include/mach/system_manager_soc64.h       |   10 +-
 drivers/ddr/altera/Makefile                   |    3 +-
 drivers/ddr/altera/sdram_n5x.c                | 2299 +++++++++++++++++
 drivers/ddr/altera/sdram_soc64.c              |   70 +
 drivers/ddr/altera/sdram_soc64.h              |    1 +
 6 files changed, 2387 insertions(+), 2 deletions(-)
 create mode 100644 drivers/ddr/altera/sdram_n5x.c

[..]

drivers/ddr/altera/Makefile line 7

Quoted 10 lines
drivers/ddr/altera/Makefile +1 -1
index 39dfee5d5a..9fa5d85a27 100644
@@ -4,11 +4,12 @@
 # Wolfgang Denk, DENX Software Engineering, [email protected].
 #
 # (C) Copyright 2010, Thomas Chou <[email protected]>
-# Copyright (C) 2014 Altera Corporation <www.altera.com>
+# Copyright (C) 2014-2021 Altera Corporation <www.altera.com>

Intel copyright

[...]

drivers/ddr/altera/Makefile line 8

Quoted 1 line
drivers/ddr/altera/Makefile +1 -0
+#include <common.h>

Sort include header.

Quoted 274 lines
drivers/ddr/altera/Makefile +274 -0
+#include <asm/arch/firewall.h>
+#include <asm/arch/handoff_soc64.h>
+#include <asm/arch/misc.h>
+#include <asm/arch/reset_manager.h>
+#include <asm/arch/system_manager.h>
+#include <asm/global_data.h>
+#include <asm/io.h>
+#include <clk.h>
+#include <div64.h>
+#include <dm.h>
+#include <errno.h>
+#include <fdtdec.h>
+#include <hang.h>
+#include <linux/err.h>
+#include <linux/sizes.h>
+#include <ram.h>
+#include <reset.h>
+#include "sdram_soc64.h"
+#include <wait_bit.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* MPFE NOC registers */
+#define FPGA2SDRAM_MGR_MAIN_SIDEBANDMGR_FLAGOUTSET0    0xF8024050
+
+/* Memory reset manager */
+#define MEM_RST_MGR_STATUS     0x8
+
+/* Register and bit in memory reset manager */
+#define MEM_RST_MGR_STATUS_RESET_COMPLETE      BIT(0)
+#define MEM_RST_MGR_STATUS_PWROKIN_STATUS      BIT(1)
+#define MEM_RST_MGR_STATUS_CONTROLLER_RST      BIT(2)
+#define MEM_RST_MGR_STATUS_AXI_RST             BIT(3)
+
+#define TIMEOUT_200MS     200
+#define TIMEOUT_5000MS    5000
+
+/* DDR4 umctl2 */
+#define DDR4_MSTR_OFFSET               0x0
+#define DDR4_FREQ_RATIO                        BIT(22)
+
+#define DDR4_STAT_OFFSET               0x4
+#define DDR4_STAT_SELFREF_TYPE         GENMASK(5, 4)
+#define DDR4_STAT_SELFREF_TYPE_SHIFT   4
+#define DDR4_STAT_OPERATING_MODE       GENMASK(2, 0)
+
+#define DDR4_MRCTRL0_OFFSET            0x10
+#define DDR4_MRCTRL0_MR_TYPE           BIT(0)
+#define DDR4_MRCTRL0_MPR_EN            BIT(1)
+#define DDR4_MRCTRL0_MR_RANK           GENMASK(5, 4)
+#define DDR4_MRCTRL0_MR_RANK_SHIFT     4
+#define DDR4_MRCTRL0_MR_ADDR           GENMASK(15, 12)
+#define DDR4_MRCTRL0_MR_ADDR_SHIFT     12
+#define DDR4_MRCTRL0_MR_WR             BIT(31)
+
+#define DDR4_MRCTRL1_OFFSET            0x14
+#define DDR4_MRCTRL1_MR_DATA           0x3FFFF
+
+#define DDR4_MRSTAT_OFFSET             0x18
+#define DDR4_MRSTAT_MR_WR_BUSY         BIT(0)
+
+#define DDR4_MRCTRL2_OFFSET            0x1C
+
+#define DDR4_PWRCTL_OFFSET                     0x30
+#define DDR4_PWRCTL_SELFREF_EN                 BIT(0)
+#define DDR4_PWRCTL_POWERDOWN_EN               BIT(1)
+#define DDR4_PWRCTL_EN_DFI_DRAM_CLK_DISABLE    BIT(3)
+#define DDR4_PWRCTL_SELFREF_SW                 BIT(5)
+
+#define DDR4_PWRTMG_OFFSET             0x34
+#define DDR4_HWLPCTL_OFFSET            0x38
+#define DDR4_RFSHCTL0_OFFSET           0x50
+#define DDR4_RFSHCTL1_OFFSET           0x54
+
+#define DDR4_RFSHCTL3_OFFSET                   0x60
+#define DDR4_RFSHCTL3_DIS_AUTO_REFRESH         BIT(0)
+#define DDR4_RFSHCTL3_REFRESH_MODE             GENMASK(6, 4)
+#define DDR4_RFSHCTL3_REFRESH_MODE_SHIFT       4
+
+#define DDR4_ECCCFG0_OFFSET            0x70
+#define DDR4_ECC_MODE                  GENMASK(2, 0)
+#define DDR4_DIS_SCRUB                 BIT(4)
+#define LPDDR4_ECCCFG0_ECC_REGION_MAP_GRANU_SHIFT      30
+#define LPDDR4_ECCCFG0_ECC_REGION_MAP_SHIFT    8
+
+#define DDR4_ECCCFG1_OFFSET            0x74
+#define LPDDR4_ECCCFG1_ECC_REGIONS_PARITY_LOCK BIT(4)
+
+#define DDR4_CRCPARCTL0_OFFSET                 0xC0
+#define DDR4_CRCPARCTL0_DFI_ALERT_ERR_INIT_CLR BIT(1)
+
+#define DDR4_CRCPARCTL1_OFFSET                 0xC4
+#define DDR4_CRCPARCTL1_CRC_PARITY_RETRY_ENABLE        BIT(8)
+#define DDR4_CRCPARCTL1_ALERT_WAIT_FOR_SW      BIT(9)
+
+#define DDR4_CRCPARSTAT_OFFSET                 0xCC
+#define DDR4_CRCPARSTAT_DFI_ALERT_ERR_INT      BIT(16)
+#define DDR4_CRCPARSTAT_DFI_ALERT_ERR_FATL_INT BIT(17)
+#define DDR4_CRCPARSTAT_DFI_ALERT_ERR_NO_SW    BIT(19)
+#define DDR4_CRCPARSTAT_CMD_IN_ERR_WINDOW      BIT(29)
+
+#define DDR4_INIT0_OFFSET                      0xD0
+#define DDR4_INIT0_SKIP_RAM_INIT               GENMASK(31, 30)
+
+#define DDR4_RANKCTL_OFFSET                    0xF4
+#define DDR4_RANKCTL_DIFF_RANK_RD_GAP          GENMASK(7, 4)
+#define DDR4_RANKCTL_DIFF_RANK_WR_GAP          GENMASK(11, 8)
+#define DDR4_RANKCTL_DIFF_RANK_RD_GAP_MSB      BIT(24)
+#define DDR4_RANKCTL_DIFF_RANK_WR_GAP_MSB      BIT(26)
+#define DDR4_RANKCTL_DIFF_RANK_RD_GAP_SHIFT    4
+#define DDR4_RANKCTL_DIFF_RANK_WR_GAP_SHIFT    8
+#define DDR4_RANKCTL_DIFF_RANK_RD_GAP_MSB_SHIFT        24
+#define DDR4_RANKCTL_DIFF_RANK_WR_GAP_MSB_SHIFT        26
+
+#define DDR4_RANKCTL1_OFFSET   0xF8
+#define DDR4_RANKCTL1_WR2RD_DR GENMASK(5, 0)
+
+#define DDR4_DRAMTMG2_OFFSET   0x108
+#define DDR4_DRAMTMG2_WR2RD    GENMASK(5, 0)
+#define DDR4_DRAMTMG2_RD2WR    GENMASK(13, 8)
+#define DDR4_DRAMTMG2_RD2WR_SHIFT      8
+
+#define DDR4_DRAMTMG9_OFFSET   0x124
+#define DDR4_DRAMTMG9_W2RD_S   GENMASK(5, 0)
+
+#define DDR4_DFITMG1_OFFSET    0x194
+#define DDR4_DFITMG1_DFI_T_WRDATA_DELAY        GENMASK(20, 16)
+#define DDR4_DFITMG1_DFI_T_WRDATA_SHIFT        16
+
+#define DDR4_DFIMISC_OFFSET                    0x1B0
+#define DDR4_DFIMISC_DFI_INIT_COMPLETE_EN      BIT(0)
+#define DDR4_DFIMISC_DFI_INIT_START            BIT(5)
+
+#define DDR4_DFISTAT_OFFSET            0x1BC
+#define DDR4_DFI_INIT_COMPLETE         BIT(0)
+
+#define DDR4_DBG0_OFFSET               0x300
+
+#define DDR4_DBG1_OFFSET               0x304
+#define DDR4_DBG1_DISDQ                        BIT(0)
+#define DDR4_DBG1_DIS_HIF              BIT(1)
+
+#define DDR4_DBGCAM_OFFSET                     0x308
+#define DDR4_DBGCAM_DBG_RD_Q_EMPTY             BIT(25)
+#define DDR4_DBGCAM_DBG_WR_Q_EMPTY             BIT(26)
+#define DDR4_DBGCAM_RD_DATA_PIPELINE_EMPTY     BIT(28)
+#define DDR4_DBGCAM_WR_DATA_PIPELINE_EMPTY     BIT(29)
+
+#define DDR4_SWCTL_OFFSET              0x320
+#define DDR4_SWCTL_SW_DONE             BIT(0)
+
+#define DDR4_SWSTAT_OFFSET             0x324
+#define DDR4_SWSTAT_SW_DONE_ACK                BIT(0)
+
+#define DDR4_PSTAT_OFFSET              0x3FC
+#define DDR4_PSTAT_RD_PORT_BUSY_0      BIT(0)
+#define DDR4_PSTAT_WR_PORT_BUSY_0      BIT(16)
+
+#define DDR4_PCTRL0_OFFSET             0x490
+#define DDR4_PCTRL0_PORT_EN            BIT(0)
+
+#define DDR4_SBRCTL_OFFSET             0xF24
+#define DDR4_SBRCTL_SCRUB_INTERVAL     0x1FFF00
+#define DDR4_SBRCTL_SCRUB_EN           BIT(0)
+#define DDR4_SBRCTL_SCRUB_WRITE                BIT(2)
+#define DDR4_SBRCTL_SCRUB_BURST_1      BIT(4)
+
+#define DDR4_SBRSTAT_OFFSET            0xF28
+#define DDR4_SBRSTAT_SCRUB_BUSY BIT(0)
+#define DDR4_SBRSTAT_SCRUB_DONE BIT(1)
+
+#define DDR4_SBRWDATA0_OFFSET          0xF2C
+#define DDR4_SBRWDATA1_OFFSET          0xF30
+#define DDR4_SBRSTART0_OFFSET          0xF38
+#define DDR4_SBRSTART1_OFFSET          0xF3C
+#define DDR4_SBRRANGE0_OFFSET          0xF40
+#define DDR4_SBRRANGE1_OFFSET          0xF44
+
+/* DDR PHY */
+#define DDR_PHY_TXODTDRVSTREN_B0_P0            0x2009A
+#define DDR_PHY_RXPBDLYTG0_R0                  0x200D0
+#define DDR_PHY_DBYTE0_TXDQDLYTG0_U0_P0                0x201A0
+
+#define DDR_PHY_DBYTE0_TXDQDLYTG0_U1_P0                0x203A0
+#define DDR_PHY_DBYTE1_TXDQDLYTG0_U0_P0                0x221A0
+#define DDR_PHY_DBYTE1_TXDQDLYTG0_U1_P0                0x223A0
+#define DDR_PHY_TXDQDLYTG0_COARSE_DELAY                GENMASK(9, 6)
+#define DDR_PHY_TXDQDLYTG0_COARSE_DELAY_SHIFT  6
+
+#define DDR_PHY_CALRATE_OFFSET                 0x40110
+#define DDR_PHY_CALZAP_OFFSET                  0x40112
+#define DDR_PHY_SEQ0BDLY0_P0_OFFSET            0x40016
+#define DDR_PHY_SEQ0BDLY1_P0_OFFSET            0x40018
+#define DDR_PHY_SEQ0BDLY2_P0_OFFSET            0x4001A
+#define DDR_PHY_SEQ0BDLY3_P0_OFFSET            0x4001C
+
+#define DDR_PHY_MEMRESETL_OFFSET               0x400C0
+#define DDR_PHY_MEMRESETL_VALUE                        BIT(0)
+#define DDR_PHY_PROTECT_MEMRESET               BIT(1)
+
+#define DDR_PHY_CALBUSY_OFFSET                 0x4012E
+#define DDR_PHY_CALBUSY                                BIT(0)
+
+#define DDR_PHY_TRAIN_IMEM_OFFSET              0xA0000
+#define DDR_PHY_TRAIN_DMEM_OFFSET              0xA8000
+
+#define DMEM_MB_CDD_RR_1_0_OFFSET              0xA802C
+#define DMEM_MB_CDD_RR_0_1_OFFSET              0xA8030
+#define DMEM_MB_CDD_WW_1_0_OFFSET              0xA8038
+#define DMEM_MB_CDD_WW_0_1_OFFSET              0xA803C
+#define DMEM_MB_CDD_RW_1_1_OFFSET              0xA8046
+#define DMEM_MB_CDD_RW_1_0_OFFSET              0xA8048
+#define DMEM_MB_CDD_RW_0_1_OFFSET              0xA804A
+#define DMEM_MB_CDD_RW_0_0_OFFSET              0xA804C
+
+#define DMEM_MB_CDD_CHA_RR_1_0_OFFSET          0xA8026
+#define DMEM_MB_CDD_CHA_RR_0_1_OFFSET          0xA8026
+#define DMEM_MB_CDD_CHB_RR_1_0_OFFSET          0xA8058
+#define DMEM_MB_CDD_CHB_RR_0_1_OFFSET          0xA805A
+#define DMEM_MB_CDD_CHA_WW_1_0_OFFSET          0xA8030
+#define DMEM_MB_CDD_CHA_WW_0_1_OFFSET          0xA8030
+#define DMEM_MB_CDD_CHB_WW_1_0_OFFSET          0xA8062
+#define DMEM_MB_CDD_CHB_WW_0_1_OFFSET          0xA8064
+
+#define DMEM_MB_CDD_CHA_RW_1_1_OFFSET          0xA8028
+#define DMEM_MB_CDD_CHA_RW_1_0_OFFSET          0xA8028
+#define DMEM_MB_CDD_CHA_RW_0_1_OFFSET          0xA802A
+#define DMEM_MB_CDD_CHA_RW_0_0_OFFSET          0xA802A
+
+#define DMEM_MB_CDD_CHB_RW_1_1_OFFSET          0xA805A
+#define DMEM_MB_CDD_CHB_RW_1_0_OFFSET          0xA805C
+#define DMEM_MB_CDD_CHB_RW_0_1_OFFSET          0xA805c
+#define DMEM_MB_CDD_CHB_RW_0_0_OFFSET          0xA805E
+
+#define DDR_PHY_SEQ0DISABLEFLAG0_OFFSET                0x120018
+#define DDR_PHY_SEQ0DISABLEFLAG1_OFFSET                0x12001A
+#define DDR_PHY_SEQ0DISABLEFLAG2_OFFSET                0x12001C
+#define DDR_PHY_SEQ0DISABLEFLAG3_OFFSET                0x12001E
+#define DDR_PHY_SEQ0DISABLEFLAG4_OFFSET                0x120020
+#define DDR_PHY_SEQ0DISABLEFLAG5_OFFSET                0x120022
+#define DDR_PHY_SEQ0DISABLEFLAG6_OFFSET                0x120024
+#define DDR_PHY_SEQ0DISABLEFLAG7_OFFSET                0x120026
+
+#define DDR_PHY_UCCLKHCLKENABLES_OFFSET                0x180100
+#define DDR_PHY_UCCLKHCLKENABLES_UCCLKEN       BIT(0)
+#define DDR_PHY_UCCLKHCLKENABLES_HCLKEN                BIT(1)
+
+#define DDR_PHY_UCTWRITEPROT_OFFSET            0x180066
+#define DDR_PHY_UCTWRITEPROT                   BIT(0)
+
+#define DDR_PHY_APBONLY0_OFFSET                        0x1A0000
+#define DDR_PHY_MICROCONTMUXSEL                        BIT(0)
+
+#define DDR_PHY_UCTSHADOWREGS_OFFSET                   0x1A0008
+#define DDR_PHY_UCTSHADOWREGS_UCTWRITEPROTESHADOW      BIT(0)
+
+#define DDR_PHY_DCTWRITEPROT_OFFSET            0x1A0062
+#define DDR_PHY_DCTWRITEPROT                   BIT(0)
+
+#define DDR_PHY_UCTWRITEONLYSHADOW_OFFSET      0x1A0064
+#define DDR_PHY_UCTDATWRITEONLYSHADOW_OFFSET   0x1A0068
+
+#define DDR_PHY_MICRORESET_OFFSET              0x1A0132
+#define DDR_PHY_MICRORESET_STALL               BIT(0)
+#define DDR_PHY_MICRORESET_RESET               BIT(3)
+
+#define DDR_PHY_TXODTDRVSTREN_B0_P1            0x22009A
+
+/* For firmware training */
+#define HW_DBG_TRACE_CONTROL_OFFSET    0x18
+#define FW_TRAINING_COMPLETED_STAT     0x07
+#define FW_TRAINING_FAILED_STAT                0xFF
+#define FW_COMPLETION_MSG_ONLY_MODE    0xFF
+#define FW_STREAMING_MSG_ID            0x08

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+#define GET_LOWHW_DATA(x)              ((x) & 0xFFFF)
+#define GET_LOWB_DATA(x)               ((x) & 0xFF)
+#define GET_HIGHB_DATA(x)              (((x) & 0xFF00) >> 8)
+
+/* Operating mode */
+#define INIT_OPM                       0x000
+#define NORMAL_OPM                     0x001
+#define PWR_D0WN_OPM                   0x010
+#define SELF_SELFREF_OPM               0x011
+#define DDR4_DEEP_PWR_DOWN_OPM         0x100

Use prefix OPM_xxx

Quoted 171 lines
drivers/ddr/altera/Makefile +171 -0
+
+/* Refresh mode */
+#define FIXED_1X               0
+#define FIXED_2X               BIT(0)
+#define FIXED_4X               BIT(4)
+
+/* Address of mode register */
+#define MR0    0x0000
+#define MR1    0x0001
+#define MR2    0x0010
+#define MR3    0x0011
+#define MR4    0x0100
+#define MR5    0x0101
+#define MR6    0x0110
+#define MR7    0x0111
+
+/* MR rank */
+#define RANK0          0x1
+#define RANK1          0x2
+#define ALL_RANK       0x3
+
+#define MR5_BIT4       BIT(4)
+
+/* Value for ecc_region_map */
+#define ALL_PROTECTED  0x7F
+
+/* Region size for ECCCFG0.ecc_region_map */
+enum region_size {
+       ONE_EIGHT,
+       ONE_SIXTEENTH,
+       ONE_THIRTY_SECOND,
+       ONE_SIXTY_FOURTH
+};
+
+enum ddr_type {
+       DDRTYPE_LPDDR4_0,
+       DDRTYPE_LPDDR4_1,
+       DDRTYPE_DDR4,
+       DDRTYPE_UNKNOWN
+};
+
+/* Reset type */
+enum reset_type {
+       POR_RESET,
+       WARM_RESET,
+       COLD_RESET
+};
+
+/* DDR handoff structure */
+struct ddr_handoff {
+       /* Memory reset manager base */
+       phys_addr_t mem_reset_base;
+
+       /* First controller attributes */
+       phys_addr_t cntlr_handoff_base;
+       phys_addr_t cntlr_base;
+       size_t cntlr_total_length;
+       enum ddr_type cntlr_t;
+       size_t cntlr_handoff_length;
+
+       /* Second controller attributes*/
+       phys_addr_t cntlr2_handoff_base;
+       phys_addr_t cntlr2_base;
+       size_t cntlr2_total_length;
+       enum ddr_type cntlr2_t;
+       size_t cntlr2_handoff_length;
+
+       /* PHY attributes */
+       phys_addr_t phy_handoff_base;
+       phys_addr_t phy_base;
+       size_t phy_total_length;
+       size_t phy_handoff_length;
+
+       /* PHY engine attributes */
+       phys_addr_t phy_engine_handoff_base;
+       size_t phy_engine_total_length;
+       size_t phy_engine_handoff_length;
+
+       /* Calibration attributes */
+       phys_addr_t train_imem_base;
+       phys_addr_t train_dmem_base;
+       size_t train_imem_length;
+       size_t train_dmem_length;
+};
+
+/* Message mode */
+enum message_mode {
+       MAJOR_MESSAGE,
+       STREAMING_MESSAGE
+};
+
+static int clr_ca_parity_error_status(phys_addr_t umctl2_base)
+{
+       int ret;
+
+       debug("%s: Clear C/A parity error status in MR5[4]\n", __func__);
+
+       /* Set mode register MRS */
+       clrbits_le32(umctl2_base + DDR4_MRCTRL0_OFFSET, DDR4_MRCTRL0_MPR_EN);
+
+       /* Set mode register to write operation */
+       setbits_le32(umctl2_base + DDR4_MRCTRL0_OFFSET, DDR4_MRCTRL0_MR_TYPE);
+
+       /* Set the address of mode rgister to 0x101(MR5) */
+       setbits_le32(umctl2_base + DDR4_MRCTRL0_OFFSET,
+                    (MR5 << DDR4_MRCTRL0_MR_ADDR_SHIFT) &
+                    DDR4_MRCTRL0_MR_ADDR);
+
+       /* Set MR rank to rank 1 */
+       setbits_le32(umctl2_base + DDR4_MRCTRL0_OFFSET,
+                    (RANK1 << DDR4_MRCTRL0_MR_RANK_SHIFT) &
+                    DDR4_MRCTRL0_MR_RANK);
+
+       /* Clear C/A parity error status in MR5[4] */
+       clrbits_le32(umctl2_base + DDR4_MRCTRL1_OFFSET, MR5_BIT4);
+
+       /* Trigger mode register read or write operation */
+       setbits_le32(umctl2_base + DDR4_MRCTRL0_OFFSET, DDR4_MRCTRL0_MR_WR);
+
+       /* Wait for retry done */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_MRSTAT_OFFSET), DDR4_MRSTAT_MR_WR_BUSY,
+                               false, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" no outstanding MR transaction\n");
+               return ret;
+       }
+
+       return 0;
+}
+
+static int ddr_retry_software_sequence(phys_addr_t umctl2_base)
+{
+       u32 value;
+       int ret;
+
+       /* Check software can perform MRS/MPR/PDA? */
+       value = readl(umctl2_base + DDR4_CRCPARSTAT_OFFSET) &
+                     DDR4_CRCPARSTAT_DFI_ALERT_ERR_NO_SW;
+
+       if (value) {
+               /* Clear interrupt bit for DFI alert error */
+               setbits_le32(umctl2_base + DDR4_CRCPARCTL0_OFFSET,
+                            DDR4_CRCPARCTL0_DFI_ALERT_ERR_INIT_CLR);
+       }
+
+       debug("%s: Software can perform MRS/MPR/PDA\n", __func__);
+
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_MRSTAT_OFFSET),
+                               DDR4_MRSTAT_MR_WR_BUSY,
+                               false, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" no outstanding MR transaction\n");
+               return ret;
+       }
+
+       ret = clr_ca_parity_error_status(umctl2_base);
+       if (ret)
+               return ret;
+
+       if (!value) {
+               /* Clear interrupt bit for DFI alert error */
+               setbits_le32(umctl2_base + DDR4_CRCPARCTL0_OFFSET,
+                            DDR4_CRCPARCTL0_DFI_ALERT_ERR_INIT_CLR);
+       }
+
+       return 0;
+}

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+
+static int ensure_retry_procedure_complete(phys_addr_t umctl2_base)
+{
+       u32 value;
+       u32 start = get_timer(0);
+       int ret;
+
+       /* Check parity/crc/error window is emptied ? */
+       value = readl(umctl2_base + DDR4_CRCPARSTAT_OFFSET) &
+                     DDR4_CRCPARSTAT_CMD_IN_ERR_WINDOW;

Can simplify the code with do...while loop.

Quoted 242 lines
drivers/ddr/altera/Makefile +242 -0
+
+       /* Polling until parity/crc/error window is emptied */
+       while (value) {
+               if (get_timer(start) > TIMEOUT_200MS) {
+                       debug("%s: Timeout while waiting for",
+                             __func__);
+                       debug(" parity/crc/error window empty\n");
+                       return -ETIMEDOUT;
+               }
+
+               /* Check software intervention is enabled? */
+               value = readl(umctl2_base + DDR4_CRCPARCTL1_OFFSET) &
+                             DDR4_CRCPARCTL1_ALERT_WAIT_FOR_SW;
+               if (value) {
+                       debug("%s: Software intervention is enabled\n",
+                             __func__);
+
+                       /* Check dfi alert error interrupt is set? */
+                       value = readl(umctl2_base + DDR4_CRCPARSTAT_OFFSET) &
+                                     DDR4_CRCPARSTAT_DFI_ALERT_ERR_INT;
+
+                       if (value) {
+                               ret = ddr_retry_software_sequence(umctl2_base);
+                               debug("%s: DFI alert error interrupt ",
+                                     __func__);
+                               debug("is set\n");
+
+                               if (ret)
+                                       return ret;
+                       }
+
+                       /*
+                        * Check fatal parity error interrupt is set?
+                        */
+                       value = readl(umctl2_base + DDR4_CRCPARSTAT_OFFSET) &
+                                     DDR4_CRCPARSTAT_DFI_ALERT_ERR_FATL_INT;
+                       if (value) {
+                               printf("%s: Fatal parity error  ",
+                                      __func__);
+                               printf("interrupt is set, Hang it!!\n");
+                               hang();
+                       }
+               }
+
+               value = readl(umctl2_base + DDR4_CRCPARSTAT_OFFSET) &
+                             DDR4_CRCPARSTAT_CMD_IN_ERR_WINDOW;
+
+               udelay(1);
+               WATCHDOG_RESET();
+       }
+
+       return 0;
+}
+
+static int enable_quasi_dynamic_reg_grp3(phys_addr_t umctl2_base,
+                                        enum ddr_type umctl2_type)
+{
+       u32 i, value, backup;
+       int ret = 0;
+
+       /* Disable input traffic per port */
+       clrbits_le32(umctl2_base + DDR4_PCTRL0_OFFSET, DDR4_PCTRL0_PORT_EN);
+
+       /* Polling AXI port until idle */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_PSTAT_OFFSET),
+                               DDR4_PSTAT_WR_PORT_BUSY_0 |
+                               DDR4_PSTAT_RD_PORT_BUSY_0, false,
+                               TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" controller idle\n");
+               return ret;
+       }
+
+       /* Backup user setting */
+       backup = readl(umctl2_base + DDR4_DBG1_OFFSET);
+
+       /* Disable input traffic to the controller */
+       setbits_le32(umctl2_base + DDR4_DBG1_OFFSET, DDR4_DBG1_DIS_HIF);
+
+       /*
+        * Ensure CAM/data pipelines are empty.
+        * Poll until CAM/data pipelines are set at least twice,
+        * timeout at 200ms
+        */
+       for (i = 0; i < 2; i++) {
+               ret = wait_for_bit_le32((const void *)(umctl2_base +
+                                       DDR4_DBGCAM_OFFSET),
+                                       DDR4_DBGCAM_WR_DATA_PIPELINE_EMPTY |
+                                       DDR4_DBGCAM_RD_DATA_PIPELINE_EMPTY |
+                                       DDR4_DBGCAM_DBG_WR_Q_EMPTY |
+                                       DDR4_DBGCAM_DBG_RD_Q_EMPTY, true,
+                                       TIMEOUT_200MS, false);
+               if (ret) {
+                       debug("%s: loop(%u): Timeout while waiting for",
+                             __func__, i + 1);
+                       debug(" CAM/data pipelines are empty\n");
+
+                       goto out;
+               }
+       }
+
+       if (umctl2_type == DDRTYPE_DDR4) {
+               /* Check DDR4 retry is enabled ? */
+               value = readl(umctl2_base + DDR4_CRCPARCTL1_OFFSET) &
+                             DDR4_CRCPARCTL1_CRC_PARITY_RETRY_ENABLE;
+
+               if (value) {
+                       debug("%s: DDR4 retry is enabled\n", __func__);
+
+                       ret = ensure_retry_procedure_complete(umctl2_base);
+                       if (ret) {
+                               debug("%s: Timeout while waiting for",
+                                     __func__);
+                               debug(" retry procedure complete\n");
+
+                               goto out;
+                       }
+               }
+       }
+
+       debug("%s: Quasi-dynamic group 3 registers are enabled\n", __func__);
+
+out:
+       /* Restore user setting */
+       writel(backup, umctl2_base + DDR4_DBG1_OFFSET);
+
+       return ret;
+}
+
+static enum ddr_type get_ddr_type(phys_addr_t ddr_type_location)
+{
+       u32 ddr_type_magic = readl(ddr_type_location);
+
+       if (ddr_type_magic == SOC64_HANDOFF_DDR_UMCTL2_DDR4_TYPE)
+               return DDRTYPE_DDR4;
+
+       if (ddr_type_magic == SOC64_HANDOFF_DDR_UMCTL2_LPDDR4_0_TYPE)
+               return DDRTYPE_LPDDR4_0;
+
+       if (ddr_type_magic == SOC64_HANDOFF_DDR_UMCTL2_LPDDR4_1_TYPE)
+               return DDRTYPE_LPDDR4_1;
+
+       return DDRTYPE_UNKNOWN;
+}
+
+static void use_lpddr4_interleaving(bool set)
+{
+       if (set) {
+               printf("Starting LPDDR4 interleaving configuration ...\n");
+               setbits_le32(FPGA2SDRAM_MGR_MAIN_SIDEBANDMGR_FLAGOUTSET0,
+                            BIT(5));
+       } else {
+               printf("Starting LPDDR4 non-interleaving configuration ...\n");
+               clrbits_le32(FPGA2SDRAM_MGR_MAIN_SIDEBANDMGR_FLAGOUTSET0,
+                            BIT(5));
+       }
+}
+
+static void use_ddr4(enum ddr_type type)
+{
+       if (type == DDRTYPE_DDR4) {
+               printf("Starting DDR4 configuration ...\n");
+               setbits_le32(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_DDR_MODE,
+                            SYSMGR_SOC64_DDR_MODE_MSK);
+       } else if (type == DDRTYPE_LPDDR4_0)  {
+               printf("Starting LPDDR4 configuration ...\n");
+               clrbits_le32(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_DDR_MODE,
+                            SYSMGR_SOC64_DDR_MODE_MSK);
+
+               use_lpddr4_interleaving(false);
+       }
+}
+
+static int scrubber_ddr_config(phys_addr_t umctl2_base,
+                              enum ddr_type umctl2_type)
+{
+       u32 backup[9];
+       int ret;
+
+       /* Reset to default value, prevent scrubber stop due to lower power */
+       writel(0, umctl2_base + DDR4_PWRCTL_OFFSET);
+
+       /* Backup user settings */
+       backup[0] = readl(umctl2_base + DDR4_SBRCTL_OFFSET);
+       backup[1] = readl(umctl2_base + DDR4_SBRWDATA0_OFFSET);
+       backup[2] = readl(umctl2_base + DDR4_SBRSTART0_OFFSET);
+       if (umctl2_type == DDRTYPE_DDR4) {
+               backup[3] = readl(umctl2_base + DDR4_SBRWDATA1_OFFSET);
+               backup[4] = readl(umctl2_base + DDR4_SBRSTART1_OFFSET);
+       }
+       backup[5] = readl(umctl2_base + DDR4_SBRRANGE0_OFFSET);
+       backup[6] = readl(umctl2_base + DDR4_SBRRANGE1_OFFSET);
+       backup[7] = readl(umctl2_base + DDR4_ECCCFG0_OFFSET);
+       backup[8] = readl(umctl2_base + DDR4_ECCCFG1_OFFSET);
+
+       if (umctl2_type != DDRTYPE_DDR4) {
+               /* Lock ECC region, ensure this regions is not being accessed */
+               setbits_le32(umctl2_base + DDR4_ECCCFG1_OFFSET,
+                            LPDDR4_ECCCFG1_ECC_REGIONS_PARITY_LOCK);
+       }
+       /* Disable input traffic per port */
+       clrbits_le32(umctl2_base + DDR4_PCTRL0_OFFSET, DDR4_PCTRL0_PORT_EN);
+       /* Disables scrubber */
+       clrbits_le32(umctl2_base + DDR4_SBRCTL_OFFSET, DDR4_SBRCTL_SCRUB_EN);
+       /* Polling all scrub writes data have been sent */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SBRSTAT_OFFSET), DDR4_SBRSTAT_SCRUB_BUSY,
+                               false, TIMEOUT_5000MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" sending all scrub data\n");
+               return ret;
+       }
+
+       /* LPDDR4 supports inline ECC only */
+       if (umctl2_type != DDRTYPE_DDR4) {
+               /*
+                * Setting all regions for protected, this is required for
+                * srubber to init whole LPDDR4 expect ECC region
+                */
+               writel(((ONE_EIGHT <<
+                      LPDDR4_ECCCFG0_ECC_REGION_MAP_GRANU_SHIFT) |
+                      (ALL_PROTECTED << LPDDR4_ECCCFG0_ECC_REGION_MAP_SHIFT)),
+                      umctl2_base + DDR4_ECCCFG0_OFFSET);
+       }
+
+       /* Scrub_burst = 1, scrub_mode = 1(performs writes) */
+       writel(DDR4_SBRCTL_SCRUB_BURST_1 | DDR4_SBRCTL_SCRUB_WRITE,
+              umctl2_base + DDR4_SBRCTL_OFFSET);
+
+       /* Zeroing whole DDR */
+       writel(0, umctl2_base + DDR4_SBRWDATA0_OFFSET);
+       writel(0, umctl2_base + DDR4_SBRSTART0_OFFSET);
+       if (umctl2_type == DDRTYPE_DDR4) {
+               writel(0, umctl2_base + DDR4_SBRWDATA1_OFFSET);
+               writel(0, umctl2_base + DDR4_SBRSTART1_OFFSET);
+       }
+       writel(0, umctl2_base + DDR4_SBRRANGE0_OFFSET);
+       writel(0, umctl2_base + DDR4_SBRRANGE1_OFFSET);
+

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+       /* Enables scrubber */
+       setbits_le32(umctl2_base + DDR4_SBRCTL_OFFSET, DDR4_SBRCTL_SCRUB_EN);
+       /* Polling all scrub writes commands have been sent */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SBRSTAT_OFFSET), DDR4_SBRSTAT_SCRUB_DONE,
+                               true, TIMEOUT_5000MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" sending all scrub commands\n");
+               return ret;

Need restore user settings before return?

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+       }
+
+       /* Polling all scrub writes data have been sent */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SBRSTAT_OFFSET), DDR4_SBRSTAT_SCRUB_BUSY,
+                               false, TIMEOUT_5000MS, false);
+       if (ret) {
+               printf("%s: Timeout while waiting for", __func__);
+               printf(" sending all scrub data\n");
+               return ret;

Same here.

Quoted 70 lines
drivers/ddr/altera/Makefile +70 -0
+       }
+
+       /* Disables scrubber */
+       clrbits_le32(umctl2_base + DDR4_SBRCTL_OFFSET, DDR4_SBRCTL_SCRUB_EN);
+
+       /* Restore user settings */
+       writel(backup[0], umctl2_base + DDR4_SBRCTL_OFFSET);
+       writel(backup[1], umctl2_base + DDR4_SBRWDATA0_OFFSET);
+       writel(backup[2], umctl2_base + DDR4_SBRSTART0_OFFSET);
+       if (umctl2_type == DDRTYPE_DDR4) {
+               writel(backup[3], umctl2_base + DDR4_SBRWDATA1_OFFSET);
+               writel(backup[4], umctl2_base + DDR4_SBRSTART1_OFFSET);
+       }
+       writel(backup[5], umctl2_base + DDR4_SBRRANGE0_OFFSET);
+       writel(backup[6], umctl2_base + DDR4_SBRRANGE1_OFFSET);
+       writel(backup[7], umctl2_base + DDR4_ECCCFG0_OFFSET);
+       writel(backup[8], umctl2_base + DDR4_ECCCFG1_OFFSET);
+
+       /* Enables ECC scrub on scrubber */
+       if (!(readl(umctl2_base + DDR4_SBRCTL_OFFSET) &
+           DDR4_SBRCTL_SCRUB_WRITE)) {
+               /* Enables scrubber */
+               setbits_le32(umctl2_base + DDR4_SBRCTL_OFFSET,
+                            DDR4_SBRCTL_SCRUB_EN);
+       }
+
+       return 0;
+}
+
+static int init_umctl2(phys_addr_t umctl2_handoff_base,
+                      phys_addr_t umctl2_base, enum ddr_type umctl2_type,
+                      size_t umctl2_handoff_length,
+                      u32 *user_backup)
+{
+       u32 handoff_table[umctl2_handoff_length];
+       u32 i;
+       int ret;
+
+       if (umctl2_type == DDRTYPE_DDR4)
+               printf("Initializing DDR4 controller ...\n");
+       else if (umctl2_type == DDRTYPE_LPDDR4_0)
+               printf("Initializing LPDDR4_0 controller ...\n");
+       else if (umctl2_type == DDRTYPE_LPDDR4_1)
+               printf("Initializing LPDDR4_1 controller ...\n");
+
+       /* Prevent controller from issuing read/write to SDRAM */
+       setbits_le32(umctl2_base + DDR4_DBG1_OFFSET, DDR4_DBG1_DISDQ);
+
+       /* Put SDRAM into self-refresh */
+       setbits_le32(umctl2_base + DDR4_PWRCTL_OFFSET, DDR4_PWRCTL_SELFREF_EN);
+
+       /* Enable quasi-dynamic programing of the controller registers */
+       clrbits_le32(umctl2_base + DDR4_SWCTL_OFFSET, DDR4_SWCTL_SW_DONE);
+
+       /* Ensure the controller is in initialization mode */
+       ret = wait_for_bit_le32((const void *)(umctl2_base + DDR4_STAT_OFFSET),
+                               DDR4_STAT_OPERATING_MODE, false, TIMEOUT_200MS,
+                               false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" init operating mode\n");
+               return ret;
+       }
+
+       debug("%s: UMCTL2 handoff base address = 0x%p table length = 0x%08x\n",
+             __func__, (u32 *)umctl2_handoff_base,
+             (u32)umctl2_handoff_length);
+
+       socfpga_handoff_read((void *)umctl2_handoff_base, handoff_table,
+                            umctl2_handoff_length);

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+
+       for (i = 0; i < umctl2_handoff_length; i = i + 2) {
+               debug("%s: Absolute addr: 0x%08llx APB offset: 0x%08x",
+                     __func__, handoff_table[i] + umctl2_base,
+                     handoff_table[i]);
+               debug(" wr = 0x%08x ", handoff_table[i + 1]);
+
+               writel(handoff_table[i + 1], (uintptr_t)(handoff_table[i] +
+                      umctl2_base));
+

Can have a common function to write the handoff data. Check all code after call to socfpga_handoff_read().

Quoted 543 lines
drivers/ddr/altera/Makefile +543 -0
+               debug("rd = 0x%08x\n", readl((uintptr_t)(handoff_table[i] +
+                     umctl2_base)));
+       }
+
+       /* Backup user settings, restore after DDR up running */
+       *user_backup = readl(umctl2_base + DDR4_PWRCTL_OFFSET);
+
+       /* Disable self resfresh */
+       clrbits_le32(umctl2_base + DDR4_PWRCTL_OFFSET, DDR4_PWRCTL_SELFREF_EN);
+
+       if (umctl2_type == DDRTYPE_LPDDR4_0 ||
+           umctl2_type == DDRTYPE_LPDDR4_1) {
+               /* Setting selfref_sw to 1, based on lpddr4 requirement */
+               setbits_le32(umctl2_base + DDR4_PWRCTL_OFFSET,
+                            DDR4_PWRCTL_SELFREF_SW);
+
+               /* Backup user settings, restore after DDR up running */
+               user_backup++;
+               *user_backup = readl(umctl2_base + DDR4_INIT0_OFFSET) &
+                                    DDR4_INIT0_SKIP_RAM_INIT;
+
+               /*
+                * Setting INIT0.skip_dram_init to 0x3, based on lpddr4
+                * requirement
+                */
+               setbits_le32(umctl2_base + DDR4_INIT0_OFFSET,
+                            DDR4_INIT0_SKIP_RAM_INIT);
+       }
+
+       /* Complete quasi-dynamic register programming */
+       setbits_le32(umctl2_base + DDR4_SWCTL_OFFSET, DDR4_SWCTL_SW_DONE);
+
+       /* Enable controller from issuing read/write to SDRAM */
+       clrbits_le32(umctl2_base + DDR4_DBG1_OFFSET, DDR4_DBG1_DISDQ);
+
+       return 0;
+}
+
+static int phy_pre_handoff_config(phys_addr_t umctl2_base,
+                                 enum ddr_type umctl2_type)
+{
+       int ret;
+       u32 value;
+
+       if (umctl2_type == DDRTYPE_DDR4) {
+               /* Check DDR4 retry is enabled ? */
+               value = readl(umctl2_base + DDR4_CRCPARCTL1_OFFSET) &
+                             DDR4_CRCPARCTL1_CRC_PARITY_RETRY_ENABLE;
+
+               if (value) {
+                       debug("%s: DDR4 retry is enabled\n", __func__);
+                       debug("%s: Disable auto refresh is not supported\n",
+                             __func__);
+               } else {
+                       /* Disable auto refresh */
+                       setbits_le32(umctl2_base + DDR4_RFSHCTL3_OFFSET,
+                                    DDR4_RFSHCTL3_DIS_AUTO_REFRESH);
+               }
+       }
+
+       /* Disable selfref_en & powerdown_en, nvr disable dfi dram clk */
+       clrbits_le32(umctl2_base + DDR4_PWRCTL_OFFSET,
+                    DDR4_PWRCTL_EN_DFI_DRAM_CLK_DISABLE |
+                    DDR4_PWRCTL_POWERDOWN_EN | DDR4_PWRCTL_SELFREF_EN);
+
+       /* Enable quasi-dynamic programing of the controller registers */
+       clrbits_le32(umctl2_base + DDR4_SWCTL_OFFSET, DDR4_SWCTL_SW_DONE);
+
+       ret = enable_quasi_dynamic_reg_grp3(umctl2_base, umctl2_type);
+       if (ret)
+               return ret;
+
+       /* Masking dfi init complete */
+       clrbits_le32(umctl2_base + DDR4_DFIMISC_OFFSET,
+                    DDR4_DFIMISC_DFI_INIT_COMPLETE_EN);
+
+       /* Complete quasi-dynamic register programming */
+       setbits_le32(umctl2_base + DDR4_SWCTL_OFFSET, DDR4_SWCTL_SW_DONE);
+
+       /* Polling programming done */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SWSTAT_OFFSET), DDR4_SWSTAT_SW_DONE_ACK,
+                               true, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" programming done\n");
+       }
+
+       return ret;
+}
+
+static int init_phy(struct ddr_handoff *ddr_handoff_info)
+{
+       u32 handoff_table[ddr_handoff_info->phy_handoff_length];
+       u32 i, value;
+       int ret;
+
+       printf("Initializing DDR PHY ...\n");
+
+       if (ddr_handoff_info->cntlr_t == DDRTYPE_DDR4 ||
+           ddr_handoff_info->cntlr_t == DDRTYPE_LPDDR4_0) {
+               ret = phy_pre_handoff_config(ddr_handoff_info->cntlr_base,
+                                            ddr_handoff_info->cntlr_t);
+               if (ret)
+                       return ret;
+       }
+
+       if (ddr_handoff_info->cntlr2_t == DDRTYPE_LPDDR4_1) {
+               ret = phy_pre_handoff_config
+                       (ddr_handoff_info->cntlr2_base,
+                        ddr_handoff_info->cntlr2_t);
+               if (ret)
+                       return ret;
+       }
+
+       /* Execute PHY configuration handoff */
+       socfpga_handoff_read((void *)ddr_handoff_info->phy_handoff_base,
+                            handoff_table,
+                            (u32)ddr_handoff_info->phy_handoff_length);
+
+       for (i = 0; i < ddr_handoff_info->phy_handoff_length; i = i + 2) {
+               /*
+                * Convert PHY odd offset to even offset that supported by
+                * ARM processor.
+                */
+               value = handoff_table[i] << 1;
+               debug("%s: Absolute addr: 0x%08llx, APB offset: 0x%08x ",
+                     __func__, value + ddr_handoff_info->phy_base, value);
+               debug("PHY offset: 0x%08x", handoff_table[i]);
+               debug(" wr = 0x%08x ", handoff_table[i + 1]);
+               writew(handoff_table[i + 1], (uintptr_t)(value +
+                      ddr_handoff_info->phy_base));
+               debug("rd = 0x%08x\n", readw((uintptr_t)(value +
+                     ddr_handoff_info->phy_base)));
+       }
+
+       printf("DDR PHY configuration is completed\n");
+
+       return 0;
+}
+
+static void phy_init_engine(struct ddr_handoff *handoff)
+{
+       u32 i, value;
+       u32 handoff_table[handoff->phy_engine_handoff_length];
+
+       printf("Load PHY Init Engine ...\n");
+
+       /* Execute PIE production code handoff */
+       socfpga_handoff_read((void *)handoff->phy_engine_handoff_base,
+                            handoff_table,
+                            (u32)handoff->phy_engine_handoff_length);
+
+       for (i = 0; i < handoff->phy_engine_handoff_length; i = i + 2) {
+               debug("Handoff addr: 0x%8llx ", handoff_table[i] +
+                     handoff->phy_base);
+
+               /*
+                * Convert PHY odd offset to even offset that supported by
+                * ARM processor.
+                */
+               value = handoff_table[i] << 1;
+               debug("%s: Absolute addr: 0x%08llx, APB offset: 0x%08x ",
+                     __func__, value + handoff->phy_base, value);
+               debug("PHY offset: 0x%08x", handoff_table[i]);
+               debug(" wr = 0x%08x ", handoff_table[i + 1]);
+
+               writew(handoff_table[i + 1], (uintptr_t)(value +
+                      handoff->phy_base));
+
+               debug("rd = 0x%08x\n", readw((uintptr_t)(value +
+                     handoff->phy_base)));
+       }
+
+       printf("End of loading PHY Init Engine\n");
+}
+
+int populate_ddr_handoff(struct ddr_handoff *handoff)
+{
+       phys_addr_t next_section_header;
+
+       /* DDR handoff */
+       handoff->mem_reset_base = SOC64_HANDOFF_DDR_MEMRESET_BASE;
+       debug("%s: DDR memory reset base = 0x%x\n", __func__,
+             (u32)handoff->mem_reset_base);
+       debug("%s: DDR memory reset address = 0x%x\n", __func__,
+             readl(handoff->mem_reset_base));
+
+       /* Beginning of DDR controller handoff */
+       handoff->cntlr_handoff_base = SOC64_HANDOFF_DDR_UMCTL2_SECTION;
+       debug("%s: cntlr handoff base = 0x%x\n", __func__,
+             (u32)handoff->cntlr_handoff_base);
+
+       /* Get 1st DDR type */
+       handoff->cntlr_t = get_ddr_type(handoff->cntlr_handoff_base +
+                                       SOC64_HANDOFF_DDR_UMCTL2_TYPE_OFFSET);
+       if (handoff->cntlr_t == DDRTYPE_LPDDR4_1 ||
+           handoff->cntlr_t == DDRTYPE_UNKNOWN) {
+               debug("%s: Wrong DDR handoff format, the 1st DDR ", __func__);
+               debug("type must be DDR4 or LPDDR4_0\n");
+               return -ENOEXEC;
+       }
+
+       /* 1st cntlr base physical address */
+       handoff->cntlr_base = readl(handoff->cntlr_handoff_base +
+                                   SOC64_HANDOFF_DDR_UMCTL2_BASE_ADDR_OFFSET);
+       debug("%s: cntlr base = 0x%x\n", __func__, (u32)handoff->cntlr_base);
+
+       /* Get the total length of DDR cntlr handoff section */
+       handoff->cntlr_total_length = readl(handoff->cntlr_handoff_base +
+                                           SOC64_HANDOFF_OFFSET_LENGTH);
+       debug("%s: Umctl2 total length in byte = 0x%x\n", __func__,
+             (u32)handoff->cntlr_total_length);
+
+       /* Get the length of user setting data in DDR cntlr handoff section */
+       handoff->cntlr_handoff_length = socfpga_get_handoff_size((void *)
+                                               handoff->cntlr_handoff_base);
+       debug("%s: Umctl2 handoff length in word(32-bit) = 0x%x\n", __func__,
+             (u32)handoff->cntlr_handoff_length);
+
+       /* Wrong format on user setting data */
+       if (handoff->cntlr_handoff_length < 0) {
+               debug("%s: Wrong format on user setting data\n", __func__);
+               return -ENOEXEC;
+       }
+
+       /* Get the next handoff section address */
+       next_section_header = handoff->cntlr_handoff_base +
+                               handoff->cntlr_total_length;
+       debug("%s: Next handoff section header location = 0x%llx\n", __func__,
+             next_section_header);
+
+       /*
+        * Checking next section handoff is cntlr or PHY, and changing
+        * subsequent implementation accordingly
+        */
+       if (readl(next_section_header) == SOC64_HANDOFF_DDR_UMCTL2_MAGIC) {
+               /* Get the next cntlr handoff section address */
+               handoff->cntlr2_handoff_base = next_section_header;
+               debug("%s: umctl2 2nd handoff base = 0x%x\n", __func__,
+                     (u32)handoff->cntlr2_handoff_base);
+
+               /* Get 2nd DDR type */
+               handoff->cntlr2_t = get_ddr_type(handoff->cntlr2_handoff_base +
+                                       SOC64_HANDOFF_DDR_UMCTL2_TYPE_OFFSET);
+               if (handoff->cntlr2_t == DDRTYPE_LPDDR4_0 ||
+                   handoff->cntlr2_t == DDRTYPE_UNKNOWN) {
+                       debug("%s: Wrong DDR handoff format, the 2nd DDR ",
+                             __func__);
+                       debug("type must be LPDDR4_1\n");
+                       return -ENOEXEC;
+               }
+
+               /* 2nd umctl2 base physical address */
+               handoff->cntlr2_base =
+                       readl(handoff->cntlr2_handoff_base +
+                             SOC64_HANDOFF_DDR_UMCTL2_BASE_ADDR_OFFSET);
+               debug("%s: cntlr2 base = 0x%x\n", __func__,
+                     (u32)handoff->cntlr2_base);
+
+               /* Get the total length of 2nd DDR umctl2 handoff section */
+               handoff->cntlr2_total_length =
+                       readl(handoff->cntlr2_handoff_base +
+                             SOC64_HANDOFF_OFFSET_LENGTH);
+               debug("%s: Umctl2_2nd total length in byte = 0x%x\n", __func__,
+                     (u32)handoff->cntlr2_total_length);
+
+               /*
+                * Get the length of user setting data in DDR umctl2 handoff
+                * section
+                */
+               handoff->cntlr2_handoff_length =
+                       socfpga_get_handoff_size((void *)
+                                                handoff->cntlr2_handoff_base);
+               debug("%s: cntlr2 handoff length in word(32-bit) = 0x%x\n",
+                     __func__,
+                    (u32)handoff->cntlr2_handoff_length);
+
+               /* Wrong format on user setting data */
+               if (handoff->cntlr2_handoff_length < 0) {
+                       debug("%s: Wrong format on umctl2 user setting data\n",
+                             __func__);
+                       return -ENOEXEC;
+               }
+
+               /* Get the next handoff section address */
+               next_section_header = handoff->cntlr2_handoff_base +
+                                       handoff->cntlr2_total_length;
+               debug("%s: Next handoff section header location = 0x%llx\n",
+                     __func__, next_section_header);
+       }
+
+       /* Checking next section handoff is PHY ? */
+       if (readl(next_section_header) == SOC64_HANDOFF_DDR_PHY_MAGIC) {
+               /* DDR PHY handoff */
+               handoff->phy_handoff_base = next_section_header;
+               debug("%s: PHY handoff base = 0x%x\n", __func__,
+                     (u32)handoff->phy_handoff_base);
+
+               /* PHY base physical address */
+               handoff->phy_base = readl(handoff->phy_handoff_base +
+                                       SOC64_HANDOFF_DDR_PHY_BASE_OFFSET);
+               debug("%s: PHY base = 0x%x\n", __func__,
+                     (u32)handoff->phy_base);
+
+               /* Get the total length of PHY handoff section */
+               handoff->phy_total_length = readl(handoff->phy_handoff_base +
+                                               SOC64_HANDOFF_OFFSET_LENGTH);
+               debug("%s: PHY total length in byte = 0x%x\n", __func__,
+                     (u32)handoff->phy_total_length);
+
+               /*
+                * Get the length of user setting data in DDR PHY handoff
+                * section
+                */
+               handoff->phy_handoff_length = socfpga_get_handoff_size((void *)
+                                               handoff->phy_handoff_base);
+               debug("%s: PHY handoff length in word(32-bit) = 0x%x\n",
+                     __func__, (u32)handoff->phy_handoff_length);
+
+               /* Wrong format on PHY user setting data */
+               if (handoff->phy_handoff_length < 0) {
+                       debug("%s: Wrong format on PHY user setting data\n",
+                             __func__);
+                       return -ENOEXEC;
+               }
+
+               /* Get the next handoff section address */
+               next_section_header = handoff->phy_handoff_base +
+                                       handoff->phy_total_length;
+               debug("%s: Next handoff section header location = 0x%llx\n",
+                     __func__, next_section_header);
+       } else {
+               debug("%s: Wrong format for DDR handoff, expect PHY",
+                     __func__);
+               debug(" handoff section after umctl2 handoff section\n");
+               return -ENOEXEC;
+       }
+
+       /* Checking next section handoff is PHY init Engine ? */
+       if (readl(next_section_header) ==
+               SOC64_HANDOFF_DDR_PHY_INIT_ENGINE_MAGIC) {
+               /* DDR PHY Engine handoff */
+               handoff->phy_engine_handoff_base = next_section_header;
+               debug("%s: PHY init engine handoff base = 0x%x\n", __func__,
+                     (u32)handoff->phy_engine_handoff_base);
+
+               /* Get the total length of PHY init engine handoff section */
+               handoff->phy_engine_total_length =
+                               readl(handoff->phy_engine_handoff_base +
+                                     SOC64_HANDOFF_OFFSET_LENGTH);
+               debug("%s: PHY engine total length in byte = 0x%x\n", __func__,
+                     (u32)handoff->phy_engine_total_length);
+
+               /*
+                * Get the length of user setting data in DDR PHY init engine
+                * handoff section
+                */
+               handoff->phy_engine_handoff_length =
+                       socfpga_get_handoff_size((void *)
+                                       handoff->phy_engine_handoff_base);
+               debug("%s: PHY engine handoff length in word(32-bit) = 0x%x\n",
+                     __func__, (u32)handoff->phy_engine_handoff_length);
+
+               /* Wrong format on PHY init engine setting data */
+               if (handoff->phy_engine_handoff_length < 0) {
+                       debug("%s: Wrong format on PHY init engine ",
+                             __func__);
+                       debug("user setting data\n");
+                       return -ENOEXEC;
+               }
+       } else {
+               debug("%s: Wrong format for DDR handoff, expect PHY",
+                     __func__);
+               debug(" init engine handoff section after PHY handoff\n");
+               debug(" section\n");
+               return -ENOEXEC;
+       }
+
+       handoff->train_imem_base = handoff->phy_base +
+                                               DDR_PHY_TRAIN_IMEM_OFFSET;
+       debug("%s: PHY train IMEM base = 0x%x\n",
+             __func__, (u32)handoff->train_imem_base);
+
+       handoff->train_dmem_base = handoff->phy_base +
+                                               DDR_PHY_TRAIN_DMEM_OFFSET;
+       debug("%s: PHY train DMEM base = 0x%x\n",
+             __func__, (u32)handoff->train_dmem_base);
+
+       handoff->train_imem_length = SOC64_HANDOFF_DDR_TRAIN_IMEM_LENGTH;
+       debug("%s: PHY train IMEM length = 0x%x\n",
+             __func__, (u32)handoff->train_imem_length);
+
+       handoff->train_dmem_length = SOC64_HANDOFF_DDR_TRAIN_DMEM_LENGTH;
+       debug("%s: PHY train DMEM length = 0x%x\n",
+             __func__, (u32)handoff->train_dmem_length);
+
+       return 0;
+}
+
+int enable_ddr_clock(struct udevice *dev)
+{
+       struct clk *ddr_clk;
+       int ret;
+
+       /* Enable clock before init DDR */
+       ddr_clk = devm_clk_get(dev, "mem_clk");
+       if (!IS_ERR(ddr_clk)) {
+               ret = clk_enable(ddr_clk);
+               if (ret) {
+                       printf("%s: Failed to enable DDR clock\n", __func__);
+                       return ret;
+               }
+       } else {
+               ret = PTR_ERR(ddr_clk);
+               debug("%s: Failed to get DDR clock from dts\n", __func__);
+               return ret;
+       }
+
+       printf("%s: DDR clock is enabled\n", __func__);
+
+       return 0;
+}
+
+static int ddr_start_dfi_init(phys_addr_t umctl2_base,
+                             enum ddr_type umctl2_type)
+{
+       int ret;
+
+       debug("%s: Start DFI init\n", __func__);
+
+       /* Enable quasi-dynamic programing of controller registers */
+       clrbits_le32(umctl2_base + DDR4_SWCTL_OFFSET, DDR4_SWCTL_SW_DONE);
+
+       ret = enable_quasi_dynamic_reg_grp3(umctl2_base, umctl2_type);
+       if (ret)
+               return ret;
+
+       /* Start DFI init sequence */
+       setbits_le32(umctl2_base + DDR4_DFIMISC_OFFSET,
+                    DDR4_DFIMISC_DFI_INIT_START);
+
+       /* Complete quasi-dynamic register programming */
+       setbits_le32(umctl2_base + DDR4_SWCTL_OFFSET, DDR4_SWCTL_SW_DONE);
+
+       /* Polling programming done */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SWSTAT_OFFSET),
+                               DDR4_SWSTAT_SW_DONE_ACK, true,
+                               TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" programming done\n");
+       }
+
+       return ret;
+}
+
+static int ddr_check_dfi_init_complete(phys_addr_t umctl2_base,
+                                      enum ddr_type umctl2_type)
+{
+       int ret;
+
+       /* Polling DFI init complete */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_DFISTAT_OFFSET),
+                               DDR4_DFI_INIT_COMPLETE, true,
+                               TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" DFI init done\n");
+               return ret;
+       }
+
+       debug("%s: DFI init completed.\n", __func__);
+
+       /* Enable quasi-dynamic programing of controller registers */
+       clrbits_le32(umctl2_base + DDR4_SWCTL_OFFSET, DDR4_SWCTL_SW_DONE);
+
+       ret = enable_quasi_dynamic_reg_grp3(umctl2_base, umctl2_type);
+       if (ret)
+               return ret;
+
+       /* Stop DFI init sequence */
+       clrbits_le32(umctl2_base + DDR4_DFIMISC_OFFSET,
+                    DDR4_DFIMISC_DFI_INIT_START);
+
+       /* Complete quasi-dynamic register programming */
+       setbits_le32(umctl2_base + DDR4_SWCTL_OFFSET, DDR4_SWCTL_SW_DONE);
+
+       /* Polling programming done */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SWSTAT_OFFSET),
+                               DDR4_SWSTAT_SW_DONE_ACK, true,
+                               TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" programming done\n");
+               return ret;
+       }
+
+       debug("%s:DDR programming done\n", __func__);
+
+       return ret;
+}
+
+static int ddr_trigger_sdram_init(phys_addr_t umctl2_base,
+                                 enum ddr_type umctl2_type)
+{
+       int ret;
+
+       /* Enable quasi-dynamic programing of controller registers */
+       clrbits_le32(umctl2_base + DDR4_SWCTL_OFFSET, DDR4_SWCTL_SW_DONE);
+
+       ret = enable_quasi_dynamic_reg_grp3(umctl2_base, umctl2_type);
+       if (ret)
+               return ret;
+
+       /* Unmasking dfi init complete */
+       setbits_le32(umctl2_base + DDR4_DFIMISC_OFFSET,
+                    DDR4_DFIMISC_DFI_INIT_COMPLETE_EN);
+
+       /* Software exit from self-refresh */
+       clrbits_le32(umctl2_base + DDR4_PWRCTL_OFFSET, DDR4_PWRCTL_SELFREF_SW);
+
+       /* Complete quasi-dynamic register programming */
+       setbits_le32(umctl2_base + DDR4_SWCTL_OFFSET, DDR4_SWCTL_SW_DONE);
+
+       /* Polling programming done */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SWSTAT_OFFSET),
+                               DDR4_SWSTAT_SW_DONE_ACK, true,
+                               TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" programming done\n");
+               return ret;
+       }
+
+       debug("%s:DDR programming done\n", __func__);
+       return ret;
+}
+

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+static int ddr_post_handoff_config(phys_addr_t umctl2_base,
+                                  enum ddr_type umctl2_type)
+{
+       int ret = 0;
+       u32 value;
+       u32 start = get_timer(0);
+
+       /* Polling until SDRAM entered normal operating mode */
+       value = readl(umctl2_base + DDR4_STAT_OFFSET) &
+                     DDR4_STAT_OPERATING_MODE;

Can merge to "do..while" loop below.

Quoted 590 lines
drivers/ddr/altera/Makefile +590 -0
+       while (value != NORMAL_OPM) {
+               if (get_timer(start) > TIMEOUT_200MS) {
+                       debug("%s: Timeout while waiting for",
+                             __func__);
+                       debug(" DDR enters normal operating mode\n");
+                       return -ETIMEDOUT;
+               }
+
+               value = readl(umctl2_base + DDR4_STAT_OFFSET) &
+                             DDR4_STAT_OPERATING_MODE;
+
+               udelay(1);
+               WATCHDOG_RESET();
+       }
+
+       printf("DDR entered normal operating mode\n");
+
+       /* Enabling auto refresh */
+       clrbits_le32(umctl2_base + DDR4_RFSHCTL3_OFFSET,
+                    DDR4_RFSHCTL3_DIS_AUTO_REFRESH);
+
+       /* Checking ECC is enabled? */
+       value = readl(umctl2_base + DDR4_ECCCFG0_OFFSET) & DDR4_ECC_MODE;
+       if (value) {
+               printf("ECC is enabled\n");
+               ret = scrubber_ddr_config(umctl2_base, umctl2_type);
+               if (ret)
+                       printf("Failed to enable ECC\n");
+       }
+
+       return ret;
+}
+
+static int configure_training_firmware(struct ddr_handoff *ddr_handoff_info,
+       const void *train_imem, const void *train_dmem)
+{
+       int ret = 0;
+
+       printf("Configuring training firmware ...\n");
+
+       /* Reset SDRAM */
+       writew(DDR_PHY_PROTECT_MEMRESET,
+              (uintptr_t)(ddr_handoff_info->phy_base +
+              DDR_PHY_MEMRESETL_OFFSET));
+
+       /* Enable access to the PHY configuration registers */
+       clrbits_le16(ddr_handoff_info->phy_base + DDR_PHY_APBONLY0_OFFSET,
+                    DDR_PHY_MICROCONTMUXSEL);
+
+       /* Copy train IMEM bin */
+       memcpy((void *)ddr_handoff_info->train_imem_base, train_imem,
+              ddr_handoff_info->train_imem_length);
+
+       ret = memcmp((void *)ddr_handoff_info->train_imem_base, train_imem,
+                    ddr_handoff_info->train_imem_length);
+       if (ret) {
+               debug("%s: Failed to copy train IMEM binary\n", __func__);
+               /* Isolate the APB access from internal CSRs */
+               setbits_le16(ddr_handoff_info->phy_base +
+                            DDR_PHY_APBONLY0_OFFSET, DDR_PHY_MICROCONTMUXSEL);
+               return ret;
+       }
+
+       memcpy((void *)ddr_handoff_info->train_dmem_base, train_dmem,
+              ddr_handoff_info->train_dmem_length);
+
+       ret = memcmp((void *)ddr_handoff_info->train_dmem_base, train_dmem,
+                    ddr_handoff_info->train_dmem_length);
+       if (ret)
+               debug("%s: Failed to copy train DMEM binary\n", __func__);
+
+       /* Isolate the APB access from internal CSRs */
+       setbits_le16(ddr_handoff_info->phy_base + DDR_PHY_APBONLY0_OFFSET,
+                    DDR_PHY_MICROCONTMUXSEL);
+
+       return ret;
+}
+
+static void calibrating_sdram(struct ddr_handoff *ddr_handoff_info)
+{
+       /* Init mailbox protocol - set 1 to DCTWRITEPROT[0] */
+       setbits_le16(ddr_handoff_info->phy_base + DDR_PHY_DCTWRITEPROT_OFFSET,
+                    DDR_PHY_DCTWRITEPROT);
+
+       /* Init mailbox protocol - set 1 to UCTWRITEPROT[0] */
+       setbits_le16(ddr_handoff_info->phy_base + DDR_PHY_UCTWRITEPROT_OFFSET,
+                    DDR_PHY_UCTWRITEPROT);
+
+       /* Reset and stalling ARC processor */
+       setbits_le16(ddr_handoff_info->phy_base + DDR_PHY_MICRORESET_OFFSET,
+                    DDR_PHY_MICRORESET_RESET | DDR_PHY_MICRORESET_STALL);
+
+       /* Release ARC processor */
+       clrbits_le16(ddr_handoff_info->phy_base + DDR_PHY_MICRORESET_OFFSET,
+                    DDR_PHY_MICRORESET_RESET);
+
+       /* Starting PHY firmware execution */
+       clrbits_le16(ddr_handoff_info->phy_base + DDR_PHY_MICRORESET_OFFSET,
+                    DDR_PHY_MICRORESET_STALL);
+}
+
+static int get_mail(struct ddr_handoff *handoff, enum message_mode mode,
+                   u32 *message_id)
+{
+       int ret;
+
+       /* Polling major messages from PMU */
+       ret = wait_for_bit_le16((const void *)(handoff->phy_base +
+                               DDR_PHY_UCTSHADOWREGS_OFFSET),
+                               DDR_PHY_UCTSHADOWREGS_UCTWRITEPROTESHADOW,
+                               false, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for",
+                     __func__);
+               debug(" major messages from PMU\n");
+               return ret;
+       }
+
+       *message_id = readw((uintptr_t)(handoff->phy_base +
+                           DDR_PHY_UCTWRITEONLYSHADOW_OFFSET));
+
+       if (mode == STREAMING_MESSAGE)
+               *message_id |= readw((uintptr_t)((handoff->phy_base +
+                                    DDR_PHY_UCTDATWRITEONLYSHADOW_OFFSET))) <<
+                                    SZ_16;
+
+       /* Ack the receipt of the major message */
+       clrbits_le16(handoff->phy_base + DDR_PHY_DCTWRITEPROT_OFFSET,
+                    DDR_PHY_DCTWRITEPROT);
+
+       ret = wait_for_bit_le16((const void *)(handoff->phy_base +
+                               DDR_PHY_UCTSHADOWREGS_OFFSET),
+                               DDR_PHY_UCTSHADOWREGS_UCTWRITEPROTESHADOW,
+                               true, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for",
+                     __func__);
+               debug(" ack the receipt of the major message completed\n");
+               return ret;
+       }
+
+       /* Complete protocol */
+       setbits_le16(handoff->phy_base + DDR_PHY_DCTWRITEPROT_OFFSET,
+                    DDR_PHY_DCTWRITEPROT);
+
+       return ret;
+}
+
+static int get_mail_streaming(struct ddr_handoff *handoff,
+                             enum message_mode mode, u32 *index)
+{
+       int ret;
+
+       *index = readw((uintptr_t)(handoff->phy_base +
+                      DDR_PHY_UCTWRITEONLYSHADOW_OFFSET));
+
+       if (mode == STREAMING_MESSAGE)
+               *index |= readw((uintptr_t)((handoff->phy_base +
+                               DDR_PHY_UCTDATWRITEONLYSHADOW_OFFSET))) <<
+                               SZ_16;
+
+       /* Ack the receipt of the major message */
+       clrbits_le16(handoff->phy_base + DDR_PHY_DCTWRITEPROT_OFFSET,
+                    DDR_PHY_DCTWRITEPROT);
+
+       ret = wait_for_bit_le16((const void *)(handoff->phy_base +
+                               DDR_PHY_UCTSHADOWREGS_OFFSET),
+                               DDR_PHY_UCTSHADOWREGS_UCTWRITEPROTESHADOW,
+                               true, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for",
+                     __func__);
+               debug(" ack the receipt of the major message completed\n");
+               return ret;
+       }
+
+       /* Complete protocol */
+       setbits_le16(handoff->phy_base + DDR_PHY_DCTWRITEPROT_OFFSET,
+                    DDR_PHY_DCTWRITEPROT);
+
+       return 0;
+}
+
+static int decode_streaming_message(struct ddr_handoff *ddr_handoff_info,
+                                   u32 *streaming_index)
+{
+       int i = 0, ret;
+       u32 temp;
+
+       temp = *streaming_index;
+
+       while (i < GET_LOWHW_DATA(temp)) {
+               ret = get_mail(ddr_handoff_info, STREAMING_MESSAGE,
+                              streaming_index);
+               if (ret)
+                       return ret;
+
+               printf("args[%d]: 0x%x ", i, *streaming_index);
+               i++;
+       }
+
+       return 0;
+}
+
+static int poll_for_training_complete(struct ddr_handoff *ddr_handoff_info)
+{
+       int ret;
+       u32 message_id = 0;
+       u32 streaming_index = 0;
+
+       do {
+               ret = get_mail(ddr_handoff_info, MAJOR_MESSAGE, &message_id);
+               if (ret)
+                       return ret;
+
+                printf("Major message id = 0%x\n", message_id);
+
+               if (message_id == FW_STREAMING_MSG_ID) {
+                       ret = get_mail_streaming(ddr_handoff_info,
+                                                STREAMING_MESSAGE,
+                                                &streaming_index);
+                       if (ret)
+                               return ret;
+
+                       printf("streaming index 0%x : ", streaming_index);
+
+                       decode_streaming_message(ddr_handoff_info,
+                                                &streaming_index);
+
+                       printf("\n");
+               }
+       } while ((message_id != FW_TRAINING_COMPLETED_STAT) &&
+              (message_id != FW_TRAINING_FAILED_STAT));
+
+       if (message_id == FW_TRAINING_COMPLETED_STAT) {
+               printf("DDR firmware training completed\n");
+       } else if (message_id == FW_TRAINING_FAILED_STAT) {
+               printf("DDR firmware training failed\n");
+               hang();
+       }
+
+       return 0;
+}
+
+static void enable_phy_clk_for_csr_access(struct ddr_handoff *handoff,
+                                         bool enable)
+{
+       if (enable) {
+               /* Enable PHY clk */
+               setbits_le16((uintptr_t)(handoff->phy_base +
+                            DDR_PHY_UCCLKHCLKENABLES_OFFSET),
+                            DDR_PHY_UCCLKHCLKENABLES_UCCLKEN |
+                            DDR_PHY_UCCLKHCLKENABLES_HCLKEN);
+       } else {
+               /* Disable PHY clk */
+               clrbits_le16((uintptr_t)(handoff->phy_base +
+                            DDR_PHY_UCCLKHCLKENABLES_OFFSET),
+                            DDR_PHY_UCCLKHCLKENABLES_UCCLKEN |
+                            DDR_PHY_UCCLKHCLKENABLES_HCLKEN);
+       }
+}
+
+/* helper function for updating train result to umctl2 RANKCTL register */
+static void set_cal_res_to_rankctrl(u32 reg_addr, u16 update_value,
+                                   u32 mask, u32 msb_mask, u32 shift)
+{
+       u32 reg, value;
+
+       reg = readl((uintptr_t)reg_addr);
+
+       debug("max value divided by 2 is 0x%x\n", update_value);
+       debug("umclt2 register 0x%x value is 0%x before ", reg_addr, reg);
+       debug("update with train result\n");
+
+       value = (reg & mask) >> shift;
+
+       value += update_value + 3;
+
+       /* reg value greater than 0xF, set one to diff_rank_wr_gap_msb */
+       if (value > 0xF)
+               setbits_le32((u32 *)(uintptr_t)reg_addr, msb_mask);
+       else
+               clrbits_le32((u32 *)(uintptr_t)reg_addr, msb_mask);
+
+       reg = readl((uintptr_t)reg_addr);
+
+       value = (value << shift) & mask;
+
+       /* update register */
+       writel((reg & (~mask)) | value, (uintptr_t)reg_addr);
+
+       reg = readl((uintptr_t)reg_addr);
+       debug("umclt2 register 0x%x value is 0%x before ", reg_addr, reg);
+       debug("update with train result\n");
+}
+
+/* helper function for updating train result to register */
+static void set_cal_res_to_reg(u32 reg_addr, u16 update_value, u32 mask,
+                              u32 shift)
+{
+       u32 reg, value;
+
+       reg = readl((uintptr_t)reg_addr);
+
+       debug("max value divided by 2 is 0x%x\n", update_value);
+       debug("umclt2 register 0x%x value is 0%x before ", reg_addr, reg);
+       debug("update with train result\n");
+
+       value = (reg & mask) >> shift;
+
+       value = ((value + update_value + 3) << shift) & mask;
+
+       /* update register */
+       writel((reg & (~mask)) | value, (uintptr_t)reg_addr);
+
+       reg = readl((uintptr_t)reg_addr);
+       debug("umclt2 register 0x%x value is 0%x before ", reg_addr, reg);
+       debug("update with train result\n");
+}
+
+static u16 get_max_txdqsdlytg0_ux_p0(struct ddr_handoff *handoff, u32 reg,
+                                    u8 numdbyte, u16 upd_val)
+{
+       u32 b_addr;
+       u16 val;
+       u8 byte;
+
+       /* Getting max value from DBYTEx TxDqsDlyTg0_ux_p0 */
+       for (byte = 0; byte < numdbyte; byte++) {
+               b_addr = byte << 13;
+
+               /* TxDqsDlyTg0[9:6] is the coarse delay */
+               val = (readw((uintptr_t)(handoff->phy_base +
+                            reg + b_addr)) &
+                            DDR_PHY_TXDQDLYTG0_COARSE_DELAY) >>
+                            DDR_PHY_TXDQDLYTG0_COARSE_DELAY_SHIFT;
+
+               upd_val = max(val, upd_val);
+       }
+
+       return upd_val;
+}
+
+static int set_cal_res_to_umctl2(struct ddr_handoff *handoff,
+                                phys_addr_t umctl2_base,
+                                enum ddr_type umctl2_type)
+{
+       int ret;
+       u8 numdbyte = 0x8;
+       u16 upd_val, val;
+       u32 dramtmg2_reg_addr, rankctl_reg_addr, reg_addr;
+
+       /* Enable quasi-dynamic programing of the controller registers */
+       clrbits_le32(umctl2_base + DDR4_SWCTL_OFFSET, DDR4_SWCTL_SW_DONE);
+
+       ret = enable_quasi_dynamic_reg_grp3(umctl2_base, umctl2_type);
+       if (ret)
+               return ret;
+
+       /* Enable access to the PHY configuration registers */
+       clrbits_le16(handoff->phy_base + DDR_PHY_APBONLY0_OFFSET,
+                    DDR_PHY_MICROCONTMUXSEL);
+
+       if (umctl2_type == DDRTYPE_DDR4) {
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                    DMEM_MB_CDD_WW_1_0_OFFSET)));
+
+               upd_val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                       DMEM_MB_CDD_WW_0_1_OFFSET)));
+       } else if (umctl2_type == DDRTYPE_LPDDR4_0) {
+               val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                   DMEM_MB_CDD_CHA_WW_1_0_OFFSET)));
+
+               upd_val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                        DMEM_MB_CDD_CHA_WW_0_1_OFFSET)));
+       } else if (umctl2_type == DDRTYPE_LPDDR4_1) {
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                    DMEM_MB_CDD_CHB_WW_1_0_OFFSET)));
+
+               upd_val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                       DMEM_MB_CDD_CHB_WW_0_1_OFFSET)));
+       }
+
+       upd_val = max(val, upd_val);
+       debug("max value is 0x%x\n", upd_val);
+
+       /* Divided by two is required when running in freq ratio 1:2 */
+       if (!(readl(umctl2_base + DDR4_MSTR_OFFSET) & DDR4_FREQ_RATIO))
+               upd_val = DIV_ROUND_CLOSEST(upd_val, 2);
+
+       debug("Update train value to umctl2 RANKCTL.diff_rank_wr_gap\n");
+       rankctl_reg_addr = umctl2_base + DDR4_RANKCTL_OFFSET;
+       /* Update train value to umctl2 RANKCTL.diff_rank_wr_gap */
+       set_cal_res_to_rankctrl(rankctl_reg_addr, upd_val,
+                               DDR4_RANKCTL_DIFF_RANK_WR_GAP,
+                               DDR4_RANKCTL_DIFF_RANK_WR_GAP_MSB,
+                               DDR4_RANKCTL_DIFF_RANK_WR_GAP_SHIFT);
+
+       debug("Update train value to umctl2 DRAMTMG2.W2RD\n");
+       dramtmg2_reg_addr = umctl2_base + DDR4_DRAMTMG2_OFFSET;
+       /* Update train value to umctl2 dramtmg2.wr2rd */
+       set_cal_res_to_reg(dramtmg2_reg_addr, upd_val, DDR4_DRAMTMG2_WR2RD, 0);
+
+       if (umctl2_type == DDRTYPE_DDR4) {
+               debug("Update train value to umctl2 DRAMTMG9.W2RD_S\n");
+               reg_addr = umctl2_base + DDR4_DRAMTMG9_OFFSET;
+               /* Update train value to umctl2 dramtmg9.wr2rd_s */
+               set_cal_res_to_reg(reg_addr, upd_val, DDR4_DRAMTMG9_W2RD_S, 0);
+       }
+
+       if (umctl2_type == DDRTYPE_DDR4) {
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                    DMEM_MB_CDD_RR_1_0_OFFSET)));
+
+               upd_val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                       DMEM_MB_CDD_RR_0_1_OFFSET)));
+       } else if (umctl2_type == DDRTYPE_LPDDR4_0) {
+               val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                   DMEM_MB_CDD_CHA_RR_1_0_OFFSET)));
+
+               upd_val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                        DMEM_MB_CDD_CHA_RR_0_1_OFFSET)));
+       } else if (umctl2_type == DDRTYPE_LPDDR4_1) {
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                    DMEM_MB_CDD_CHB_RR_1_0_OFFSET)));
+
+               upd_val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                       DMEM_MB_CDD_CHB_RR_0_1_OFFSET)));
+       }
+
+       upd_val = max(val, upd_val);
+       debug("max value is 0x%x\n", upd_val);
+
+       /* Divided by two is required when running in freq ratio 1:2 */
+       if (!(readl(umctl2_base + DDR4_MSTR_OFFSET) & DDR4_FREQ_RATIO))
+               upd_val = DIV_ROUND_CLOSEST(upd_val, 2);
+
+       debug("Update train value to umctl2 RANKCTL.diff_rank_rd_gap\n");
+       /* Update train value to umctl2 RANKCTL.diff_rank_rd_gap */
+       set_cal_res_to_rankctrl(rankctl_reg_addr, upd_val,
+                               DDR4_RANKCTL_DIFF_RANK_RD_GAP,
+                               DDR4_RANKCTL_DIFF_RANK_RD_GAP_MSB,
+                               DDR4_RANKCTL_DIFF_RANK_RD_GAP_SHIFT);
+
+       if (umctl2_type == DDRTYPE_DDR4) {
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                    DMEM_MB_CDD_RW_1_1_OFFSET)));
+
+               upd_val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                       DMEM_MB_CDD_RW_1_0_OFFSET)));
+
+               upd_val = max(val, upd_val);
+
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                    DMEM_MB_CDD_RW_0_1_OFFSET)));
+
+               upd_val = max(val, upd_val);
+
+               val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                   DMEM_MB_CDD_RW_0_0_OFFSET)));
+
+               upd_val = max(val, upd_val);
+       } else if (umctl2_type == DDRTYPE_LPDDR4_0) {
+               val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                   DMEM_MB_CDD_CHA_RW_1_1_OFFSET)));
+
+               upd_val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                        DMEM_MB_CDD_CHA_RW_1_0_OFFSET)));
+
+               upd_val = max(val, upd_val);
+
+               val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                   DMEM_MB_CDD_CHA_RW_0_1_OFFSET)));
+
+               upd_val = max(val, upd_val);
+
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                    DMEM_MB_CDD_CHA_RW_0_0_OFFSET)));
+
+               upd_val = max(val, upd_val);
+       } else if (umctl2_type == DDRTYPE_LPDDR4_1) {
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                    DMEM_MB_CDD_CHB_RW_1_1_OFFSET)));
+
+               upd_val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                       DMEM_MB_CDD_CHB_RW_1_0_OFFSET)));
+
+               upd_val = max(val, upd_val);
+
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                    DMEM_MB_CDD_CHB_RW_0_1_OFFSET)));
+
+               upd_val = max(val, upd_val);
+
+               val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                   DMEM_MB_CDD_CHB_RW_0_0_OFFSET)));
+
+               upd_val = max(val, upd_val);
+       }
+
+       debug("max value is 0x%x\n", upd_val);
+
+       /* Divided by two is required when running in freq ratio 1:2 */
+       if (!(readl(umctl2_base + DDR4_MSTR_OFFSET) & DDR4_FREQ_RATIO))
+               upd_val = DIV_ROUND_CLOSEST(upd_val, 2);
+
+       debug("Update train value to umctl2 dramtmg2.rd2wr\n");
+       /* Update train value to umctl2 dramtmg2.rd2wr */
+       set_cal_res_to_reg(dramtmg2_reg_addr, upd_val, DDR4_DRAMTMG2_RD2WR,
+                          DDR4_DRAMTMG2_RD2WR_SHIFT);
+
+       /* Checking ECC is enabled?, lpddr4 using inline ECC */
+       val = readl(umctl2_base + DDR4_ECCCFG0_OFFSET) & DDR4_ECC_MODE;
+       if (val && umctl2_type == DDRTYPE_DDR4)
+               numdbyte = 0x9;
+
+       upd_val = 0;
+
+       /* Getting max value from DBYTEx TxDqsDlyTg0_u0_p0 */
+       upd_val = get_max_txdqsdlytg0_ux_p0(handoff,
+                                           DDR_PHY_DBYTE0_TXDQDLYTG0_U0_P0,
+                                           numdbyte, upd_val);
+
+       /* Getting max value from DBYTEx TxDqsDlyTg0_u1_p0 */
+       upd_val = get_max_txdqsdlytg0_ux_p0(handoff,
+                                           DDR_PHY_DBYTE0_TXDQDLYTG0_U1_P0,
+                                           numdbyte, upd_val);
+
+       debug("TxDqsDlyTg0 max value is 0x%x\n", upd_val);
+
+       /* Divided by two is required when running in freq ratio 1:2 */
+       if (!(readl(umctl2_base + DDR4_MSTR_OFFSET) & DDR4_FREQ_RATIO))
+               upd_val = DIV_ROUND_CLOSEST(upd_val, 2);
+
+       reg_addr = umctl2_base + DDR4_DFITMG1_OFFSET;
+       /* Update train value to umctl2 dfitmg1.dfi_wrdata_delay */
+       set_cal_res_to_reg(reg_addr, upd_val, DDR4_DFITMG1_DFI_T_WRDATA_DELAY,
+                          DDR4_DFITMG1_DFI_T_WRDATA_SHIFT);
+
+       /* Complete quasi-dynamic register programming */
+       setbits_le32(umctl2_base + DDR4_SWCTL_OFFSET, DDR4_SWCTL_SW_DONE);
+
+       /* Polling programming done */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SWSTAT_OFFSET), DDR4_SWSTAT_SW_DONE_ACK,
+                               true, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" programming done\n");
+       }
+
+       /* Isolate the APB access from internal CSRs */
+       setbits_le16(handoff->phy_base + DDR_PHY_APBONLY0_OFFSET,
+                    DDR_PHY_MICROCONTMUXSEL);
+
+       return ret;
+}
+
+static int start_ddr_calibration(struct ddr_handoff *ddr_handoff_info)
+{
+       int ret;
+
+       /* Implement 1D training firmware */
+       ret = configure_training_firmware(ddr_handoff_info,
+               (const void *)SOC64_HANDOFF_DDR_TRAIN_IMEM_1D_SECTION,
+               (const void *)SOC64_HANDOFF_DDR_TRAIN_DMEM_1D_SECTION);
+       if (ret) {
+               debug("%s: Failed to configure 1D training firmware\n",
+                     __func__);
+               return ret;
+       }
+
+       calibrating_sdram(ddr_handoff_info);
+
+       ret = poll_for_training_complete(ddr_handoff_info);
+       if (ret) {
+               debug("%s: Failed to get FW training completed\n",
+                     __func__);
+               return ret;
+       }
+
+       /* Updating training result to DDR controller */
+       if (ddr_handoff_info->cntlr_t == DDRTYPE_DDR4) {
+               ret = set_cal_res_to_umctl2(ddr_handoff_info,
+                                           ddr_handoff_info->cntlr_base,
+                                           ddr_handoff_info->cntlr_t);
+               if (ret) {
+                       debug("%s: Failed to update train result to ",
+                             __func__);
+                       debug("DDR controller\n");

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+                       return ret;
+               }
+       }
+
+       /* Implement 2D training firmware */
+       ret = configure_training_firmware(ddr_handoff_info,
+               (const void *)SOC64_HANDOFF_DDR_TRAIN_IMEM_2D_SECTION,
+               (const void *)SOC64_HANDOFF_DDR_TRAIN_DMEM_2D_SECTION);
+       if (ret) {
+               if (ret) {

Why need 2 checking for "ret"?

Quoted 453 lines
drivers/ddr/altera/Makefile +332 -0
+                       debug("%s: Failed to update train result to ",
+                             __func__);
+                       debug("DDR controller\n");
+                       return ret;
+               }
+       }
+
+       calibrating_sdram(ddr_handoff_info);
+
+       ret = poll_for_training_complete(ddr_handoff_info);
+       if (ret)
+               debug("%s: Failed to get FW training completed\n",
+                     __func__);
+
+       return ret;
+}
+
+static int init_controller(struct ddr_handoff *ddr_handoff_info,
+                          u32 *user_backup, u32 *user_backup_2nd)
+{
+       int ret = 0;
+
+       if (ddr_handoff_info->cntlr_t == DDRTYPE_DDR4  ||
+           ddr_handoff_info->cntlr_t == DDRTYPE_LPDDR4_0) {
+               /* Initialize 1st DDR controller */
+               ret = init_umctl2(ddr_handoff_info->cntlr_handoff_base,
+                                 ddr_handoff_info->cntlr_base,
+                                 ddr_handoff_info->cntlr_t,
+                                 ddr_handoff_info->cntlr_handoff_length,
+                                 user_backup);
+               if (ret) {
+                       debug("%s: Failed to inilialize first controller\n",
+                             __func__);
+                       return ret;
+               }
+       }
+
+       if (ddr_handoff_info->cntlr2_t == DDRTYPE_LPDDR4_1) {
+               /* Initialize 2nd DDR controller */
+               ret = init_umctl2(ddr_handoff_info->cntlr2_handoff_base,
+                                 ddr_handoff_info->cntlr2_base,
+                                 ddr_handoff_info->cntlr2_t,
+                                 ddr_handoff_info->cntlr2_handoff_length,
+                                 user_backup_2nd);
+               if (ret)
+                       debug("%s: Failed to inilialize 2nd controller\n",
+                             __func__);
+       }
+
+       return ret;
+}
+
+static int dfi_init(struct ddr_handoff *ddr_handoff_info)
+{
+       int ret;
+
+       ret = ddr_start_dfi_init(ddr_handoff_info->cntlr_base,
+                                ddr_handoff_info->cntlr_t);
+       if (ret)
+               return ret;
+
+       if (ddr_handoff_info->cntlr2_t == DDRTYPE_LPDDR4_1)
+               ret = ddr_start_dfi_init(ddr_handoff_info->cntlr2_base,
+                                        ddr_handoff_info->cntlr2_t);
+
+       return ret;
+}
+
+static int check_dfi_init(struct ddr_handoff *handoff)
+{
+       int ret;
+
+       ret = ddr_check_dfi_init_complete(handoff->cntlr_base,
+                                         handoff->cntlr_t);
+       if (ret)
+               return ret;
+
+       if (handoff->cntlr2_t == DDRTYPE_LPDDR4_1)
+               ret = ddr_check_dfi_init_complete(handoff->cntlr2_base,
+                                                 handoff->cntlr2_t);
+
+       return ret;
+}
+
+static int trigger_sdram_init(struct ddr_handoff *handoff)
+{
+       int ret;
+
+       ret = ddr_trigger_sdram_init(handoff->cntlr_base,
+                                    handoff->cntlr_t);
+       if (ret)
+               return ret;
+
+       if (handoff->cntlr2_t == DDRTYPE_LPDDR4_1)
+               ret = ddr_trigger_sdram_init(handoff->cntlr2_base,
+                                            handoff->cntlr2_t);
+
+       return ret;
+}
+
+static int ddr_post_config(struct ddr_handoff *handoff)
+{
+       int ret;
+
+       ret = ddr_post_handoff_config(handoff->cntlr_base,
+                                     handoff->cntlr_t);
+       if (ret)
+               return ret;
+
+       if (handoff->cntlr2_t == DDRTYPE_LPDDR4_1)
+               ret = ddr_post_handoff_config(handoff->cntlr2_base,
+                                             handoff->cntlr2_t);
+
+       return ret;
+}
+
+static bool is_ddr_retention_enabled(u32 boot_scratch_cold0_reg)
+{
+       return boot_scratch_cold0_reg &
+              ALT_SYSMGR_SCRATCH_REG_0_DDR_RETENTION_MASK;
+}
+
+static bool is_ddr_bitstream_sha_matching(u32 boot_scratch_cold0_reg)
+{
+       return boot_scratch_cold0_reg & ALT_SYSMGR_SCRATCH_REG_0_DDR_SHA_MASK;
+}
+
+static enum reset_type get_reset_type(u32 boot_scratch_cold0_reg)
+{
+       return (boot_scratch_cold0_reg &
+               ALT_SYSMGR_SCRATCH_REG_0_DDR_RESET_TYPE_MASK) >>
+               ALT_SYSMGR_SCRATCH_REG_0_DDR_RESET_TYPE_SHIFT;
+}
+
+void reset_type_debug_print(u32 boot_scratch_cold0_reg)
+{
+       switch (get_reset_type(boot_scratch_cold0_reg)) {
+       case POR_RESET:
+               debug("%s: POR is triggered\n", __func__);
+               break;
+       case WARM_RESET:
+               debug("%s: Warm reset is triggered\n", __func__);
+               break;
+       case COLD_RESET:
+               debug("%s: Cold reset is triggered\n", __func__);
+               break;
+       default:
+               debug("%s: Invalid reset type\n", __func__);
+       }
+}
+
+bool is_ddr_init(void)
+{
+       u32 reg = readl(socfpga_get_sysmgr_addr() +
+                       SYSMGR_SOC64_BOOT_SCRATCH_COLD0);
+
+       reset_type_debug_print(reg);
+
+       if (get_reset_type(reg) == POR_RESET) {
+               debug("%s: DDR init is required\n", __func__);
+               return true;
+       }
+
+       if (get_reset_type(reg) == WARM_RESET) {
+               debug("%s: DDR init is skipped\n", __func__);
+               return false;
+       }
+
+       if (get_reset_type(reg) == COLD_RESET) {
+               if (is_ddr_retention_enabled(reg) &&
+                   is_ddr_bitstream_sha_matching(reg)) {
+                       debug("%s: DDR retention bit is set\n", __func__);
+                       debug("%s: Matching in DDR bistream\n", __func__);
+                       debug("%s: DDR init is skipped\n", __func__);
+                       return false;
+               }
+       }
+
+       debug("%s: DDR init is required\n", __func__);
+       return true;
+}
+
+int sdram_mmr_init_full(struct udevice *dev)
+{
+       u32 user_backup[2], user_backup_2nd[2];
+       int ret;
+       struct bd_info bd;
+       struct ddr_handoff ddr_handoff_info;
+       struct altera_sdram_priv *priv = dev_get_priv(dev);
+
+       printf("Checking SDRAM configuration in progress ...\n");
+       ret = populate_ddr_handoff(&ddr_handoff_info);
+               if (ret) {
+                       debug("%s: Failed to populate DDR handoff\n",
+                             __func__);
+                       return ret;
+               }
+
+       /* Set the MPFE NoC mux to correct DDR controller type */
+       use_ddr4(ddr_handoff_info.cntlr_t);
+
+       if (is_ddr_init()) {
+               printf("SDRAM init in progress ...\n");
+
+               /*
+                * Polling reset complete, must be high to ensure DDR subsystem
+                * in complete reset state before init DDR clock and DDR
+                * controller
+                */
+               ret = wait_for_bit_le32((const void *)((uintptr_t)(readl
+                                       (ddr_handoff_info.mem_reset_base) +
+                                       MEM_RST_MGR_STATUS)),
+                                       MEM_RST_MGR_STATUS_RESET_COMPLETE,
+                                       true, TIMEOUT_200MS, false);
+               if (ret) {
+                       debug("%s: Timeout while waiting for", __func__);
+                       debug(" reset complete done\n");
+                       return ret;
+               }
+
+               ret = enable_ddr_clock(dev);
+               if (ret)
+                       return ret;
+
+               ret = init_controller(&ddr_handoff_info, user_backup,
+                                     user_backup_2nd);
+               if (ret) {
+                       debug("%s: Failed to inilialize DDR controller\n",
+                             __func__);
+                       return ret;
+               }
+
+               /* Release the controller from reset */
+               setbits_le32((uintptr_t)
+                            (readl(ddr_handoff_info.mem_reset_base) +
+                            MEM_RST_MGR_STATUS), MEM_RST_MGR_STATUS_AXI_RST |
+                            MEM_RST_MGR_STATUS_CONTROLLER_RST |
+                            MEM_RST_MGR_STATUS_RESET_COMPLETE);
+
+               printf("DDR controller configuration is completed\n");
+
+               /* Initialize DDR PHY */
+               ret = init_phy(&ddr_handoff_info);
+               if (ret) {
+                       debug("%s: Failed to inilialize DDR PHY\n", __func__);
+                       return ret;
+               }
+
+               enable_phy_clk_for_csr_access(&ddr_handoff_info, true);
+
+               ret = start_ddr_calibration(&ddr_handoff_info);
+               if (ret) {
+                       debug("%s: Failed to calibrate DDR\n", __func__);
+                       return ret;
+               }
+
+               enable_phy_clk_for_csr_access(&ddr_handoff_info, false);
+
+               /* Reset ARC processor when no using for security purpose */
+               setbits_le16(ddr_handoff_info.phy_base +
+                            DDR_PHY_MICRORESET_OFFSET,
+                            DDR_PHY_MICRORESET_RESET);
+
+               /* DDR freq set to support DDR4-3200 */
+               phy_init_engine(&ddr_handoff_info);
+
+               ret = dfi_init(&ddr_handoff_info);
+               if (ret)
+                       return ret;
+
+               ret = check_dfi_init(&ddr_handoff_info);
+               if (ret)
+                       return ret;
+
+               ret = trigger_sdram_init(&ddr_handoff_info);
+               if (ret)
+                       return ret;
+
+               ret = ddr_post_config(&ddr_handoff_info);
+               if (ret)
+                       return ret;
+
+               /* Restore user settings */
+               writel(user_backup[0], ddr_handoff_info.cntlr_base +
+                      DDR4_PWRCTL_OFFSET);
+
+               if (ddr_handoff_info.cntlr2_t == DDRTYPE_LPDDR4_0)
+                       setbits_le32(ddr_handoff_info.cntlr_base +
+                                    DDR4_INIT0_OFFSET, user_backup[1]);
+
+               if (ddr_handoff_info.cntlr2_t == DDRTYPE_LPDDR4_1) {
+                       /* Restore user settings */
+                       writel(user_backup_2nd[0],
+                              ddr_handoff_info.cntlr2_base +
+                              DDR4_PWRCTL_OFFSET);
+
+                       setbits_le32(ddr_handoff_info.cntlr2_base +
+                                    DDR4_INIT0_OFFSET, user_backup_2nd[1]);
+               }
+
+               /* Enable input traffic per port */
+               setbits_le32(ddr_handoff_info.cntlr_base + DDR4_PCTRL0_OFFSET,
+                            DDR4_PCTRL0_PORT_EN);
+
+               if (ddr_handoff_info.cntlr2_t == DDRTYPE_LPDDR4_1) {
+                       /* Enable input traffic per port */
+                       setbits_le32(ddr_handoff_info.cntlr2_base +
+                                    DDR4_PCTRL0_OFFSET, DDR4_PCTRL0_PORT_EN);
+               }
+
+               printf("DDR init success\n");
+       }
+
+       /* Get bank configuration from devicetree */
+       ret = fdtdec_decode_ram_size(gd->fdt_blob, NULL, 0, NULL,
+                                    (phys_size_t *)&gd->ram_size, &bd);
+       if (ret) {
+               debug("%s: Failed to decode memory node\n",  __func__);
+               return -1;
+       }
+
+       printf("DDR: %lld MiB\n", gd->ram_size >> 20);
+
+       priv->info.base = bd.bi_dram[0].start;
+       priv->info.size = gd->ram_size;
+
+       sdram_size_check(&bd);
+
+       sdram_set_firewall(&bd);
+
+       return 0;
+}
drivers/ddr/altera/sdram_soc64.c +70 -0
index cc656db97c..d6baac2410 100644
@@ -100,12 +100,14 @@ int emif_reset(struct altera_sdram_plat *plat)
        return 0;
 }
 
+#if !IS_ENABLED(CONFIG_TARGET_SOCFPGA_N5X)
 int poll_hmc_clock_status(void)
 {
        return wait_for_bit_le32((const void *)(socfpga_get_sysmgr_addr() +
                                 SYSMGR_SOC64_HMC_CLK),
                                 SYSMGR_HMC_CLK_STATUS_MSK, true, 1000, false);
 }
+#endif
 
 void sdram_clear_mem(phys_addr_t addr, phys_size_t size)
 {
@@ -249,11 +251,78 @@ phys_size_t sdram_calculate_size(struct altera_sdram_plat *plat)
        return size;
 }
 
+void sdram_set_firewall(struct bd_info *bd)
+{
+       u32 i;
+       phys_size_t value;
+       u32 lower, upper;
+
+       for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
+               if (!bd->bi_dram[i].size)
+                       continue;
+
+               value = bd->bi_dram[i].start;
+
+               /* Keep first 1MB of SDRAM memory region as secure region when
+                * using ATF flow, where the ATF code is located.
+                */
+               if (IS_ENABLED(CONFIG_SPL_ATF) && i == 0)
+                       value += SZ_1M;
+
+               /* Setting non-secure MPU region base and base extended */
+               lower = lower_32_bits(value);
+               upper = upper_32_bits(value);
+               FW_MPU_DDR_SCR_WRITEL(lower,
+                                     FW_MPU_DDR_SCR_MPUREGION0ADDR_BASE +
+                                     (i * 4 * sizeof(u32)));
+               FW_MPU_DDR_SCR_WRITEL(upper & 0xff,
+                                     FW_MPU_DDR_SCR_MPUREGION0ADDR_BASEEXT +
+                                     (i * 4 * sizeof(u32)));
+
+               /* Setting non-secure Non-MPU region base and base extended */
+               FW_MPU_DDR_SCR_WRITEL(lower,
+                                     FW_MPU_DDR_SCR_NONMPUREGION0ADDR_BASE +
+                                     (i * 4 * sizeof(u32)));
+               FW_MPU_DDR_SCR_WRITEL(upper & 0xff,
+                                     FW_MPU_DDR_SCR_NONMPUREGION0ADDR_BASEEXT +
+                                     (i * 4 * sizeof(u32)));
+
+               /* Setting non-secure MPU limit and limit extexded */
+               value = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
+
+               lower = lower_32_bits(value);
+               upper = upper_32_bits(value);
+
+               FW_MPU_DDR_SCR_WRITEL(lower,
+                                     FW_MPU_DDR_SCR_MPUREGION0ADDR_LIMIT +
+                                     (i * 4 * sizeof(u32)));
+               FW_MPU_DDR_SCR_WRITEL(upper & 0xff,
+                                     FW_MPU_DDR_SCR_MPUREGION0ADDR_LIMITEXT +
+                                     (i * 4 * sizeof(u32)));
+
+               /* Setting non-secure Non-MPU limit and limit extexded */
+               FW_MPU_DDR_SCR_WRITEL(lower,
+                                     FW_MPU_DDR_SCR_NONMPUREGION0ADDR_LIMIT +
+                                     (i * 4 * sizeof(u32)));
+               FW_MPU_DDR_SCR_WRITEL(upper & 0xff,
+                                     FW_MPU_DDR_SCR_NONMPUREGION0ADDR_LIMITEXT +
+                                     (i * 4 * sizeof(u32)));
+
+               FW_MPU_DDR_SCR_WRITEL(BIT(i) | BIT(i + 8),
+                                     FW_MPU_DDR_SCR_EN_SET);
+       }
+}
+
 static int altera_sdram_of_to_plat(struct udevice *dev)
 {
        struct altera_sdram_plat *plat = dev_get_plat(dev);
        fdt_addr_t addr;
 
+       /* These regs info are part of DDR handoff in bitstream */
+#if IS_ENABLED(CONFIG_TARGET_SOCFPGA_N5X)
+       return 0;
+#endif
+
        addr = dev_read_addr_index(dev, 0);
        if (addr == FDT_ADDR_T_NONE)
                return -EINVAL;
@@ -314,6 +383,7 @@ static struct ram_ops altera_sdram_ops = {
 static const struct udevice_id altera_sdram_ids[] = {
        { .compatible = "altr,sdr-ctl-s10" },
        { .compatible = "intel,sdr-ctl-agilex" },
+       { .compatible = "intel,sdr-ctl-n5x" },
        { /* sentinel */ }
 };
 
drivers/ddr/altera/sdram_soc64.h +1 -1
index 8af0afc410..7460f8c220 100644
@@ -180,6 +180,7 @@ int emif_reset(struct altera_sdram_plat *plat);
 int poll_hmc_clock_status(void);
 void sdram_clear_mem(phys_addr_t addr, phys_size_t size);
 void sdram_init_ecc_bits(struct bd_info *bd);
+void sdram_set_firewall(struct bd_info *bd);
 void sdram_size_check(struct bd_info *bd);
 phys_size_t sdram_calculate_size(struct altera_sdram_plat *plat);
 int sdram_mmr_init_full(struct udevice *dev);
--

2.19.0

#22 lore raw

RE: [v2 12/17] ddr: altera: Add SDRAM driver for Intel N5X device

Hi Ley Foon,

Quoted 69 lines

-----Original Message-----
From: Ley Foon Tan <[email protected]>
Sent: Friday, 28 May, 2021 5:41 PM
To: Lim, Elly Siew Chin <[email protected]>
Cc: ZY - u-boot <[email protected]>; Marek Vasut <[email protected]>; Tan, Ley Foon <[email protected]>; See, Chin Liang <[email protected]>; Simon Goldschmidt <[email protected]>; Chee, Tien Fong <[email protected]>; Westergreen, Dalon <[email protected]>; Simon Glass <[email protected]>; Gan, Yau Wai <[email protected]>
Subject: Re: [v2 12/17] ddr: altera: Add SDRAM driver for Intel N5X device

Quoted 38 lines · Siew Chin Lim

The DDR subsystem in Diamond Mesa is consisted of controller, PHY, memory reset manager and memory clock manager.

Configuration settings of controller, PHY and memory reset manager is come from DDR handoff data in bitstream, which contain the register base addresses and user settings from tool.

Configuration settings of memory clock manager is come from the HPS handoff data in bitstream, however the register base address is defined in device tree.

The calibration is fully done in HPS, which requires IMEM and DMEM binaries loading to PHY SRAM for running this calibration, both IMEM and DMEM binaries are also part of bitstream, this bitstream would be loaded to OCRAM by SDM, and configured by DDR driver.

---
v2:
- Move is_ddr_init_skipped and its helper functions to DDR driver and converted function to positive checking
- Using GENMASK() macro
- Fixed typo
- Return status of subfunction
- Changed dm to n5x

---
 arch/arm/mach-socfpga/include/mach/firewall.h |    6 +
 .../include/mach/system_manager_soc64.h       |   10 +-
 drivers/ddr/altera/Makefile                   |    3 +-
 drivers/ddr/altera/sdram_n5x.c                | 2299 +++++++++++++++++
 drivers/ddr/altera/sdram_soc64.c              |   70 +
 drivers/ddr/altera/sdram_soc64.h              |    1 +
 6 files changed, 2387 insertions(+), 2 deletions(-)
 create mode 100644 drivers/ddr/altera/sdram_n5x.c

[..]

drivers/ddr/altera/Makefile line 7

Quoted 10 lines
drivers/ddr/altera/Makefile +1 -1
index 39dfee5d5a..9fa5d85a27 100644
@@ -4,11 +4,12 @@
 # Wolfgang Denk, DENX Software Engineering, [email protected].
 #
 # (C) Copyright 2010, Thomas Chou <[email protected]>
-# Copyright (C) 2014 Altera Corporation <www.altera.com>
+# Copyright (C) 2014-2021 Altera Corporation <www.altera.com>

Intel copyright

Quoted 4 lines

[...]

Quoted 1 line

+#include <common.h>

Sort include header.

Okay.

Quoted 279 lines
Quoted 15 lines
drivers/ddr/altera/Makefile +14 -0
+#include <asm/arch/firewall.h>
+#include <asm/arch/handoff_soc64.h>
+#include <asm/arch/misc.h>
+#include <asm/arch/reset_manager.h>
+#include <asm/arch/system_manager.h>
+#include <asm/global_data.h>
+#include <asm/io.h>
+#include <clk.h>
+#include <div64.h>
+#include <dm.h>
+#include <errno.h>
+#include <fdtdec.h>
+#include <hang.h>
+#include <linux/err.h>

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+#include <linux/sizes.h>
+#include <ram.h>
+#include <reset.h>
+#include "sdram_soc64.h"
+#include <wait_bit.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* MPFE NOC registers */
+#define FPGA2SDRAM_MGR_MAIN_SIDEBANDMGR_FLAGOUTSET0

0xF8024050

Quoted 253 lines
drivers/ddr/altera/Makefile +253 -0
+
+/* Memory reset manager */
+#define MEM_RST_MGR_STATUS     0x8
+
+/* Register and bit in memory reset manager */
+#define MEM_RST_MGR_STATUS_RESET_COMPLETE      BIT(0)
+#define MEM_RST_MGR_STATUS_PWROKIN_STATUS      BIT(1)
+#define MEM_RST_MGR_STATUS_CONTROLLER_RST      BIT(2)
+#define MEM_RST_MGR_STATUS_AXI_RST             BIT(3)
+
+#define TIMEOUT_200MS     200
+#define TIMEOUT_5000MS    5000
+
+/* DDR4 umctl2 */
+#define DDR4_MSTR_OFFSET               0x0
+#define DDR4_FREQ_RATIO                        BIT(22)
+
+#define DDR4_STAT_OFFSET               0x4
+#define DDR4_STAT_SELFREF_TYPE         GENMASK(5, 4)
+#define DDR4_STAT_SELFREF_TYPE_SHIFT   4
+#define DDR4_STAT_OPERATING_MODE       GENMASK(2, 0)
+
+#define DDR4_MRCTRL0_OFFSET            0x10
+#define DDR4_MRCTRL0_MR_TYPE           BIT(0)
+#define DDR4_MRCTRL0_MPR_EN            BIT(1)
+#define DDR4_MRCTRL0_MR_RANK           GENMASK(5, 4)
+#define DDR4_MRCTRL0_MR_RANK_SHIFT     4
+#define DDR4_MRCTRL0_MR_ADDR           GENMASK(15, 12)
+#define DDR4_MRCTRL0_MR_ADDR_SHIFT     12
+#define DDR4_MRCTRL0_MR_WR             BIT(31)
+
+#define DDR4_MRCTRL1_OFFSET            0x14
+#define DDR4_MRCTRL1_MR_DATA           0x3FFFF
+
+#define DDR4_MRSTAT_OFFSET             0x18
+#define DDR4_MRSTAT_MR_WR_BUSY         BIT(0)
+
+#define DDR4_MRCTRL2_OFFSET            0x1C
+
+#define DDR4_PWRCTL_OFFSET                     0x30
+#define DDR4_PWRCTL_SELFREF_EN                 BIT(0)
+#define DDR4_PWRCTL_POWERDOWN_EN               BIT(1)
+#define DDR4_PWRCTL_EN_DFI_DRAM_CLK_DISABLE    BIT(3)
+#define DDR4_PWRCTL_SELFREF_SW                 BIT(5)
+
+#define DDR4_PWRTMG_OFFSET             0x34
+#define DDR4_HWLPCTL_OFFSET            0x38
+#define DDR4_RFSHCTL0_OFFSET           0x50
+#define DDR4_RFSHCTL1_OFFSET           0x54
+
+#define DDR4_RFSHCTL3_OFFSET                   0x60
+#define DDR4_RFSHCTL3_DIS_AUTO_REFRESH         BIT(0)
+#define DDR4_RFSHCTL3_REFRESH_MODE             GENMASK(6, 4)
+#define DDR4_RFSHCTL3_REFRESH_MODE_SHIFT       4
+
+#define DDR4_ECCCFG0_OFFSET            0x70
+#define DDR4_ECC_MODE                  GENMASK(2, 0)
+#define DDR4_DIS_SCRUB                 BIT(4)
+#define LPDDR4_ECCCFG0_ECC_REGION_MAP_GRANU_SHIFT      30
+#define LPDDR4_ECCCFG0_ECC_REGION_MAP_SHIFT    8
+
+#define DDR4_ECCCFG1_OFFSET            0x74
+#define LPDDR4_ECCCFG1_ECC_REGIONS_PARITY_LOCK BIT(4)
+
+#define DDR4_CRCPARCTL0_OFFSET                 0xC0
+#define DDR4_CRCPARCTL0_DFI_ALERT_ERR_INIT_CLR BIT(1)
+
+#define DDR4_CRCPARCTL1_OFFSET                 0xC4
+#define DDR4_CRCPARCTL1_CRC_PARITY_RETRY_ENABLE        BIT(8)
+#define DDR4_CRCPARCTL1_ALERT_WAIT_FOR_SW      BIT(9)
+
+#define DDR4_CRCPARSTAT_OFFSET                 0xCC
+#define DDR4_CRCPARSTAT_DFI_ALERT_ERR_INT      BIT(16)
+#define DDR4_CRCPARSTAT_DFI_ALERT_ERR_FATL_INT BIT(17)
+#define DDR4_CRCPARSTAT_DFI_ALERT_ERR_NO_SW    BIT(19)
+#define DDR4_CRCPARSTAT_CMD_IN_ERR_WINDOW      BIT(29)
+
+#define DDR4_INIT0_OFFSET                      0xD0
+#define DDR4_INIT0_SKIP_RAM_INIT               GENMASK(31, 30)
+
+#define DDR4_RANKCTL_OFFSET                    0xF4
+#define DDR4_RANKCTL_DIFF_RANK_RD_GAP          GENMASK(7, 4)
+#define DDR4_RANKCTL_DIFF_RANK_WR_GAP          GENMASK(11, 8)
+#define DDR4_RANKCTL_DIFF_RANK_RD_GAP_MSB      BIT(24)
+#define DDR4_RANKCTL_DIFF_RANK_WR_GAP_MSB      BIT(26)
+#define DDR4_RANKCTL_DIFF_RANK_RD_GAP_SHIFT    4
+#define DDR4_RANKCTL_DIFF_RANK_WR_GAP_SHIFT    8
+#define DDR4_RANKCTL_DIFF_RANK_RD_GAP_MSB_SHIFT        24
+#define DDR4_RANKCTL_DIFF_RANK_WR_GAP_MSB_SHIFT        26
+
+#define DDR4_RANKCTL1_OFFSET   0xF8
+#define DDR4_RANKCTL1_WR2RD_DR GENMASK(5, 0)
+
+#define DDR4_DRAMTMG2_OFFSET   0x108
+#define DDR4_DRAMTMG2_WR2RD    GENMASK(5, 0)
+#define DDR4_DRAMTMG2_RD2WR    GENMASK(13, 8)
+#define DDR4_DRAMTMG2_RD2WR_SHIFT      8
+
+#define DDR4_DRAMTMG9_OFFSET   0x124
+#define DDR4_DRAMTMG9_W2RD_S   GENMASK(5, 0)
+
+#define DDR4_DFITMG1_OFFSET    0x194
+#define DDR4_DFITMG1_DFI_T_WRDATA_DELAY        GENMASK(20, 16)
+#define DDR4_DFITMG1_DFI_T_WRDATA_SHIFT        16
+
+#define DDR4_DFIMISC_OFFSET                    0x1B0
+#define DDR4_DFIMISC_DFI_INIT_COMPLETE_EN      BIT(0)
+#define DDR4_DFIMISC_DFI_INIT_START            BIT(5)
+
+#define DDR4_DFISTAT_OFFSET            0x1BC
+#define DDR4_DFI_INIT_COMPLETE         BIT(0)
+
+#define DDR4_DBG0_OFFSET               0x300
+
+#define DDR4_DBG1_OFFSET               0x304
+#define DDR4_DBG1_DISDQ                        BIT(0)
+#define DDR4_DBG1_DIS_HIF              BIT(1)
+
+#define DDR4_DBGCAM_OFFSET                     0x308
+#define DDR4_DBGCAM_DBG_RD_Q_EMPTY             BIT(25)
+#define DDR4_DBGCAM_DBG_WR_Q_EMPTY             BIT(26)
+#define DDR4_DBGCAM_RD_DATA_PIPELINE_EMPTY     BIT(28)
+#define DDR4_DBGCAM_WR_DATA_PIPELINE_EMPTY     BIT(29)
+
+#define DDR4_SWCTL_OFFSET              0x320
+#define DDR4_SWCTL_SW_DONE             BIT(0)
+
+#define DDR4_SWSTAT_OFFSET             0x324
+#define DDR4_SWSTAT_SW_DONE_ACK                BIT(0)
+
+#define DDR4_PSTAT_OFFSET              0x3FC
+#define DDR4_PSTAT_RD_PORT_BUSY_0      BIT(0)
+#define DDR4_PSTAT_WR_PORT_BUSY_0      BIT(16)
+
+#define DDR4_PCTRL0_OFFSET             0x490
+#define DDR4_PCTRL0_PORT_EN            BIT(0)
+
+#define DDR4_SBRCTL_OFFSET             0xF24
+#define DDR4_SBRCTL_SCRUB_INTERVAL     0x1FFF00
+#define DDR4_SBRCTL_SCRUB_EN           BIT(0)
+#define DDR4_SBRCTL_SCRUB_WRITE                BIT(2)
+#define DDR4_SBRCTL_SCRUB_BURST_1      BIT(4)
+
+#define DDR4_SBRSTAT_OFFSET            0xF28
+#define DDR4_SBRSTAT_SCRUB_BUSY BIT(0)
+#define DDR4_SBRSTAT_SCRUB_DONE BIT(1)
+
+#define DDR4_SBRWDATA0_OFFSET          0xF2C
+#define DDR4_SBRWDATA1_OFFSET          0xF30
+#define DDR4_SBRSTART0_OFFSET          0xF38
+#define DDR4_SBRSTART1_OFFSET          0xF3C
+#define DDR4_SBRRANGE0_OFFSET          0xF40
+#define DDR4_SBRRANGE1_OFFSET          0xF44
+
+/* DDR PHY */
+#define DDR_PHY_TXODTDRVSTREN_B0_P0            0x2009A
+#define DDR_PHY_RXPBDLYTG0_R0                  0x200D0
+#define DDR_PHY_DBYTE0_TXDQDLYTG0_U0_P0                0x201A0
+
+#define DDR_PHY_DBYTE0_TXDQDLYTG0_U1_P0                0x203A0
+#define DDR_PHY_DBYTE1_TXDQDLYTG0_U0_P0                0x221A0
+#define DDR_PHY_DBYTE1_TXDQDLYTG0_U1_P0                0x223A0
+#define DDR_PHY_TXDQDLYTG0_COARSE_DELAY                GENMASK(9, 6)
+#define DDR_PHY_TXDQDLYTG0_COARSE_DELAY_SHIFT  6
+
+#define DDR_PHY_CALRATE_OFFSET                 0x40110
+#define DDR_PHY_CALZAP_OFFSET                  0x40112
+#define DDR_PHY_SEQ0BDLY0_P0_OFFSET            0x40016
+#define DDR_PHY_SEQ0BDLY1_P0_OFFSET            0x40018
+#define DDR_PHY_SEQ0BDLY2_P0_OFFSET            0x4001A
+#define DDR_PHY_SEQ0BDLY3_P0_OFFSET            0x4001C
+
+#define DDR_PHY_MEMRESETL_OFFSET               0x400C0
+#define DDR_PHY_MEMRESETL_VALUE                        BIT(0)
+#define DDR_PHY_PROTECT_MEMRESET               BIT(1)
+
+#define DDR_PHY_CALBUSY_OFFSET                 0x4012E
+#define DDR_PHY_CALBUSY                                BIT(0)
+
+#define DDR_PHY_TRAIN_IMEM_OFFSET              0xA0000
+#define DDR_PHY_TRAIN_DMEM_OFFSET              0xA8000
+
+#define DMEM_MB_CDD_RR_1_0_OFFSET              0xA802C
+#define DMEM_MB_CDD_RR_0_1_OFFSET              0xA8030
+#define DMEM_MB_CDD_WW_1_0_OFFSET              0xA8038
+#define DMEM_MB_CDD_WW_0_1_OFFSET              0xA803C
+#define DMEM_MB_CDD_RW_1_1_OFFSET              0xA8046
+#define DMEM_MB_CDD_RW_1_0_OFFSET              0xA8048
+#define DMEM_MB_CDD_RW_0_1_OFFSET              0xA804A
+#define DMEM_MB_CDD_RW_0_0_OFFSET              0xA804C
+
+#define DMEM_MB_CDD_CHA_RR_1_0_OFFSET          0xA8026
+#define DMEM_MB_CDD_CHA_RR_0_1_OFFSET          0xA8026
+#define DMEM_MB_CDD_CHB_RR_1_0_OFFSET          0xA8058
+#define DMEM_MB_CDD_CHB_RR_0_1_OFFSET          0xA805A
+#define DMEM_MB_CDD_CHA_WW_1_0_OFFSET          0xA8030
+#define DMEM_MB_CDD_CHA_WW_0_1_OFFSET          0xA8030
+#define DMEM_MB_CDD_CHB_WW_1_0_OFFSET          0xA8062
+#define DMEM_MB_CDD_CHB_WW_0_1_OFFSET          0xA8064
+
+#define DMEM_MB_CDD_CHA_RW_1_1_OFFSET          0xA8028
+#define DMEM_MB_CDD_CHA_RW_1_0_OFFSET          0xA8028
+#define DMEM_MB_CDD_CHA_RW_0_1_OFFSET          0xA802A
+#define DMEM_MB_CDD_CHA_RW_0_0_OFFSET          0xA802A
+
+#define DMEM_MB_CDD_CHB_RW_1_1_OFFSET          0xA805A
+#define DMEM_MB_CDD_CHB_RW_1_0_OFFSET          0xA805C
+#define DMEM_MB_CDD_CHB_RW_0_1_OFFSET          0xA805c
+#define DMEM_MB_CDD_CHB_RW_0_0_OFFSET          0xA805E
+
+#define DDR_PHY_SEQ0DISABLEFLAG0_OFFSET                0x120018
+#define DDR_PHY_SEQ0DISABLEFLAG1_OFFSET                0x12001A
+#define DDR_PHY_SEQ0DISABLEFLAG2_OFFSET                0x12001C
+#define DDR_PHY_SEQ0DISABLEFLAG3_OFFSET                0x12001E
+#define DDR_PHY_SEQ0DISABLEFLAG4_OFFSET                0x120020
+#define DDR_PHY_SEQ0DISABLEFLAG5_OFFSET                0x120022
+#define DDR_PHY_SEQ0DISABLEFLAG6_OFFSET                0x120024
+#define DDR_PHY_SEQ0DISABLEFLAG7_OFFSET                0x120026
+
+#define DDR_PHY_UCCLKHCLKENABLES_OFFSET                0x180100
+#define DDR_PHY_UCCLKHCLKENABLES_UCCLKEN       BIT(0)
+#define DDR_PHY_UCCLKHCLKENABLES_HCLKEN                BIT(1)
+
+#define DDR_PHY_UCTWRITEPROT_OFFSET            0x180066
+#define DDR_PHY_UCTWRITEPROT                   BIT(0)
+
+#define DDR_PHY_APBONLY0_OFFSET                        0x1A0000
+#define DDR_PHY_MICROCONTMUXSEL                        BIT(0)
+
+#define DDR_PHY_UCTSHADOWREGS_OFFSET                   0x1A0008
+#define DDR_PHY_UCTSHADOWREGS_UCTWRITEPROTESHADOW      BIT(0)
+
+#define DDR_PHY_DCTWRITEPROT_OFFSET            0x1A0062
+#define DDR_PHY_DCTWRITEPROT                   BIT(0)
+
+#define DDR_PHY_UCTWRITEONLYSHADOW_OFFSET      0x1A0064
+#define DDR_PHY_UCTDATWRITEONLYSHADOW_OFFSET   0x1A0068
+
+#define DDR_PHY_MICRORESET_OFFSET              0x1A0132
+#define DDR_PHY_MICRORESET_STALL               BIT(0)
+#define DDR_PHY_MICRORESET_RESET               BIT(3)
+
+#define DDR_PHY_TXODTDRVSTREN_B0_P1            0x22009A
+
+/* For firmware training */
+#define HW_DBG_TRACE_CONTROL_OFFSET    0x18
+#define FW_TRAINING_COMPLETED_STAT     0x07
+#define FW_TRAINING_FAILED_STAT                0xFF
+#define FW_COMPLETION_MSG_ONLY_MODE    0xFF
+#define FW_STREAMING_MSG_ID            0x08
+#define GET_LOWHW_DATA(x)              ((x) & 0xFFFF)
+#define GET_LOWB_DATA(x)               ((x) & 0xFF)
+#define GET_HIGHB_DATA(x)              (((x) & 0xFF00) >> 8)
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 7 lines
drivers/ddr/altera/Makefile +7 -0
+
+/* Operating mode */
+#define INIT_OPM                       0x000
+#define NORMAL_OPM                     0x001
+#define PWR_D0WN_OPM                   0x010
+#define SELF_SELFREF_OPM               0x011
+#define DDR4_DEEP_PWR_DOWN_OPM         0x100

Use prefix OPM_xxx

Okay.

Quoted 178 lines
Quoted 90 lines
drivers/ddr/altera/Makefile +89 -0
+
+/* Refresh mode */
+#define FIXED_1X               0
+#define FIXED_2X               BIT(0)
+#define FIXED_4X               BIT(4)
+
+/* Address of mode register */
+#define MR0    0x0000
+#define MR1    0x0001
+#define MR2    0x0010
+#define MR3    0x0011
+#define MR4    0x0100
+#define MR5    0x0101
+#define MR6    0x0110
+#define MR7    0x0111
+
+/* MR rank */
+#define RANK0          0x1
+#define RANK1          0x2
+#define ALL_RANK       0x3
+
+#define MR5_BIT4       BIT(4)
+
+/* Value for ecc_region_map */
+#define ALL_PROTECTED  0x7F
+
+/* Region size for ECCCFG0.ecc_region_map */
+enum region_size {
+       ONE_EIGHT,
+       ONE_SIXTEENTH,
+       ONE_THIRTY_SECOND,
+       ONE_SIXTY_FOURTH
+};
+
+enum ddr_type {
+       DDRTYPE_LPDDR4_0,
+       DDRTYPE_LPDDR4_1,
+       DDRTYPE_DDR4,
+       DDRTYPE_UNKNOWN
+};
+
+/* Reset type */
+enum reset_type {
+       POR_RESET,
+       WARM_RESET,
+       COLD_RESET
+};
+
+/* DDR handoff structure */
+struct ddr_handoff {
+       /* Memory reset manager base */
+       phys_addr_t mem_reset_base;
+
+       /* First controller attributes */
+       phys_addr_t cntlr_handoff_base;
+       phys_addr_t cntlr_base;
+       size_t cntlr_total_length;
+       enum ddr_type cntlr_t;
+       size_t cntlr_handoff_length;
+
+       /* Second controller attributes*/
+       phys_addr_t cntlr2_handoff_base;
+       phys_addr_t cntlr2_base;
+       size_t cntlr2_total_length;
+       enum ddr_type cntlr2_t;
+       size_t cntlr2_handoff_length;
+
+       /* PHY attributes */
+       phys_addr_t phy_handoff_base;
+       phys_addr_t phy_base;
+       size_t phy_total_length;
+       size_t phy_handoff_length;
+
+       /* PHY engine attributes */
+       phys_addr_t phy_engine_handoff_base;
+       size_t phy_engine_total_length;
+       size_t phy_engine_handoff_length;
+
+       /* Calibration attributes */
+       phys_addr_t train_imem_base;
+       phys_addr_t train_dmem_base;
+       size_t train_imem_length;
+       size_t train_dmem_length;
+};
+
+/* Message mode */
+enum message_mode {
+       MAJOR_MESSAGE,
+       STREAMING_MESSAGE

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+};
+
+static int clr_ca_parity_error_status(phys_addr_t umctl2_base)
+{
+       int ret;
+
+       debug("%s: Clear C/A parity error status in MR5[4]\n", __func__);
+
+       /* Set mode register MRS */
+       clrbits_le32(umctl2_base + DDR4_MRCTRL0_OFFSET,

DDR4_MRCTRL0_MPR_EN);

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+
+       /* Set mode register to write operation */
+       setbits_le32(umctl2_base + DDR4_MRCTRL0_OFFSET,

DDR4_MRCTRL0_MR_TYPE);

Quoted 6 lines
drivers/ddr/altera/Makefile +6 -0
+
+       /* Set the address of mode rgister to 0x101(MR5) */
+       setbits_le32(umctl2_base + DDR4_MRCTRL0_OFFSET,
+                    (MR5 << DDR4_MRCTRL0_MR_ADDR_SHIFT) &
+                    DDR4_MRCTRL0_MR_ADDR);
+

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+       /* Set MR rank to rank 1 */
+       setbits_le32(umctl2_base + DDR4_MRCTRL0_OFFSET,
+                    (RANK1 << DDR4_MRCTRL0_MR_RANK_SHIFT) &
+                    DDR4_MRCTRL0_MR_RANK);
+
+       /* Clear C/A parity error status in MR5[4] */
+       clrbits_le32(umctl2_base + DDR4_MRCTRL1_OFFSET, MR5_BIT4);
+
+       /* Trigger mode register read or write operation */
+       setbits_le32(umctl2_base + DDR4_MRCTRL0_OFFSET,

DDR4_MRCTRL0_MR_WR);

Quoted 56 lines
drivers/ddr/altera/Makefile +56 -0
+
+       /* Wait for retry done */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_MRSTAT_OFFSET), DDR4_MRSTAT_MR_WR_BUSY,
+                               false, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" no outstanding MR transaction\n");
+               return ret;
+       }
+
+       return 0;
+}
+
+static int ddr_retry_software_sequence(phys_addr_t umctl2_base)
+{
+       u32 value;
+       int ret;
+
+       /* Check software can perform MRS/MPR/PDA? */
+       value = readl(umctl2_base + DDR4_CRCPARSTAT_OFFSET) &
+                     DDR4_CRCPARSTAT_DFI_ALERT_ERR_NO_SW;
+
+       if (value) {
+               /* Clear interrupt bit for DFI alert error */
+               setbits_le32(umctl2_base + DDR4_CRCPARCTL0_OFFSET,
+                            DDR4_CRCPARCTL0_DFI_ALERT_ERR_INIT_CLR);
+       }
+
+       debug("%s: Software can perform MRS/MPR/PDA\n", __func__);
+
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_MRSTAT_OFFSET),
+                               DDR4_MRSTAT_MR_WR_BUSY,
+                               false, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" no outstanding MR transaction\n");
+               return ret;
+       }
+
+       ret = clr_ca_parity_error_status(umctl2_base);
+       if (ret)
+               return ret;
+
+       if (!value) {
+               /* Clear interrupt bit for DFI alert error */
+               setbits_le32(umctl2_base + DDR4_CRCPARCTL0_OFFSET,
+                            DDR4_CRCPARCTL0_DFI_ALERT_ERR_INIT_CLR);
+       }
+
+       return 0;
+}
+
+static int ensure_retry_procedure_complete(phys_addr_t umctl2_base)
+{
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 7 lines
drivers/ddr/altera/Makefile +7 -0
+       u32 value;
+       u32 start = get_timer(0);
+       int ret;
+
+       /* Check parity/crc/error window is emptied ? */
+       value = readl(umctl2_base + DDR4_CRCPARSTAT_OFFSET) &
+                     DDR4_CRCPARSTAT_CMD_IN_ERR_WINDOW;

Can simplify the code with do...while loop.

Okay.

Quoted 262 lines
Quoted 53 lines
drivers/ddr/altera/Makefile +52 -0
+
+       /* Polling until parity/crc/error window is emptied */
+       while (value) {
+               if (get_timer(start) > TIMEOUT_200MS) {
+                       debug("%s: Timeout while waiting for",
+                             __func__);
+                       debug(" parity/crc/error window empty\n");
+                       return -ETIMEDOUT;
+               }
+
+               /* Check software intervention is enabled? */
+               value = readl(umctl2_base + DDR4_CRCPARCTL1_OFFSET) &
+                             DDR4_CRCPARCTL1_ALERT_WAIT_FOR_SW;
+               if (value) {
+                       debug("%s: Software intervention is enabled\n",
+                             __func__);
+
+                       /* Check dfi alert error interrupt is set? */
+                       value = readl(umctl2_base + DDR4_CRCPARSTAT_OFFSET) &
+                                     DDR4_CRCPARSTAT_DFI_ALERT_ERR_INT;
+
+                       if (value) {
+                               ret = ddr_retry_software_sequence(umctl2_base);
+                               debug("%s: DFI alert error interrupt ",
+                                     __func__);
+                               debug("is set\n");
+
+                               if (ret)
+                                       return ret;
+                       }
+
+                       /*
+                        * Check fatal parity error interrupt is set?
+                        */
+                       value = readl(umctl2_base + DDR4_CRCPARSTAT_OFFSET) &
+                                     DDR4_CRCPARSTAT_DFI_ALERT_ERR_FATL_INT;
+                       if (value) {
+                               printf("%s: Fatal parity error  ",
+                                      __func__);
+                               printf("interrupt is set, Hang it!!\n");
+                               hang();
+                       }
+               }
+
+               value = readl(umctl2_base + DDR4_CRCPARSTAT_OFFSET) &
+                             DDR4_CRCPARSTAT_CMD_IN_ERR_WINDOW;
+
+               udelay(1);
+               WATCHDOG_RESET();
+       }
+
+       return 0;

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+}
+
+static int enable_quasi_dynamic_reg_grp3(phys_addr_t umctl2_base,
+                                        enum ddr_type umctl2_type)
+{
+       u32 i, value, backup;
+       int ret = 0;
+
+       /* Disable input traffic per port */
+       clrbits_le32(umctl2_base + DDR4_PCTRL0_OFFSET,

DDR4_PCTRL0_PORT_EN);

Quoted 80 lines
drivers/ddr/altera/Makefile +80 -0
+
+       /* Polling AXI port until idle */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_PSTAT_OFFSET),
+                               DDR4_PSTAT_WR_PORT_BUSY_0 |
+                               DDR4_PSTAT_RD_PORT_BUSY_0, false,
+                               TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" controller idle\n");
+               return ret;
+       }
+
+       /* Backup user setting */
+       backup = readl(umctl2_base + DDR4_DBG1_OFFSET);
+
+       /* Disable input traffic to the controller */
+       setbits_le32(umctl2_base + DDR4_DBG1_OFFSET, DDR4_DBG1_DIS_HIF);
+
+       /*
+        * Ensure CAM/data pipelines are empty.
+        * Poll until CAM/data pipelines are set at least twice,
+        * timeout at 200ms
+        */
+       for (i = 0; i < 2; i++) {
+               ret = wait_for_bit_le32((const void *)(umctl2_base +
+                                       DDR4_DBGCAM_OFFSET),
+                                       DDR4_DBGCAM_WR_DATA_PIPELINE_EMPTY |
+                                       DDR4_DBGCAM_RD_DATA_PIPELINE_EMPTY |
+                                       DDR4_DBGCAM_DBG_WR_Q_EMPTY |
+                                       DDR4_DBGCAM_DBG_RD_Q_EMPTY, true,
+                                       TIMEOUT_200MS, false);
+               if (ret) {
+                       debug("%s: loop(%u): Timeout while waiting for",
+                             __func__, i + 1);
+                       debug(" CAM/data pipelines are empty\n");
+
+                       goto out;
+               }
+       }
+
+       if (umctl2_type == DDRTYPE_DDR4) {
+               /* Check DDR4 retry is enabled ? */
+               value = readl(umctl2_base + DDR4_CRCPARCTL1_OFFSET) &
+                             DDR4_CRCPARCTL1_CRC_PARITY_RETRY_ENABLE;
+
+               if (value) {
+                       debug("%s: DDR4 retry is enabled\n", __func__);
+
+                       ret = ensure_retry_procedure_complete(umctl2_base);
+                       if (ret) {
+                               debug("%s: Timeout while waiting for",
+                                     __func__);
+                               debug(" retry procedure complete\n");
+
+                               goto out;
+                       }
+               }
+       }
+
+       debug("%s: Quasi-dynamic group 3 registers are enabled\n", __func__);
+
+out:
+       /* Restore user setting */
+       writel(backup, umctl2_base + DDR4_DBG1_OFFSET);
+
+       return ret;
+}
+
+static enum ddr_type get_ddr_type(phys_addr_t ddr_type_location)
+{
+       u32 ddr_type_magic = readl(ddr_type_location);
+
+       if (ddr_type_magic == SOC64_HANDOFF_DDR_UMCTL2_DDR4_TYPE)
+               return DDRTYPE_DDR4;
+
+       if (ddr_type_magic == SOC64_HANDOFF_DDR_UMCTL2_LPDDR4_0_TYPE)
+               return DDRTYPE_LPDDR4_0;
+
+       if (ddr_type_magic == SOC64_HANDOFF_DDR_UMCTL2_LPDDR4_1_TYPE)

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+               return DDRTYPE_LPDDR4_1;
+
+       return DDRTYPE_UNKNOWN;
+}
+
+static void use_lpddr4_interleaving(bool set)
+{
+       if (set) {
+               printf("Starting LPDDR4 interleaving configuration ...\n");
+

setbits_le32(FPGA2SDRAM_MGR_MAIN_SIDEBANDMGR_FLAGOUTSET0,

drivers/ddr/altera/Makefile

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+                            BIT(5));
+       } else {
+               printf("Starting LPDDR4 non-interleaving configuration ...\n");
+

clrbits_le32(FPGA2SDRAM_MGR_MAIN_SIDEBANDMGR_FLAGOUTSET0,

drivers/ddr/altera/Makefile

Quoted 9 lines
drivers/ddr/altera/Makefile +9 -0
+                            BIT(5));
+       }
+}
+
+static void use_ddr4(enum ddr_type type)
+{
+       if (type == DDRTYPE_DDR4) {
+               printf("Starting DDR4 configuration ...\n");
+               setbits_le32(socfpga_get_sysmgr_addr() +

SYSMGR_SOC64_DDR_MODE,

drivers/ddr/altera/Makefile

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+                            SYSMGR_SOC64_DDR_MODE_MSK);
+       } else if (type == DDRTYPE_LPDDR4_0)  {
+               printf("Starting LPDDR4 configuration ...\n");
+               clrbits_le32(socfpga_get_sysmgr_addr() +

SYSMGR_SOC64_DDR_MODE,

Quoted 25 lines
drivers/ddr/altera/Makefile +25 -0
+                            SYSMGR_SOC64_DDR_MODE_MSK);
+
+               use_lpddr4_interleaving(false);
+       }
+}
+
+static int scrubber_ddr_config(phys_addr_t umctl2_base,
+                              enum ddr_type umctl2_type)
+{
+       u32 backup[9];
+       int ret;
+
+       /* Reset to default value, prevent scrubber stop due to lower power */
+       writel(0, umctl2_base + DDR4_PWRCTL_OFFSET);
+
+       /* Backup user settings */
+       backup[0] = readl(umctl2_base + DDR4_SBRCTL_OFFSET);
+       backup[1] = readl(umctl2_base + DDR4_SBRWDATA0_OFFSET);
+       backup[2] = readl(umctl2_base + DDR4_SBRSTART0_OFFSET);
+       if (umctl2_type == DDRTYPE_DDR4) {
+               backup[3] = readl(umctl2_base + DDR4_SBRWDATA1_OFFSET);
+               backup[4] = readl(umctl2_base + DDR4_SBRSTART1_OFFSET);
+       }
+       backup[5] = readl(umctl2_base + DDR4_SBRRANGE0_OFFSET);
+       backup[6] = readl(umctl2_base + DDR4_SBRRANGE1_OFFSET);

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+       backup[7] = readl(umctl2_base + DDR4_ECCCFG0_OFFSET);
+       backup[8] = readl(umctl2_base + DDR4_ECCCFG1_OFFSET);
+
+       if (umctl2_type != DDRTYPE_DDR4) {
+               /* Lock ECC region, ensure this regions is not being accessed */
+               setbits_le32(umctl2_base + DDR4_ECCCFG1_OFFSET,
+                            LPDDR4_ECCCFG1_ECC_REGIONS_PARITY_LOCK);
+       }
+       /* Disable input traffic per port */
+       clrbits_le32(umctl2_base + DDR4_PCTRL0_OFFSET,

DDR4_PCTRL0_PORT_EN);

drivers/ddr/altera/Makefile

Quoted 2 lines
drivers/ddr/altera/Makefile +2 -0
+       /* Disables scrubber */
+       clrbits_le32(umctl2_base + DDR4_SBRCTL_OFFSET,

DDR4_SBRCTL_SCRUB_EN);

Quoted 9 lines
drivers/ddr/altera/Makefile +9 -0
+       /* Polling all scrub writes data have been sent */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SBRSTAT_OFFSET), DDR4_SBRSTAT_SCRUB_BUSY,
+                               false, TIMEOUT_5000MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" sending all scrub data\n");
+               return ret;
+       }

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+
+       /* LPDDR4 supports inline ECC only */
+       if (umctl2_type != DDRTYPE_DDR4) {
+               /*
+                * Setting all regions for protected, this is required for
+                * srubber to init whole LPDDR4 expect ECC region
+                */
+               writel(((ONE_EIGHT <<
+                      LPDDR4_ECCCFG0_ECC_REGION_MAP_GRANU_SHIFT) |
+                      (ALL_PROTECTED <<

LPDDR4_ECCCFG0_ECC_REGION_MAP_SHIFT)),

Quoted 9 lines
drivers/ddr/altera/Makefile +9 -0
+                      umctl2_base + DDR4_ECCCFG0_OFFSET);
+       }
+
+       /* Scrub_burst = 1, scrub_mode = 1(performs writes) */
+       writel(DDR4_SBRCTL_SCRUB_BURST_1 | DDR4_SBRCTL_SCRUB_WRITE,
+              umctl2_base + DDR4_SBRCTL_OFFSET);
+
+       /* Zeroing whole DDR */
+       writel(0, umctl2_base + DDR4_SBRWDATA0_OFFSET);

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+       writel(0, umctl2_base + DDR4_SBRSTART0_OFFSET);
+       if (umctl2_type == DDRTYPE_DDR4) {
+               writel(0, umctl2_base + DDR4_SBRWDATA1_OFFSET);
+               writel(0, umctl2_base + DDR4_SBRSTART1_OFFSET);
+       }
+       writel(0, umctl2_base + DDR4_SBRRANGE0_OFFSET);
+       writel(0, umctl2_base + DDR4_SBRRANGE1_OFFSET);
+
+       /* Enables scrubber */
+       setbits_le32(umctl2_base + DDR4_SBRCTL_OFFSET,

DDR4_SBRCTL_SCRUB_EN);

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+       /* Polling all scrub writes commands have been sent */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SBRSTAT_OFFSET), DDR4_SBRSTAT_SCRUB_DONE,
+                               true, TIMEOUT_5000MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" sending all scrub commands\n");
+               return ret;
Quoted 1 line

Need restore user settings before return?

No need because this is considered error, and system would hang for watchdog to kick in.

Quoted 11 lines

drivers/ddr/altera/Makefile

Quoted 11 lines
drivers/ddr/altera/Makefile +10 -0
+       }
+
+       /* Polling all scrub writes data have been sent */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SBRSTAT_OFFSET), DDR4_SBRSTAT_SCRUB_BUSY,
+                               false, TIMEOUT_5000MS, false);
+       if (ret) {
+               printf("%s: Timeout while waiting for", __func__);
+               printf(" sending all scrub data\n");
+               return ret;
Quoted 1 line

Same here.

No need because this is considered error, and system would hang for watchdog to kick in.

Quoted 80 lines

drivers/ddr/altera/Makefile

Quoted 5 lines
drivers/ddr/altera/Makefile +4 -0
+       }
+
+       /* Disables scrubber */
+       clrbits_le32(umctl2_base + DDR4_SBRCTL_OFFSET,

DDR4_SBRCTL_SCRUB_EN);

Quoted 36 lines
drivers/ddr/altera/Makefile +36 -0
+
+       /* Restore user settings */
+       writel(backup[0], umctl2_base + DDR4_SBRCTL_OFFSET);
+       writel(backup[1], umctl2_base + DDR4_SBRWDATA0_OFFSET);
+       writel(backup[2], umctl2_base + DDR4_SBRSTART0_OFFSET);
+       if (umctl2_type == DDRTYPE_DDR4) {
+               writel(backup[3], umctl2_base + DDR4_SBRWDATA1_OFFSET);
+               writel(backup[4], umctl2_base + DDR4_SBRSTART1_OFFSET);
+       }
+       writel(backup[5], umctl2_base + DDR4_SBRRANGE0_OFFSET);
+       writel(backup[6], umctl2_base + DDR4_SBRRANGE1_OFFSET);
+       writel(backup[7], umctl2_base + DDR4_ECCCFG0_OFFSET);
+       writel(backup[8], umctl2_base + DDR4_ECCCFG1_OFFSET);
+
+       /* Enables ECC scrub on scrubber */
+       if (!(readl(umctl2_base + DDR4_SBRCTL_OFFSET) &
+           DDR4_SBRCTL_SCRUB_WRITE)) {
+               /* Enables scrubber */
+               setbits_le32(umctl2_base + DDR4_SBRCTL_OFFSET,
+                            DDR4_SBRCTL_SCRUB_EN);
+       }
+
+       return 0;
+}
+
+static int init_umctl2(phys_addr_t umctl2_handoff_base,
+                      phys_addr_t umctl2_base, enum ddr_type umctl2_type,
+                      size_t umctl2_handoff_length,
+                      u32 *user_backup)
+{
+       u32 handoff_table[umctl2_handoff_length];
+       u32 i;
+       int ret;
+
+       if (umctl2_type == DDRTYPE_DDR4)
+               printf("Initializing DDR4 controller ...\n");

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+       else if (umctl2_type == DDRTYPE_LPDDR4_0)
+               printf("Initializing LPDDR4_0 controller ...\n");
+       else if (umctl2_type == DDRTYPE_LPDDR4_1)
+               printf("Initializing LPDDR4_1 controller ...\n");
+
+       /* Prevent controller from issuing read/write to SDRAM */
+       setbits_le32(umctl2_base + DDR4_DBG1_OFFSET, DDR4_DBG1_DISDQ);
+
+       /* Put SDRAM into self-refresh */
+       setbits_le32(umctl2_base + DDR4_PWRCTL_OFFSET,

DDR4_PWRCTL_SELFREF_EN);

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+
+       /* Enable quasi-dynamic programing of the controller registers */
+       clrbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+
+       /* Ensure the controller is in initialization mode */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +

DDR4_STAT_OFFSET),

drivers/ddr/altera/Makefile

Quoted 9 lines
drivers/ddr/altera/Makefile +9 -0
+                               DDR4_STAT_OPERATING_MODE, false, TIMEOUT_200MS,
+                               false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" init operating mode\n");
+               return ret;
+       }
+
+       debug("%s: UMCTL2 handoff base address = 0x%p table length =

0x%08x\n",

Quoted 9 lines
drivers/ddr/altera/Makefile +9 -0
+             __func__, (u32 *)umctl2_handoff_base,
+             (u32)umctl2_handoff_length);
+
+       socfpga_handoff_read((void *)umctl2_handoff_base, handoff_table,
+                            umctl2_handoff_length);
+
+       for (i = 0; i < umctl2_handoff_length; i = i + 2) {
+               debug("%s: Absolute addr: 0x%08llx APB offset: 0x%08x",
+                     __func__, handoff_table[i] + umctl2_base,
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 6 lines
drivers/ddr/altera/Makefile +6 -0
+                     handoff_table[i]);
+               debug(" wr = 0x%08x ", handoff_table[i + 1]);
+
+               writel(handoff_table[i + 1], (uintptr_t)(handoff_table[i] +
+                      umctl2_base));
+

Can have a common function to write the handoff data. Check all code after call to socfpga_handoff_read().

I can create a common function for both PHY and PHY init engine, but not for this umctl because both for loop process are different, handoff_table for both PHY and PHY int engine need some preprocessing before writing into respective registers but this is not required in umctl.

Quoted 563 lines

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +9 -0
+               debug("rd = 0x%08x\n", readl((uintptr_t)(handoff_table[i] +
+                     umctl2_base)));
+       }
+
+       /* Backup user settings, restore after DDR up running */
+       *user_backup = readl(umctl2_base + DDR4_PWRCTL_OFFSET);
+
+       /* Disable self resfresh */
+       clrbits_le32(umctl2_base + DDR4_PWRCTL_OFFSET,

DDR4_PWRCTL_SELFREF_EN);

Quoted 12 lines
drivers/ddr/altera/Makefile +12 -0
+
+       if (umctl2_type == DDRTYPE_LPDDR4_0 ||
+           umctl2_type == DDRTYPE_LPDDR4_1) {
+               /* Setting selfref_sw to 1, based on lpddr4 requirement */
+               setbits_le32(umctl2_base + DDR4_PWRCTL_OFFSET,
+                            DDR4_PWRCTL_SELFREF_SW);
+
+               /* Backup user settings, restore after DDR up running */
+               user_backup++;
+               *user_backup = readl(umctl2_base + DDR4_INIT0_OFFSET) &
+                                    DDR4_INIT0_SKIP_RAM_INIT;
+

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+               /*
+                * Setting INIT0.skip_dram_init to 0x3, based on lpddr4
+                * requirement
+                */
+               setbits_le32(umctl2_base + DDR4_INIT0_OFFSET,
+                            DDR4_INIT0_SKIP_RAM_INIT);
+       }
+
+       /* Complete quasi-dynamic register programming */
+       setbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

Quoted 23 lines
drivers/ddr/altera/Makefile +23 -0
+
+       /* Enable controller from issuing read/write to SDRAM */
+       clrbits_le32(umctl2_base + DDR4_DBG1_OFFSET, DDR4_DBG1_DISDQ);
+
+       return 0;
+}
+
+static int phy_pre_handoff_config(phys_addr_t umctl2_base,
+                                 enum ddr_type umctl2_type)
+{
+       int ret;
+       u32 value;
+
+       if (umctl2_type == DDRTYPE_DDR4) {
+               /* Check DDR4 retry is enabled ? */
+               value = readl(umctl2_base + DDR4_CRCPARCTL1_OFFSET) &
+                             DDR4_CRCPARCTL1_CRC_PARITY_RETRY_ENABLE;
+
+               if (value) {
+                       debug("%s: DDR4 retry is enabled\n", __func__);
+                       debug("%s: Disable auto refresh is not supported\n",
+                             __func__);
+               } else {

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+                       /* Disable auto refresh */
+                       setbits_le32(umctl2_base + DDR4_RFSHCTL3_OFFSET,
+                                    DDR4_RFSHCTL3_DIS_AUTO_REFRESH);
+               }
+       }
+
+       /* Disable selfref_en & powerdown_en, nvr disable dfi dram clk */
+       clrbits_le32(umctl2_base + DDR4_PWRCTL_OFFSET,
+                    DDR4_PWRCTL_EN_DFI_DRAM_CLK_DISABLE |
+                    DDR4_PWRCTL_POWERDOWN_EN |

DDR4_PWRCTL_SELFREF_EN);

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+
+       /* Enable quasi-dynamic programing of the controller registers */
+       clrbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

drivers/ddr/altera/Makefile

Quoted 11 lines
drivers/ddr/altera/Makefile +11 -0
+
+       ret = enable_quasi_dynamic_reg_grp3(umctl2_base, umctl2_type);
+       if (ret)
+               return ret;
+
+       /* Masking dfi init complete */
+       clrbits_le32(umctl2_base + DDR4_DFIMISC_OFFSET,
+                    DDR4_DFIMISC_DFI_INIT_COMPLETE_EN);
+
+       /* Complete quasi-dynamic register programming */
+       setbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

Quoted 102 lines
drivers/ddr/altera/Makefile +102 -0
+
+       /* Polling programming done */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SWSTAT_OFFSET), DDR4_SWSTAT_SW_DONE_ACK,
+                               true, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" programming done\n");
+       }
+
+       return ret;
+}
+
+static int init_phy(struct ddr_handoff *ddr_handoff_info)
+{
+       u32 handoff_table[ddr_handoff_info->phy_handoff_length];
+       u32 i, value;
+       int ret;
+
+       printf("Initializing DDR PHY ...\n");
+
+       if (ddr_handoff_info->cntlr_t == DDRTYPE_DDR4 ||
+           ddr_handoff_info->cntlr_t == DDRTYPE_LPDDR4_0) {
+               ret = phy_pre_handoff_config(ddr_handoff_info->cntlr_base,
+                                            ddr_handoff_info->cntlr_t);
+               if (ret)
+                       return ret;
+       }
+
+       if (ddr_handoff_info->cntlr2_t == DDRTYPE_LPDDR4_1) {
+               ret = phy_pre_handoff_config
+                       (ddr_handoff_info->cntlr2_base,
+                        ddr_handoff_info->cntlr2_t);
+               if (ret)
+                       return ret;
+       }
+
+       /* Execute PHY configuration handoff */
+       socfpga_handoff_read((void *)ddr_handoff_info->phy_handoff_base,
+                            handoff_table,
+                            (u32)ddr_handoff_info->phy_handoff_length);
+
+       for (i = 0; i < ddr_handoff_info->phy_handoff_length; i = i + 2) {
+               /*
+                * Convert PHY odd offset to even offset that supported by
+                * ARM processor.
+                */
+               value = handoff_table[i] << 1;
+               debug("%s: Absolute addr: 0x%08llx, APB offset: 0x%08x ",
+                     __func__, value + ddr_handoff_info->phy_base, value);
+               debug("PHY offset: 0x%08x", handoff_table[i]);
+               debug(" wr = 0x%08x ", handoff_table[i + 1]);
+               writew(handoff_table[i + 1], (uintptr_t)(value +
+                      ddr_handoff_info->phy_base));
+               debug("rd = 0x%08x\n", readw((uintptr_t)(value +
+                     ddr_handoff_info->phy_base)));
+       }
+
+       printf("DDR PHY configuration is completed\n");
+
+       return 0;
+}
+
+static void phy_init_engine(struct ddr_handoff *handoff)
+{
+       u32 i, value;
+       u32 handoff_table[handoff->phy_engine_handoff_length];
+
+       printf("Load PHY Init Engine ...\n");
+
+       /* Execute PIE production code handoff */
+       socfpga_handoff_read((void *)handoff->phy_engine_handoff_base,
+                            handoff_table,
+                            (u32)handoff->phy_engine_handoff_length);
+
+       for (i = 0; i < handoff->phy_engine_handoff_length; i = i + 2) {
+               debug("Handoff addr: 0x%8llx ", handoff_table[i] +
+                     handoff->phy_base);
+
+               /*
+                * Convert PHY odd offset to even offset that supported by
+                * ARM processor.
+                */
+               value = handoff_table[i] << 1;
+               debug("%s: Absolute addr: 0x%08llx, APB offset: 0x%08x ",
+                     __func__, value + handoff->phy_base, value);
+               debug("PHY offset: 0x%08x", handoff_table[i]);
+               debug(" wr = 0x%08x ", handoff_table[i + 1]);
+
+               writew(handoff_table[i + 1], (uintptr_t)(value +
+                      handoff->phy_base));
+
+               debug("rd = 0x%08x\n", readw((uintptr_t)(value +
+                     handoff->phy_base)));
+       }
+
+       printf("End of loading PHY Init Engine\n");
+}
+
+int populate_ddr_handoff(struct ddr_handoff *handoff)
+{
+       phys_addr_t next_section_header;

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+
+       /* DDR handoff */
+       handoff->mem_reset_base = SOC64_HANDOFF_DDR_MEMRESET_BASE;
+       debug("%s: DDR memory reset base = 0x%x\n", __func__,
+             (u32)handoff->mem_reset_base);
+       debug("%s: DDR memory reset address = 0x%x\n", __func__,
+             readl(handoff->mem_reset_base));
+
+       /* Beginning of DDR controller handoff */
+       handoff->cntlr_handoff_base =

SOC64_HANDOFF_DDR_UMCTL2_SECTION;

Quoted 37 lines
drivers/ddr/altera/Makefile +37 -0
+       debug("%s: cntlr handoff base = 0x%x\n", __func__,
+             (u32)handoff->cntlr_handoff_base);
+
+       /* Get 1st DDR type */
+       handoff->cntlr_t = get_ddr_type(handoff->cntlr_handoff_base +
+                                       SOC64_HANDOFF_DDR_UMCTL2_TYPE_OFFSET);
+       if (handoff->cntlr_t == DDRTYPE_LPDDR4_1 ||
+           handoff->cntlr_t == DDRTYPE_UNKNOWN) {
+               debug("%s: Wrong DDR handoff format, the 1st DDR ", __func__);
+               debug("type must be DDR4 or LPDDR4_0\n");
+               return -ENOEXEC;
+       }
+
+       /* 1st cntlr base physical address */
+       handoff->cntlr_base = readl(handoff->cntlr_handoff_base +
+                                   SOC64_HANDOFF_DDR_UMCTL2_BASE_ADDR_OFFSET);
+       debug("%s: cntlr base = 0x%x\n", __func__, (u32)handoff->cntlr_base);
+
+       /* Get the total length of DDR cntlr handoff section */
+       handoff->cntlr_total_length = readl(handoff->cntlr_handoff_base +
+                                           SOC64_HANDOFF_OFFSET_LENGTH);
+       debug("%s: Umctl2 total length in byte = 0x%x\n", __func__,
+             (u32)handoff->cntlr_total_length);
+
+       /* Get the length of user setting data in DDR cntlr handoff section */
+       handoff->cntlr_handoff_length = socfpga_get_handoff_size((void *)
+                                               handoff->cntlr_handoff_base);
+       debug("%s: Umctl2 handoff length in word(32-bit) = 0x%x\n", __func__,
+             (u32)handoff->cntlr_handoff_length);
+
+       /* Wrong format on user setting data */
+       if (handoff->cntlr_handoff_length < 0) {
+               debug("%s: Wrong format on user setting data\n", __func__);
+               return -ENOEXEC;
+       }
+
+       /* Get the next handoff section address */

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+       next_section_header = handoff->cntlr_handoff_base +
+                               handoff->cntlr_total_length;
+       debug("%s: Next handoff section header location = 0x%llx\n", __func__,
+             next_section_header);
+
+       /*
+        * Checking next section handoff is cntlr or PHY, and changing
+        * subsequent implementation accordingly
+        */
+       if (readl(next_section_header) ==

SOC64_HANDOFF_DDR_UMCTL2_MAGIC) {

Quoted 143 lines
drivers/ddr/altera/Makefile +143 -0
+               /* Get the next cntlr handoff section address */
+               handoff->cntlr2_handoff_base = next_section_header;
+               debug("%s: umctl2 2nd handoff base = 0x%x\n", __func__,
+                     (u32)handoff->cntlr2_handoff_base);
+
+               /* Get 2nd DDR type */
+               handoff->cntlr2_t = get_ddr_type(handoff->cntlr2_handoff_base +
+                                       SOC64_HANDOFF_DDR_UMCTL2_TYPE_OFFSET);
+               if (handoff->cntlr2_t == DDRTYPE_LPDDR4_0 ||
+                   handoff->cntlr2_t == DDRTYPE_UNKNOWN) {
+                       debug("%s: Wrong DDR handoff format, the 2nd DDR ",
+                             __func__);
+                       debug("type must be LPDDR4_1\n");
+                       return -ENOEXEC;
+               }
+
+               /* 2nd umctl2 base physical address */
+               handoff->cntlr2_base =
+                       readl(handoff->cntlr2_handoff_base +
+                             SOC64_HANDOFF_DDR_UMCTL2_BASE_ADDR_OFFSET);
+               debug("%s: cntlr2 base = 0x%x\n", __func__,
+                     (u32)handoff->cntlr2_base);
+
+               /* Get the total length of 2nd DDR umctl2 handoff section */
+               handoff->cntlr2_total_length =
+                       readl(handoff->cntlr2_handoff_base +
+                             SOC64_HANDOFF_OFFSET_LENGTH);
+               debug("%s: Umctl2_2nd total length in byte = 0x%x\n", __func__,
+                     (u32)handoff->cntlr2_total_length);
+
+               /*
+                * Get the length of user setting data in DDR umctl2 handoff
+                * section
+                */
+               handoff->cntlr2_handoff_length =
+                       socfpga_get_handoff_size((void *)
+                                                handoff->cntlr2_handoff_base);
+               debug("%s: cntlr2 handoff length in word(32-bit) = 0x%x\n",
+                     __func__,
+                    (u32)handoff->cntlr2_handoff_length);
+
+               /* Wrong format on user setting data */
+               if (handoff->cntlr2_handoff_length < 0) {
+                       debug("%s: Wrong format on umctl2 user setting data\n",
+                             __func__);
+                       return -ENOEXEC;
+               }
+
+               /* Get the next handoff section address */
+               next_section_header = handoff->cntlr2_handoff_base +
+                                       handoff->cntlr2_total_length;
+               debug("%s: Next handoff section header location = 0x%llx\n",
+                     __func__, next_section_header);
+       }
+
+       /* Checking next section handoff is PHY ? */
+       if (readl(next_section_header) == SOC64_HANDOFF_DDR_PHY_MAGIC) {
+               /* DDR PHY handoff */
+               handoff->phy_handoff_base = next_section_header;
+               debug("%s: PHY handoff base = 0x%x\n", __func__,
+                     (u32)handoff->phy_handoff_base);
+
+               /* PHY base physical address */
+               handoff->phy_base = readl(handoff->phy_handoff_base +
+                                       SOC64_HANDOFF_DDR_PHY_BASE_OFFSET);
+               debug("%s: PHY base = 0x%x\n", __func__,
+                     (u32)handoff->phy_base);
+
+               /* Get the total length of PHY handoff section */
+               handoff->phy_total_length = readl(handoff->phy_handoff_base +
+                                               SOC64_HANDOFF_OFFSET_LENGTH);
+               debug("%s: PHY total length in byte = 0x%x\n", __func__,
+                     (u32)handoff->phy_total_length);
+
+               /*
+                * Get the length of user setting data in DDR PHY handoff
+                * section
+                */
+               handoff->phy_handoff_length = socfpga_get_handoff_size((void *)
+                                               handoff->phy_handoff_base);
+               debug("%s: PHY handoff length in word(32-bit) = 0x%x\n",
+                     __func__, (u32)handoff->phy_handoff_length);
+
+               /* Wrong format on PHY user setting data */
+               if (handoff->phy_handoff_length < 0) {
+                       debug("%s: Wrong format on PHY user setting data\n",
+                             __func__);
+                       return -ENOEXEC;
+               }
+
+               /* Get the next handoff section address */
+               next_section_header = handoff->phy_handoff_base +
+                                       handoff->phy_total_length;
+               debug("%s: Next handoff section header location = 0x%llx\n",
+                     __func__, next_section_header);
+       } else {
+               debug("%s: Wrong format for DDR handoff, expect PHY",
+                     __func__);
+               debug(" handoff section after umctl2 handoff section\n");
+               return -ENOEXEC;
+       }
+
+       /* Checking next section handoff is PHY init Engine ? */
+       if (readl(next_section_header) ==
+               SOC64_HANDOFF_DDR_PHY_INIT_ENGINE_MAGIC) {
+               /* DDR PHY Engine handoff */
+               handoff->phy_engine_handoff_base = next_section_header;
+               debug("%s: PHY init engine handoff base = 0x%x\n", __func__,
+                     (u32)handoff->phy_engine_handoff_base);
+
+               /* Get the total length of PHY init engine handoff section */
+               handoff->phy_engine_total_length =
+                               readl(handoff->phy_engine_handoff_base +
+                                     SOC64_HANDOFF_OFFSET_LENGTH);
+               debug("%s: PHY engine total length in byte = 0x%x\n", __func__,
+                     (u32)handoff->phy_engine_total_length);
+
+               /*
+                * Get the length of user setting data in DDR PHY init engine
+                * handoff section
+                */
+               handoff->phy_engine_handoff_length =
+                       socfpga_get_handoff_size((void *)
+                                       handoff->phy_engine_handoff_base);
+               debug("%s: PHY engine handoff length in word(32-bit) = 0x%x\n",
+                     __func__, (u32)handoff->phy_engine_handoff_length);
+
+               /* Wrong format on PHY init engine setting data */
+               if (handoff->phy_engine_handoff_length < 0) {
+                       debug("%s: Wrong format on PHY init engine ",
+                             __func__);
+                       debug("user setting data\n");
+                       return -ENOEXEC;
+               }
+       } else {
+               debug("%s: Wrong format for DDR handoff, expect PHY",
+                     __func__);
+               debug(" init engine handoff section after PHY handoff\n");
+               debug(" section\n");
+               return -ENOEXEC;
+       }
+
+       handoff->train_imem_base = handoff->phy_base +

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+                                               DDR_PHY_TRAIN_IMEM_OFFSET;
+       debug("%s: PHY train IMEM base = 0x%x\n",
+             __func__, (u32)handoff->train_imem_base);
+
+       handoff->train_dmem_base = handoff->phy_base +
+                                               DDR_PHY_TRAIN_DMEM_OFFSET;
+       debug("%s: PHY train DMEM base = 0x%x\n",
+             __func__, (u32)handoff->train_dmem_base);
+
+       handoff->train_imem_length =

SOC64_HANDOFF_DDR_TRAIN_IMEM_LENGTH;

drivers/ddr/altera/Makefile

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+       debug("%s: PHY train IMEM length = 0x%x\n",
+             __func__, (u32)handoff->train_imem_length);
+
+       handoff->train_dmem_length =

SOC64_HANDOFF_DDR_TRAIN_DMEM_LENGTH;

Quoted 29 lines
drivers/ddr/altera/Makefile +29 -0
+       debug("%s: PHY train DMEM length = 0x%x\n",
+             __func__, (u32)handoff->train_dmem_length);
+
+       return 0;
+}
+
+int enable_ddr_clock(struct udevice *dev)
+{
+       struct clk *ddr_clk;
+       int ret;
+
+       /* Enable clock before init DDR */
+       ddr_clk = devm_clk_get(dev, "mem_clk");
+       if (!IS_ERR(ddr_clk)) {
+               ret = clk_enable(ddr_clk);
+               if (ret) {
+                       printf("%s: Failed to enable DDR clock\n", __func__);
+                       return ret;
+               }
+       } else {
+               ret = PTR_ERR(ddr_clk);
+               debug("%s: Failed to get DDR clock from dts\n", __func__);
+               return ret;
+       }
+
+       printf("%s: DDR clock is enabled\n", __func__);
+
+       return 0;
+}

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+
+static int ddr_start_dfi_init(phys_addr_t umctl2_base,
+                             enum ddr_type umctl2_type)
+{
+       int ret;
+
+       debug("%s: Start DFI init\n", __func__);
+
+       /* Enable quasi-dynamic programing of controller registers */
+       clrbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

drivers/ddr/altera/Makefile

Quoted 11 lines
drivers/ddr/altera/Makefile +11 -0
+
+       ret = enable_quasi_dynamic_reg_grp3(umctl2_base, umctl2_type);
+       if (ret)
+               return ret;
+
+       /* Start DFI init sequence */
+       setbits_le32(umctl2_base + DDR4_DFIMISC_OFFSET,
+                    DDR4_DFIMISC_DFI_INIT_START);
+
+       /* Complete quasi-dynamic register programming */
+       setbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

Quoted 24 lines
drivers/ddr/altera/Makefile +24 -0
+
+       /* Polling programming done */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SWSTAT_OFFSET),
+                               DDR4_SWSTAT_SW_DONE_ACK, true,
+                               TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" programming done\n");
+       }
+
+       return ret;
+}
+
+static int ddr_check_dfi_init_complete(phys_addr_t umctl2_base,
+                                      enum ddr_type umctl2_type)
+{
+       int ret;
+
+       /* Polling DFI init complete */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_DFISTAT_OFFSET),
+                               DDR4_DFI_INIT_COMPLETE, true,
+                               TIMEOUT_200MS, false);

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" DFI init done\n");
+               return ret;
+       }
+
+       debug("%s: DFI init completed.\n", __func__);
+
+       /* Enable quasi-dynamic programing of controller registers */
+       clrbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

drivers/ddr/altera/Makefile

Quoted 11 lines
drivers/ddr/altera/Makefile +11 -0
+
+       ret = enable_quasi_dynamic_reg_grp3(umctl2_base, umctl2_type);
+       if (ret)
+               return ret;
+
+       /* Stop DFI init sequence */
+       clrbits_le32(umctl2_base + DDR4_DFIMISC_OFFSET,
+                    DDR4_DFIMISC_DFI_INIT_START);
+
+       /* Complete quasi-dynamic register programming */
+       setbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

Quoted 14 lines
drivers/ddr/altera/Makefile +14 -0
+
+       /* Polling programming done */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SWSTAT_OFFSET),
+                               DDR4_SWSTAT_SW_DONE_ACK, true,
+                               TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" programming done\n");
+               return ret;
+       }
+
+       debug("%s:DDR programming done\n", __func__);
+

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+       return ret;
+}
+
+static int ddr_trigger_sdram_init(phys_addr_t umctl2_base,
+                                 enum ddr_type umctl2_type)
+{
+       int ret;
+
+       /* Enable quasi-dynamic programing of controller registers */
+       clrbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

drivers/ddr/altera/Makefile

Quoted 11 lines
drivers/ddr/altera/Makefile +11 -0
+
+       ret = enable_quasi_dynamic_reg_grp3(umctl2_base, umctl2_type);
+       if (ret)
+               return ret;
+
+       /* Unmasking dfi init complete */
+       setbits_le32(umctl2_base + DDR4_DFIMISC_OFFSET,
+                    DDR4_DFIMISC_DFI_INIT_COMPLETE_EN);
+
+       /* Software exit from self-refresh */
+       clrbits_le32(umctl2_base + DDR4_PWRCTL_OFFSET,

DDR4_PWRCTL_SELFREF_SW);

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+
+       /* Complete quasi-dynamic register programming */
+       setbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

Quoted 19 lines
drivers/ddr/altera/Makefile +19 -0
+
+       /* Polling programming done */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SWSTAT_OFFSET),
+                               DDR4_SWSTAT_SW_DONE_ACK, true,
+                               TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" programming done\n");
+               return ret;
+       }
+
+       debug("%s:DDR programming done\n", __func__);
+       return ret;
+}
+
+static int ddr_post_handoff_config(phys_addr_t umctl2_base,
+                                  enum ddr_type umctl2_type)
+{
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 7 lines
drivers/ddr/altera/Makefile +7 -0
+       int ret = 0;
+       u32 value;
+       u32 start = get_timer(0);
+
+       /* Polling until SDRAM entered normal operating mode */
+       value = readl(umctl2_base + DDR4_STAT_OFFSET) &
+                     DDR4_STAT_OPERATING_MODE;

Can merge to "do..while" loop below.

Okay.

Quoted 610 lines
Quoted 14 lines
drivers/ddr/altera/Makefile +13 -0
+       while (value != NORMAL_OPM) {
+               if (get_timer(start) > TIMEOUT_200MS) {
+                       debug("%s: Timeout while waiting for",
+                             __func__);
+                       debug(" DDR enters normal operating mode\n");
+                       return -ETIMEDOUT;
+               }
+
+               value = readl(umctl2_base + DDR4_STAT_OFFSET) &
+                             DDR4_STAT_OPERATING_MODE;
+
+               udelay(1);
+               WATCHDOG_RESET();

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+       }
+
+       printf("DDR entered normal operating mode\n");
+
+       /* Enabling auto refresh */
+       clrbits_le32(umctl2_base + DDR4_RFSHCTL3_OFFSET,
+                    DDR4_RFSHCTL3_DIS_AUTO_REFRESH);
+
+       /* Checking ECC is enabled? */
+       value = readl(umctl2_base + DDR4_ECCCFG0_OFFSET) &

DDR4_ECC_MODE;

Quoted 14 lines
drivers/ddr/altera/Makefile +14 -0
+       if (value) {
+               printf("ECC is enabled\n");
+               ret = scrubber_ddr_config(umctl2_base, umctl2_type);
+               if (ret)
+                       printf("Failed to enable ECC\n");
+       }
+
+       return ret;
+}
+
+static int configure_training_firmware(struct ddr_handoff *ddr_handoff_info,
+       const void *train_imem, const void *train_dmem)
+{
+       int ret = 0;

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+
+       printf("Configuring training firmware ...\n");
+
+       /* Reset SDRAM */
+       writew(DDR_PHY_PROTECT_MEMRESET,
+              (uintptr_t)(ddr_handoff_info->phy_base +
+              DDR_PHY_MEMRESETL_OFFSET));
+
+       /* Enable access to the PHY configuration registers */
+       clrbits_le16(ddr_handoff_info->phy_base +

DDR_PHY_APBONLY0_OFFSET,

drivers/ddr/altera/Makefile

Quoted 13 lines
drivers/ddr/altera/Makefile +13 -0
+                    DDR_PHY_MICROCONTMUXSEL);
+
+       /* Copy train IMEM bin */
+       memcpy((void *)ddr_handoff_info->train_imem_base, train_imem,
+              ddr_handoff_info->train_imem_length);
+
+       ret = memcmp((void *)ddr_handoff_info->train_imem_base, train_imem,
+                    ddr_handoff_info->train_imem_length);
+       if (ret) {
+               debug("%s: Failed to copy train IMEM binary\n", __func__);
+               /* Isolate the APB access from internal CSRs */
+               setbits_le16(ddr_handoff_info->phy_base +
+                            DDR_PHY_APBONLY0_OFFSET,

DDR_PHY_MICROCONTMUXSEL);

drivers/ddr/altera/Makefile

Quoted 7 lines
drivers/ddr/altera/Makefile +7 -0
+               return ret;
+       }
+
+       memcpy((void *)ddr_handoff_info->train_dmem_base, train_dmem,
+              ddr_handoff_info->train_dmem_length);
+
+       ret = memcmp((void *)ddr_handoff_info->train_dmem_base,

train_dmem,

drivers/ddr/altera/Makefile

Quoted 6 lines
drivers/ddr/altera/Makefile +6 -0
+                    ddr_handoff_info->train_dmem_length);
+       if (ret)
+               debug("%s: Failed to copy train DMEM binary\n", __func__);
+
+       /* Isolate the APB access from internal CSRs */
+       setbits_le16(ddr_handoff_info->phy_base +

DDR_PHY_APBONLY0_OFFSET,

drivers/ddr/altera/Makefile

Quoted 9 lines
drivers/ddr/altera/Makefile +9 -0
+                    DDR_PHY_MICROCONTMUXSEL);
+
+       return ret;
+}
+
+static void calibrating_sdram(struct ddr_handoff *ddr_handoff_info)
+{
+       /* Init mailbox protocol - set 1 to DCTWRITEPROT[0] */
+       setbits_le16(ddr_handoff_info->phy_base +

DDR_PHY_DCTWRITEPROT_OFFSET,

drivers/ddr/altera/Makefile

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+                    DDR_PHY_DCTWRITEPROT);
+
+       /* Init mailbox protocol - set 1 to UCTWRITEPROT[0] */
+       setbits_le16(ddr_handoff_info->phy_base +

DDR_PHY_UCTWRITEPROT_OFFSET,

drivers/ddr/altera/Makefile

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+                    DDR_PHY_UCTWRITEPROT);
+
+       /* Reset and stalling ARC processor */
+       setbits_le16(ddr_handoff_info->phy_base +

DDR_PHY_MICRORESET_OFFSET,

drivers/ddr/altera/Makefile

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+                    DDR_PHY_MICRORESET_RESET | DDR_PHY_MICRORESET_STALL);
+
+       /* Release ARC processor */
+       clrbits_le16(ddr_handoff_info->phy_base +

DDR_PHY_MICRORESET_OFFSET,

drivers/ddr/altera/Makefile

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+                    DDR_PHY_MICRORESET_RESET);
+
+       /* Starting PHY firmware execution */
+       clrbits_le16(ddr_handoff_info->phy_base +

DDR_PHY_MICRORESET_OFFSET,

Quoted 246 lines
drivers/ddr/altera/Makefile +246 -0
+                    DDR_PHY_MICRORESET_STALL);
+}
+
+static int get_mail(struct ddr_handoff *handoff, enum message_mode mode,
+                   u32 *message_id)
+{
+       int ret;
+
+       /* Polling major messages from PMU */
+       ret = wait_for_bit_le16((const void *)(handoff->phy_base +
+                               DDR_PHY_UCTSHADOWREGS_OFFSET),
+                               DDR_PHY_UCTSHADOWREGS_UCTWRITEPROTESHADOW,
+                               false, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for",
+                     __func__);
+               debug(" major messages from PMU\n");
+               return ret;
+       }
+
+       *message_id = readw((uintptr_t)(handoff->phy_base +
+                           DDR_PHY_UCTWRITEONLYSHADOW_OFFSET));
+
+       if (mode == STREAMING_MESSAGE)
+               *message_id |= readw((uintptr_t)((handoff->phy_base +
+                                    DDR_PHY_UCTDATWRITEONLYSHADOW_OFFSET))) <<
+                                    SZ_16;
+
+       /* Ack the receipt of the major message */
+       clrbits_le16(handoff->phy_base + DDR_PHY_DCTWRITEPROT_OFFSET,
+                    DDR_PHY_DCTWRITEPROT);
+
+       ret = wait_for_bit_le16((const void *)(handoff->phy_base +
+                               DDR_PHY_UCTSHADOWREGS_OFFSET),
+                               DDR_PHY_UCTSHADOWREGS_UCTWRITEPROTESHADOW,
+                               true, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for",
+                     __func__);
+               debug(" ack the receipt of the major message completed\n");
+               return ret;
+       }
+
+       /* Complete protocol */
+       setbits_le16(handoff->phy_base + DDR_PHY_DCTWRITEPROT_OFFSET,
+                    DDR_PHY_DCTWRITEPROT);
+
+       return ret;
+}
+
+static int get_mail_streaming(struct ddr_handoff *handoff,
+                             enum message_mode mode, u32 *index)
+{
+       int ret;
+
+       *index = readw((uintptr_t)(handoff->phy_base +
+                      DDR_PHY_UCTWRITEONLYSHADOW_OFFSET));
+
+       if (mode == STREAMING_MESSAGE)
+               *index |= readw((uintptr_t)((handoff->phy_base +
+                               DDR_PHY_UCTDATWRITEONLYSHADOW_OFFSET))) <<
+                               SZ_16;
+
+       /* Ack the receipt of the major message */
+       clrbits_le16(handoff->phy_base + DDR_PHY_DCTWRITEPROT_OFFSET,
+                    DDR_PHY_DCTWRITEPROT);
+
+       ret = wait_for_bit_le16((const void *)(handoff->phy_base +
+                               DDR_PHY_UCTSHADOWREGS_OFFSET),
+                               DDR_PHY_UCTSHADOWREGS_UCTWRITEPROTESHADOW,
+                               true, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for",
+                     __func__);
+               debug(" ack the receipt of the major message completed\n");
+               return ret;
+       }
+
+       /* Complete protocol */
+       setbits_le16(handoff->phy_base + DDR_PHY_DCTWRITEPROT_OFFSET,
+                    DDR_PHY_DCTWRITEPROT);
+
+       return 0;
+}
+
+static int decode_streaming_message(struct ddr_handoff *ddr_handoff_info,
+                                   u32 *streaming_index)
+{
+       int i = 0, ret;
+       u32 temp;
+
+       temp = *streaming_index;
+
+       while (i < GET_LOWHW_DATA(temp)) {
+               ret = get_mail(ddr_handoff_info, STREAMING_MESSAGE,
+                              streaming_index);
+               if (ret)
+                       return ret;
+
+               printf("args[%d]: 0x%x ", i, *streaming_index);
+               i++;
+       }
+
+       return 0;
+}
+
+static int poll_for_training_complete(struct ddr_handoff *ddr_handoff_info)
+{
+       int ret;
+       u32 message_id = 0;
+       u32 streaming_index = 0;
+
+       do {
+               ret = get_mail(ddr_handoff_info, MAJOR_MESSAGE, &message_id);
+               if (ret)
+                       return ret;
+
+                printf("Major message id = 0%x\n", message_id);
+
+               if (message_id == FW_STREAMING_MSG_ID) {
+                       ret = get_mail_streaming(ddr_handoff_info,
+                                                STREAMING_MESSAGE,
+                                                &streaming_index);
+                       if (ret)
+                               return ret;
+
+                       printf("streaming index 0%x : ", streaming_index);
+
+                       decode_streaming_message(ddr_handoff_info,
+                                                &streaming_index);
+
+                       printf("\n");
+               }
+       } while ((message_id != FW_TRAINING_COMPLETED_STAT) &&
+              (message_id != FW_TRAINING_FAILED_STAT));
+
+       if (message_id == FW_TRAINING_COMPLETED_STAT) {
+               printf("DDR firmware training completed\n");
+       } else if (message_id == FW_TRAINING_FAILED_STAT) {
+               printf("DDR firmware training failed\n");
+               hang();
+       }
+
+       return 0;
+}
+
+static void enable_phy_clk_for_csr_access(struct ddr_handoff *handoff,
+                                         bool enable)
+{
+       if (enable) {
+               /* Enable PHY clk */
+               setbits_le16((uintptr_t)(handoff->phy_base +
+                            DDR_PHY_UCCLKHCLKENABLES_OFFSET),
+                            DDR_PHY_UCCLKHCLKENABLES_UCCLKEN |
+                            DDR_PHY_UCCLKHCLKENABLES_HCLKEN);
+       } else {
+               /* Disable PHY clk */
+               clrbits_le16((uintptr_t)(handoff->phy_base +
+                            DDR_PHY_UCCLKHCLKENABLES_OFFSET),
+                            DDR_PHY_UCCLKHCLKENABLES_UCCLKEN |
+                            DDR_PHY_UCCLKHCLKENABLES_HCLKEN);
+       }
+}
+
+/* helper function for updating train result to umctl2 RANKCTL register */
+static void set_cal_res_to_rankctrl(u32 reg_addr, u16 update_value,
+                                   u32 mask, u32 msb_mask, u32 shift)
+{
+       u32 reg, value;
+
+       reg = readl((uintptr_t)reg_addr);
+
+       debug("max value divided by 2 is 0x%x\n", update_value);
+       debug("umclt2 register 0x%x value is 0%x before ", reg_addr, reg);
+       debug("update with train result\n");
+
+       value = (reg & mask) >> shift;
+
+       value += update_value + 3;
+
+       /* reg value greater than 0xF, set one to diff_rank_wr_gap_msb */
+       if (value > 0xF)
+               setbits_le32((u32 *)(uintptr_t)reg_addr, msb_mask);
+       else
+               clrbits_le32((u32 *)(uintptr_t)reg_addr, msb_mask);
+
+       reg = readl((uintptr_t)reg_addr);
+
+       value = (value << shift) & mask;
+
+       /* update register */
+       writel((reg & (~mask)) | value, (uintptr_t)reg_addr);
+
+       reg = readl((uintptr_t)reg_addr);
+       debug("umclt2 register 0x%x value is 0%x before ", reg_addr, reg);
+       debug("update with train result\n");
+}
+
+/* helper function for updating train result to register */
+static void set_cal_res_to_reg(u32 reg_addr, u16 update_value, u32 mask,
+                              u32 shift)
+{
+       u32 reg, value;
+
+       reg = readl((uintptr_t)reg_addr);
+
+       debug("max value divided by 2 is 0x%x\n", update_value);
+       debug("umclt2 register 0x%x value is 0%x before ", reg_addr, reg);
+       debug("update with train result\n");
+
+       value = (reg & mask) >> shift;
+
+       value = ((value + update_value + 3) << shift) & mask;
+
+       /* update register */
+       writel((reg & (~mask)) | value, (uintptr_t)reg_addr);
+
+       reg = readl((uintptr_t)reg_addr);
+       debug("umclt2 register 0x%x value is 0%x before ", reg_addr, reg);
+       debug("update with train result\n");
+}
+
+static u16 get_max_txdqsdlytg0_ux_p0(struct ddr_handoff *handoff, u32 reg,
+                                    u8 numdbyte, u16 upd_val)
+{
+       u32 b_addr;
+       u16 val;
+       u8 byte;
+
+       /* Getting max value from DBYTEx TxDqsDlyTg0_ux_p0 */
+       for (byte = 0; byte < numdbyte; byte++) {
+               b_addr = byte << 13;
+
+               /* TxDqsDlyTg0[9:6] is the coarse delay */
+               val = (readw((uintptr_t)(handoff->phy_base +
+                            reg + b_addr)) &
+                            DDR_PHY_TXDQDLYTG0_COARSE_DELAY) >>
+                            DDR_PHY_TXDQDLYTG0_COARSE_DELAY_SHIFT;
+
+               upd_val = max(val, upd_val);
+       }
+
+       return upd_val;
+}
+
+static int set_cal_res_to_umctl2(struct ddr_handoff *handoff,

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+                                phys_addr_t umctl2_base,
+                                enum ddr_type umctl2_type)
+{
+       int ret;
+       u8 numdbyte = 0x8;
+       u16 upd_val, val;
+       u32 dramtmg2_reg_addr, rankctl_reg_addr, reg_addr;
+
+       /* Enable quasi-dynamic programing of the controller registers */
+       clrbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

Quoted 38 lines
drivers/ddr/altera/Makefile +38 -0
+
+       ret = enable_quasi_dynamic_reg_grp3(umctl2_base, umctl2_type);
+       if (ret)
+               return ret;
+
+       /* Enable access to the PHY configuration registers */
+       clrbits_le16(handoff->phy_base + DDR_PHY_APBONLY0_OFFSET,
+                    DDR_PHY_MICROCONTMUXSEL);
+
+       if (umctl2_type == DDRTYPE_DDR4) {
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                    DMEM_MB_CDD_WW_1_0_OFFSET)));
+
+               upd_val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                       DMEM_MB_CDD_WW_0_1_OFFSET)));
+       } else if (umctl2_type == DDRTYPE_LPDDR4_0) {
+               val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                   DMEM_MB_CDD_CHA_WW_1_0_OFFSET)));
+
+               upd_val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                        DMEM_MB_CDD_CHA_WW_0_1_OFFSET)));
+       } else if (umctl2_type == DDRTYPE_LPDDR4_1) {
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                    DMEM_MB_CDD_CHB_WW_1_0_OFFSET)));
+
+               upd_val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                       DMEM_MB_CDD_CHB_WW_0_1_OFFSET)));
+       }
+
+       upd_val = max(val, upd_val);
+       debug("max value is 0x%x\n", upd_val);
+
+       /* Divided by two is required when running in freq ratio 1:2 */
+       if (!(readl(umctl2_base + DDR4_MSTR_OFFSET) & DDR4_FREQ_RATIO))
+               upd_val = DIV_ROUND_CLOSEST(upd_val, 2);
+
+       debug("Update train value to umctl2 RANKCTL.diff_rank_wr_gap\n");
+       rankctl_reg_addr = umctl2_base + DDR4_RANKCTL_OFFSET;

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+       /* Update train value to umctl2 RANKCTL.diff_rank_wr_gap */
+       set_cal_res_to_rankctrl(rankctl_reg_addr, upd_val,
+                               DDR4_RANKCTL_DIFF_RANK_WR_GAP,
+                               DDR4_RANKCTL_DIFF_RANK_WR_GAP_MSB,
+                               DDR4_RANKCTL_DIFF_RANK_WR_GAP_SHIFT);
+
+       debug("Update train value to umctl2 DRAMTMG2.W2RD\n");
+       dramtmg2_reg_addr = umctl2_base + DDR4_DRAMTMG2_OFFSET;
+       /* Update train value to umctl2 dramtmg2.wr2rd */
+       set_cal_res_to_reg(dramtmg2_reg_addr, upd_val,

DDR4_DRAMTMG2_WR2RD, 0);

drivers/ddr/altera/Makefile

Quoted 6 lines
drivers/ddr/altera/Makefile +6 -0
+
+       if (umctl2_type == DDRTYPE_DDR4) {
+               debug("Update train value to umctl2 DRAMTMG9.W2RD_S\n");
+               reg_addr = umctl2_base + DDR4_DRAMTMG9_OFFSET;
+               /* Update train value to umctl2 dramtmg9.wr2rd_s */
+               set_cal_res_to_reg(reg_addr, upd_val, DDR4_DRAMTMG9_W2RD_S,

0);

Quoted 91 lines
drivers/ddr/altera/Makefile +91 -0
+       }
+
+       if (umctl2_type == DDRTYPE_DDR4) {
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                    DMEM_MB_CDD_RR_1_0_OFFSET)));
+
+               upd_val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                       DMEM_MB_CDD_RR_0_1_OFFSET)));
+       } else if (umctl2_type == DDRTYPE_LPDDR4_0) {
+               val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                   DMEM_MB_CDD_CHA_RR_1_0_OFFSET)));
+
+               upd_val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                        DMEM_MB_CDD_CHA_RR_0_1_OFFSET)));
+       } else if (umctl2_type == DDRTYPE_LPDDR4_1) {
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                    DMEM_MB_CDD_CHB_RR_1_0_OFFSET)));
+
+               upd_val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                       DMEM_MB_CDD_CHB_RR_0_1_OFFSET)));
+       }
+
+       upd_val = max(val, upd_val);
+       debug("max value is 0x%x\n", upd_val);
+
+       /* Divided by two is required when running in freq ratio 1:2 */
+       if (!(readl(umctl2_base + DDR4_MSTR_OFFSET) & DDR4_FREQ_RATIO))
+               upd_val = DIV_ROUND_CLOSEST(upd_val, 2);
+
+       debug("Update train value to umctl2 RANKCTL.diff_rank_rd_gap\n");
+       /* Update train value to umctl2 RANKCTL.diff_rank_rd_gap */
+       set_cal_res_to_rankctrl(rankctl_reg_addr, upd_val,
+                               DDR4_RANKCTL_DIFF_RANK_RD_GAP,
+                               DDR4_RANKCTL_DIFF_RANK_RD_GAP_MSB,
+                               DDR4_RANKCTL_DIFF_RANK_RD_GAP_SHIFT);
+
+       if (umctl2_type == DDRTYPE_DDR4) {
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                    DMEM_MB_CDD_RW_1_1_OFFSET)));
+
+               upd_val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                       DMEM_MB_CDD_RW_1_0_OFFSET)));
+
+               upd_val = max(val, upd_val);
+
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                    DMEM_MB_CDD_RW_0_1_OFFSET)));
+
+               upd_val = max(val, upd_val);
+
+               val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                   DMEM_MB_CDD_RW_0_0_OFFSET)));
+
+               upd_val = max(val, upd_val);
+       } else if (umctl2_type == DDRTYPE_LPDDR4_0) {
+               val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                   DMEM_MB_CDD_CHA_RW_1_1_OFFSET)));
+
+               upd_val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                        DMEM_MB_CDD_CHA_RW_1_0_OFFSET)));
+
+               upd_val = max(val, upd_val);
+
+               val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                   DMEM_MB_CDD_CHA_RW_0_1_OFFSET)));
+
+               upd_val = max(val, upd_val);
+
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                    DMEM_MB_CDD_CHA_RW_0_0_OFFSET)));
+
+               upd_val = max(val, upd_val);
+       } else if (umctl2_type == DDRTYPE_LPDDR4_1) {
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                    DMEM_MB_CDD_CHB_RW_1_1_OFFSET)));
+
+               upd_val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                       DMEM_MB_CDD_CHB_RW_1_0_OFFSET)));
+
+               upd_val = max(val, upd_val);
+
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                    DMEM_MB_CDD_CHB_RW_0_1_OFFSET)));
+
+               upd_val = max(val, upd_val);
+
+               val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                   DMEM_MB_CDD_CHB_RW_0_0_OFFSET)));
+
+               upd_val = max(val, upd_val);
+       }

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+
+       debug("max value is 0x%x\n", upd_val);
+
+       /* Divided by two is required when running in freq ratio 1:2 */
+       if (!(readl(umctl2_base + DDR4_MSTR_OFFSET) & DDR4_FREQ_RATIO))
+               upd_val = DIV_ROUND_CLOSEST(upd_val, 2);
+
+       debug("Update train value to umctl2 dramtmg2.rd2wr\n");
+       /* Update train value to umctl2 dramtmg2.rd2wr */
+       set_cal_res_to_reg(dramtmg2_reg_addr, upd_val,

DDR4_DRAMTMG2_RD2WR,

Quoted 18 lines
drivers/ddr/altera/Makefile +18 -0
+                          DDR4_DRAMTMG2_RD2WR_SHIFT);
+
+       /* Checking ECC is enabled?, lpddr4 using inline ECC */
+       val = readl(umctl2_base + DDR4_ECCCFG0_OFFSET) & DDR4_ECC_MODE;
+       if (val && umctl2_type == DDRTYPE_DDR4)
+               numdbyte = 0x9;
+
+       upd_val = 0;
+
+       /* Getting max value from DBYTEx TxDqsDlyTg0_u0_p0 */
+       upd_val = get_max_txdqsdlytg0_ux_p0(handoff,
+                                           DDR_PHY_DBYTE0_TXDQDLYTG0_U0_P0,
+                                           numdbyte, upd_val);
+
+       /* Getting max value from DBYTEx TxDqsDlyTg0_u1_p0 */
+       upd_val = get_max_txdqsdlytg0_ux_p0(handoff,
+                                           DDR_PHY_DBYTE0_TXDQDLYTG0_U1_P0,
+                                           numdbyte, upd_val);

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+
+       debug("TxDqsDlyTg0 max value is 0x%x\n", upd_val);
+
+       /* Divided by two is required when running in freq ratio 1:2 */
+       if (!(readl(umctl2_base + DDR4_MSTR_OFFSET) & DDR4_FREQ_RATIO))
+               upd_val = DIV_ROUND_CLOSEST(upd_val, 2);
+
+       reg_addr = umctl2_base + DDR4_DFITMG1_OFFSET;
+       /* Update train value to umctl2 dfitmg1.dfi_wrdata_delay */
+       set_cal_res_to_reg(reg_addr, upd_val,

DDR4_DFITMG1_DFI_T_WRDATA_DELAY,

drivers/ddr/altera/Makefile

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+                          DDR4_DFITMG1_DFI_T_WRDATA_SHIFT);
+
+       /* Complete quasi-dynamic register programming */
+       setbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

Quoted 52 lines
drivers/ddr/altera/Makefile +52 -0
+
+       /* Polling programming done */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SWSTAT_OFFSET), DDR4_SWSTAT_SW_DONE_ACK,
+                               true, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" programming done\n");
+       }
+
+       /* Isolate the APB access from internal CSRs */
+       setbits_le16(handoff->phy_base + DDR_PHY_APBONLY0_OFFSET,
+                    DDR_PHY_MICROCONTMUXSEL);
+
+       return ret;
+}
+
+static int start_ddr_calibration(struct ddr_handoff *ddr_handoff_info)
+{
+       int ret;
+
+       /* Implement 1D training firmware */
+       ret = configure_training_firmware(ddr_handoff_info,
+               (const void *)SOC64_HANDOFF_DDR_TRAIN_IMEM_1D_SECTION,
+               (const void *)SOC64_HANDOFF_DDR_TRAIN_DMEM_1D_SECTION);
+       if (ret) {
+               debug("%s: Failed to configure 1D training firmware\n",
+                     __func__);
+               return ret;
+       }
+
+       calibrating_sdram(ddr_handoff_info);
+
+       ret = poll_for_training_complete(ddr_handoff_info);
+       if (ret) {
+               debug("%s: Failed to get FW training completed\n",
+                     __func__);
+               return ret;
+       }
+
+       /* Updating training result to DDR controller */
+       if (ddr_handoff_info->cntlr_t == DDRTYPE_DDR4) {
+               ret = set_cal_res_to_umctl2(ddr_handoff_info,
+                                           ddr_handoff_info->cntlr_base,
+                                           ddr_handoff_info->cntlr_t);
+               if (ret) {
+                       debug("%s: Failed to update train result to ",
+                             __func__);
+                       debug("DDR controller\n");
+                       return ret;
+               }
+       }
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 7 lines
drivers/ddr/altera/Makefile +7 -0
+
+       /* Implement 2D training firmware */
+       ret = configure_training_firmware(ddr_handoff_info,
+               (const void *)SOC64_HANDOFF_DDR_TRAIN_IMEM_2D_SECTION,
+               (const void *)SOC64_HANDOFF_DDR_TRAIN_DMEM_2D_SECTION);
+       if (ret) {
+               if (ret) {

Why need 2 checking for "ret"?

Good catch !! I think this was accidently duplicated

Quoted 461 lines
Quoted 116 lines
drivers/ddr/altera/Makefile +115 -0
+                       debug("%s: Failed to update train result to ",
+                             __func__);
+                       debug("DDR controller\n");
+                       return ret;
+               }
+       }
+
+       calibrating_sdram(ddr_handoff_info);
+
+       ret = poll_for_training_complete(ddr_handoff_info);
+       if (ret)
+               debug("%s: Failed to get FW training completed\n",
+                     __func__);
+
+       return ret;
+}
+
+static int init_controller(struct ddr_handoff *ddr_handoff_info,
+                          u32 *user_backup, u32 *user_backup_2nd)
+{
+       int ret = 0;
+
+       if (ddr_handoff_info->cntlr_t == DDRTYPE_DDR4  ||
+           ddr_handoff_info->cntlr_t == DDRTYPE_LPDDR4_0) {
+               /* Initialize 1st DDR controller */
+               ret = init_umctl2(ddr_handoff_info->cntlr_handoff_base,
+                                 ddr_handoff_info->cntlr_base,
+                                 ddr_handoff_info->cntlr_t,
+                                 ddr_handoff_info->cntlr_handoff_length,
+                                 user_backup);
+               if (ret) {
+                       debug("%s: Failed to inilialize first controller\n",
+                             __func__);
+                       return ret;
+               }
+       }
+
+       if (ddr_handoff_info->cntlr2_t == DDRTYPE_LPDDR4_1) {
+               /* Initialize 2nd DDR controller */
+               ret = init_umctl2(ddr_handoff_info->cntlr2_handoff_base,
+                                 ddr_handoff_info->cntlr2_base,
+                                 ddr_handoff_info->cntlr2_t,
+                                 ddr_handoff_info->cntlr2_handoff_length,
+                                 user_backup_2nd);
+               if (ret)
+                       debug("%s: Failed to inilialize 2nd controller\n",
+                             __func__);
+       }
+
+       return ret;
+}
+
+static int dfi_init(struct ddr_handoff *ddr_handoff_info)
+{
+       int ret;
+
+       ret = ddr_start_dfi_init(ddr_handoff_info->cntlr_base,
+                                ddr_handoff_info->cntlr_t);
+       if (ret)
+               return ret;
+
+       if (ddr_handoff_info->cntlr2_t == DDRTYPE_LPDDR4_1)
+               ret = ddr_start_dfi_init(ddr_handoff_info->cntlr2_base,
+                                        ddr_handoff_info->cntlr2_t);
+
+       return ret;
+}
+
+static int check_dfi_init(struct ddr_handoff *handoff)
+{
+       int ret;
+
+       ret = ddr_check_dfi_init_complete(handoff->cntlr_base,
+                                         handoff->cntlr_t);
+       if (ret)
+               return ret;
+
+       if (handoff->cntlr2_t == DDRTYPE_LPDDR4_1)
+               ret = ddr_check_dfi_init_complete(handoff->cntlr2_base,
+                                                 handoff->cntlr2_t);
+
+       return ret;
+}
+
+static int trigger_sdram_init(struct ddr_handoff *handoff)
+{
+       int ret;
+
+       ret = ddr_trigger_sdram_init(handoff->cntlr_base,
+                                    handoff->cntlr_t);
+       if (ret)
+               return ret;
+
+       if (handoff->cntlr2_t == DDRTYPE_LPDDR4_1)
+               ret = ddr_trigger_sdram_init(handoff->cntlr2_base,
+                                            handoff->cntlr2_t);
+
+       return ret;
+}
+
+static int ddr_post_config(struct ddr_handoff *handoff)
+{
+       int ret;
+
+       ret = ddr_post_handoff_config(handoff->cntlr_base,
+                                     handoff->cntlr_t);
+       if (ret)
+               return ret;
+
+       if (handoff->cntlr2_t == DDRTYPE_LPDDR4_1)
+               ret = ddr_post_handoff_config(handoff->cntlr2_base,
+                                             handoff->cntlr2_t);
+
+       return ret;
+}

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+
+static bool is_ddr_retention_enabled(u32 boot_scratch_cold0_reg)
+{
+       return boot_scratch_cold0_reg &
+              ALT_SYSMGR_SCRATCH_REG_0_DDR_RETENTION_MASK;
+}
+
+static bool is_ddr_bitstream_sha_matching(u32 boot_scratch_cold0_reg)
+{
+       return boot_scratch_cold0_reg &

ALT_SYSMGR_SCRATCH_REG_0_DDR_SHA_MASK;

Quoted 101 lines
drivers/ddr/altera/Makefile +101 -0
+}
+
+static enum reset_type get_reset_type(u32 boot_scratch_cold0_reg)
+{
+       return (boot_scratch_cold0_reg &
+               ALT_SYSMGR_SCRATCH_REG_0_DDR_RESET_TYPE_MASK) >>
+               ALT_SYSMGR_SCRATCH_REG_0_DDR_RESET_TYPE_SHIFT;
+}
+
+void reset_type_debug_print(u32 boot_scratch_cold0_reg)
+{
+       switch (get_reset_type(boot_scratch_cold0_reg)) {
+       case POR_RESET:
+               debug("%s: POR is triggered\n", __func__);
+               break;
+       case WARM_RESET:
+               debug("%s: Warm reset is triggered\n", __func__);
+               break;
+       case COLD_RESET:
+               debug("%s: Cold reset is triggered\n", __func__);
+               break;
+       default:
+               debug("%s: Invalid reset type\n", __func__);
+       }
+}
+
+bool is_ddr_init(void)
+{
+       u32 reg = readl(socfpga_get_sysmgr_addr() +
+                       SYSMGR_SOC64_BOOT_SCRATCH_COLD0);
+
+       reset_type_debug_print(reg);
+
+       if (get_reset_type(reg) == POR_RESET) {
+               debug("%s: DDR init is required\n", __func__);
+               return true;
+       }
+
+       if (get_reset_type(reg) == WARM_RESET) {
+               debug("%s: DDR init is skipped\n", __func__);
+               return false;
+       }
+
+       if (get_reset_type(reg) == COLD_RESET) {
+               if (is_ddr_retention_enabled(reg) &&
+                   is_ddr_bitstream_sha_matching(reg)) {
+                       debug("%s: DDR retention bit is set\n", __func__);
+                       debug("%s: Matching in DDR bistream\n", __func__);
+                       debug("%s: DDR init is skipped\n", __func__);
+                       return false;
+               }
+       }
+
+       debug("%s: DDR init is required\n", __func__);
+       return true;
+}
+
+int sdram_mmr_init_full(struct udevice *dev)
+{
+       u32 user_backup[2], user_backup_2nd[2];
+       int ret;
+       struct bd_info bd;
+       struct ddr_handoff ddr_handoff_info;
+       struct altera_sdram_priv *priv = dev_get_priv(dev);
+
+       printf("Checking SDRAM configuration in progress ...\n");
+       ret = populate_ddr_handoff(&ddr_handoff_info);
+               if (ret) {
+                       debug("%s: Failed to populate DDR handoff\n",
+                             __func__);
+                       return ret;
+               }
+
+       /* Set the MPFE NoC mux to correct DDR controller type */
+       use_ddr4(ddr_handoff_info.cntlr_t);
+
+       if (is_ddr_init()) {
+               printf("SDRAM init in progress ...\n");
+
+               /*
+                * Polling reset complete, must be high to ensure DDR subsystem
+                * in complete reset state before init DDR clock and DDR
+                * controller
+                */
+               ret = wait_for_bit_le32((const void *)((uintptr_t)(readl
+                                       (ddr_handoff_info.mem_reset_base) +
+                                       MEM_RST_MGR_STATUS)),
+                                       MEM_RST_MGR_STATUS_RESET_COMPLETE,
+                                       true, TIMEOUT_200MS, false);
+               if (ret) {
+                       debug("%s: Timeout while waiting for", __func__);
+                       debug(" reset complete done\n");
+                       return ret;
+               }
+
+               ret = enable_ddr_clock(dev);
+               if (ret)
+                       return ret;
+
+               ret = init_controller(&ddr_handoff_info, user_backup,
+                                     user_backup_2nd);

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+               if (ret) {
+                       debug("%s: Failed to inilialize DDR controller\n",
+                             __func__);
+                       return ret;
+               }
+
+               /* Release the controller from reset */
+               setbits_le32((uintptr_t)
+                            (readl(ddr_handoff_info.mem_reset_base) +
+                            MEM_RST_MGR_STATUS), MEM_RST_MGR_STATUS_AXI_RST

|

Review

Quoted 97 lines
drivers/ddr/altera/Makefile +96 -0
+                            MEM_RST_MGR_STATUS_CONTROLLER_RST |
+                            MEM_RST_MGR_STATUS_RESET_COMPLETE);
+
+               printf("DDR controller configuration is completed\n");
+
+               /* Initialize DDR PHY */
+               ret = init_phy(&ddr_handoff_info);
+               if (ret) {
+                       debug("%s: Failed to inilialize DDR PHY\n", __func__);
+                       return ret;
+               }
+
+               enable_phy_clk_for_csr_access(&ddr_handoff_info, true);
+
+               ret = start_ddr_calibration(&ddr_handoff_info);
+               if (ret) {
+                       debug("%s: Failed to calibrate DDR\n", __func__);
+                       return ret;
+               }
+
+               enable_phy_clk_for_csr_access(&ddr_handoff_info, false);
+
+               /* Reset ARC processor when no using for security purpose */
+               setbits_le16(ddr_handoff_info.phy_base +
+                            DDR_PHY_MICRORESET_OFFSET,
+                            DDR_PHY_MICRORESET_RESET);
+
+               /* DDR freq set to support DDR4-3200 */
+               phy_init_engine(&ddr_handoff_info);
+
+               ret = dfi_init(&ddr_handoff_info);
+               if (ret)
+                       return ret;
+
+               ret = check_dfi_init(&ddr_handoff_info);
+               if (ret)
+                       return ret;
+
+               ret = trigger_sdram_init(&ddr_handoff_info);
+               if (ret)
+                       return ret;
+
+               ret = ddr_post_config(&ddr_handoff_info);
+               if (ret)
+                       return ret;
+
+               /* Restore user settings */
+               writel(user_backup[0], ddr_handoff_info.cntlr_base +
+                      DDR4_PWRCTL_OFFSET);
+
+               if (ddr_handoff_info.cntlr2_t == DDRTYPE_LPDDR4_0)
+                       setbits_le32(ddr_handoff_info.cntlr_base +
+                                    DDR4_INIT0_OFFSET, user_backup[1]);
+
+               if (ddr_handoff_info.cntlr2_t == DDRTYPE_LPDDR4_1) {
+                       /* Restore user settings */
+                       writel(user_backup_2nd[0],
+                              ddr_handoff_info.cntlr2_base +
+                              DDR4_PWRCTL_OFFSET);
+
+                       setbits_le32(ddr_handoff_info.cntlr2_base +
+                                    DDR4_INIT0_OFFSET, user_backup_2nd[1]);
+               }
+
+               /* Enable input traffic per port */
+               setbits_le32(ddr_handoff_info.cntlr_base + DDR4_PCTRL0_OFFSET,
+                            DDR4_PCTRL0_PORT_EN);
+
+               if (ddr_handoff_info.cntlr2_t == DDRTYPE_LPDDR4_1) {
+                       /* Enable input traffic per port */
+                       setbits_le32(ddr_handoff_info.cntlr2_base +
+                                    DDR4_PCTRL0_OFFSET, DDR4_PCTRL0_PORT_EN);
+               }
+
+               printf("DDR init success\n");
+       }
+
+       /* Get bank configuration from devicetree */
+       ret = fdtdec_decode_ram_size(gd->fdt_blob, NULL, 0, NULL,
+                                    (phys_size_t *)&gd->ram_size, &bd);
+       if (ret) {
+               debug("%s: Failed to decode memory node\n",  __func__);
+               return -1;
+       }
+
+       printf("DDR: %lld MiB\n", gd->ram_size >> 20);
+
+       priv->info.base = bd.bi_dram[0].start;
+       priv->info.size = gd->ram_size;
+
+       sdram_size_check(&bd);
+
+       sdram_set_firewall(&bd);
+
+       return 0;
+}
(quoted diff) +0 -0

b/drivers/ddr/altera/sdram_soc64.c

drivers/ddr/altera/sdram_soc64.c phys_size_t sdram_calculate_size(struct

Quoted 19 lines

index cc656db97c..d6baac2410 100644

drivers/ddr/altera/sdram_soc64.c +2 -0
@@ -100,12 +100,14 @@ int emif_reset(struct altera_sdram_plat *plat)
        return 0;
 }
 
+#if !IS_ENABLED(CONFIG_TARGET_SOCFPGA_N5X)
 int poll_hmc_clock_status(void)
 {
        return wait_for_bit_le32((const void *)(socfpga_get_sysmgr_addr() +
                                 SYSMGR_SOC64_HMC_CLK),
                                 SYSMGR_HMC_CLK_STATUS_MSK, true, 1000, false);
 }
+#endif
 
 void sdram_clear_mem(phys_addr_t addr, phys_size_t size)
 {
@@ -249,11 +251,78 @@ phys_size_t sdram_calculate_size(struct

altera_sdram_plat *plat)

Quoted 27 lines
drivers/ddr/altera/sdram_soc64.c +24 -0
        return size;
 }
 
+void sdram_set_firewall(struct bd_info *bd)
+{
+       u32 i;
+       phys_size_t value;
+       u32 lower, upper;
+
+       for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
+               if (!bd->bi_dram[i].size)
+                       continue;
+
+               value = bd->bi_dram[i].start;
+
+               /* Keep first 1MB of SDRAM memory region as secure region when
+                * using ATF flow, where the ATF code is located.
+                */
+               if (IS_ENABLED(CONFIG_SPL_ATF) && i == 0)
+                       value += SZ_1M;
+
+               /* Setting non-secure MPU region base and base extended */
+               lower = lower_32_bits(value);
+               upper = upper_32_bits(value);
+               FW_MPU_DDR_SCR_WRITEL(lower,
+                                     FW_MPU_DDR_SCR_MPUREGION0ADDR_BASE +
+                                     (i * 4 * sizeof(u32)));

drivers/ddr/altera/sdram_soc64.c phys_size_t sdram_calculate_size(struct altera_sdram_plat *plat)

Quoted 10 lines
drivers/ddr/altera/sdram_soc64.c +10 -0
+               FW_MPU_DDR_SCR_WRITEL(upper & 0xff,
+                                     FW_MPU_DDR_SCR_MPUREGION0ADDR_BASEEXT +
+                                     (i * 4 * sizeof(u32)));
+
+               /* Setting non-secure Non-MPU region base and base extended */
+               FW_MPU_DDR_SCR_WRITEL(lower,
+                                     FW_MPU_DDR_SCR_NONMPUREGION0ADDR_BASE +
+                                     (i * 4 * sizeof(u32)));
+               FW_MPU_DDR_SCR_WRITEL(upper & 0xff,
+                                     FW_MPU_DDR_SCR_NONMPUREGION0ADDR_BASEEXT

+

Quoted 11 lines
drivers/ddr/altera/sdram_soc64.c +11 -0
+                                     (i * 4 * sizeof(u32)));
+
+               /* Setting non-secure MPU limit and limit extexded */
+               value = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
+
+               lower = lower_32_bits(value);
+               upper = upper_32_bits(value);
+
+               FW_MPU_DDR_SCR_WRITEL(lower,
+                                     FW_MPU_DDR_SCR_MPUREGION0ADDR_LIMIT +
+                                     (i * 4 * sizeof(u32)));

drivers/ddr/altera/sdram_soc64.c phys_size_t sdram_calculate_size(struct altera_sdram_plat *plat)

Quoted 10 lines
drivers/ddr/altera/sdram_soc64.c +10 -0
+               FW_MPU_DDR_SCR_WRITEL(upper & 0xff,
+                                     FW_MPU_DDR_SCR_MPUREGION0ADDR_LIMITEXT +
+                                     (i * 4 * sizeof(u32)));
+
+               /* Setting non-secure Non-MPU limit and limit extexded */
+               FW_MPU_DDR_SCR_WRITEL(lower,
+                                     FW_MPU_DDR_SCR_NONMPUREGION0ADDR_LIMIT +
+                                     (i * 4 * sizeof(u32)));
+               FW_MPU_DDR_SCR_WRITEL(upper & 0xff,
+                                     FW_MPU_DDR_SCR_NONMPUREGION0ADDR_LIMITEXT

+

Review

Quoted 29 lines
drivers/ddr/altera/sdram_soc64.c +13 -0
+                                     (i * 4 * sizeof(u32)));
+
+               FW_MPU_DDR_SCR_WRITEL(BIT(i) | BIT(i + 8),
+                                     FW_MPU_DDR_SCR_EN_SET);
+       }
+}
+
 static int altera_sdram_of_to_plat(struct udevice *dev)
 {
        struct altera_sdram_plat *plat = dev_get_plat(dev);
        fdt_addr_t addr;
 
+       /* These regs info are part of DDR handoff in bitstream */
+#if IS_ENABLED(CONFIG_TARGET_SOCFPGA_N5X)
+       return 0;
+#endif
+
        addr = dev_read_addr_index(dev, 0);
        if (addr == FDT_ADDR_T_NONE)
                return -EINVAL;
@@ -314,6 +383,7 @@ static struct ram_ops altera_sdram_ops = {
 static const struct udevice_id altera_sdram_ids[] = {
        { .compatible = "altr,sdr-ctl-s10" },
        { .compatible = "intel,sdr-ctl-agilex" },
+       { .compatible = "intel,sdr-ctl-n5x" },
        { /* sentinel */ }
 };
 
(quoted diff) +0 -0

b/drivers/ddr/altera/sdram_soc64.h

Quoted 14 lines

index 8af0afc410..7460f8c220 100644

drivers/ddr/altera/sdram_soc64.h +1 -1
@@ -180,6 +180,7 @@ int emif_reset(struct altera_sdram_plat *plat);
 int poll_hmc_clock_status(void);
 void sdram_clear_mem(phys_addr_t addr, phys_size_t size);
 void sdram_init_ecc_bits(struct bd_info *bd);
+void sdram_set_firewall(struct bd_info *bd);
 void sdram_size_check(struct bd_info *bd);
 phys_size_t sdram_calculate_size(struct altera_sdram_plat *plat);
 int sdram_mmr_init_full(struct udevice *dev);
--

2.19.0

#23 lore raw

RE: [v2 12/17] ddr: altera: Add SDRAM driver for Intel N5X device

Hi Ley Foon,

Quoted 571 lines

-----Original Message-----
From: Chee, Tien Fong
Sent: Friday, 4 June, 2021 12:03 PM
To: Ley Foon Tan <[email protected]>; Lim, Elly Siew Chin <[email protected]>
Cc: ZY - u-boot <[email protected]>; Marek Vasut <[email protected]>; Tan, Ley Foon <[email protected]>; See, Chin Liang <[email protected]>; Simon Goldschmidt <[email protected]>; Westergreen, Dalon <[email protected]>; Simon Glass <[email protected]>; Gan, Yau Wai <[email protected]>
Subject: RE: [v2 12/17] ddr: altera: Add SDRAM driver for Intel N5X device

Hi Ley Foon,

Quoted 5 lines

-----Original Message-----
From: Ley Foon Tan <[email protected]>
Sent: Friday, 28 May, 2021 5:41 PM
To: Lim, Elly Siew Chin <[email protected]>
Cc: ZY - u-boot <[email protected]>; Marek Vasut <[email protected]>;

Tan,

Quoted 5 lines

Ley Foon <[email protected]>; See, Chin Liang <[email protected]>; Simon Goldschmidt <[email protected]>; Chee, Tien Fong <[email protected]>; Westergreen, Dalon <[email protected]>; Simon Glass <[email protected]>; Gan,

Yau

Quoted 59 lines

Wai <[email protected]>
Subject: Re: [v2 12/17] ddr: altera: Add SDRAM driver for Intel N5X device

Quoted 38 lines · Siew Chin Lim

The DDR subsystem in Diamond Mesa is consisted of controller, PHY, memory reset manager and memory clock manager.

Configuration settings of controller, PHY and memory reset manager is come from DDR handoff data in bitstream, which contain the register base addresses and user settings from tool.

Configuration settings of memory clock manager is come from the HPS handoff data in bitstream, however the register base address is defined in device tree.

The calibration is fully done in HPS, which requires IMEM and DMEM binaries loading to PHY SRAM for running this calibration, both IMEM and DMEM binaries are also part of bitstream, this bitstream would be loaded to OCRAM by SDM, and configured by DDR driver.

---
v2:
- Move is_ddr_init_skipped and its helper functions to DDR driver and converted function to positive checking
- Using GENMASK() macro
- Fixed typo
- Return status of subfunction
- Changed dm to n5x

---
 arch/arm/mach-socfpga/include/mach/firewall.h |    6 +
 .../include/mach/system_manager_soc64.h       |   10 +-
 drivers/ddr/altera/Makefile                   |    3 +-
 drivers/ddr/altera/sdram_n5x.c                | 2299 +++++++++++++++++
 drivers/ddr/altera/sdram_soc64.c              |   70 +
 drivers/ddr/altera/sdram_soc64.h              |    1 +
 6 files changed, 2387 insertions(+), 2 deletions(-)
 create mode 100644 drivers/ddr/altera/sdram_n5x.c

[..]

drivers/ddr/altera/Makefile line 7

Quoted 10 lines
drivers/ddr/altera/Makefile +1 -1
index 39dfee5d5a..9fa5d85a27 100644
@@ -4,11 +4,12 @@
 # Wolfgang Denk, DENX Software Engineering, [email protected].
 #
 # (C) Copyright 2010, Thomas Chou <[email protected]>
-# Copyright (C) 2014 Altera Corporation <www.altera.com>
+# Copyright (C) 2014-2021 Altera Corporation <www.altera.com>

Intel copyright

Quoted 4 lines

[...]

Quoted 1 line

+#include <common.h>

Sort include header.

Okay.

Quoted 249 lines
Quoted 15 lines
drivers/ddr/altera/Makefile +14 -0
+#include <asm/arch/firewall.h>
+#include <asm/arch/handoff_soc64.h>
+#include <asm/arch/misc.h>
+#include <asm/arch/reset_manager.h>
+#include <asm/arch/system_manager.h>
+#include <asm/global_data.h>
+#include <asm/io.h>
+#include <clk.h>
+#include <div64.h>
+#include <dm.h>
+#include <errno.h>
+#include <fdtdec.h>
+#include <hang.h>
+#include <linux/err.h>

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+#include <linux/sizes.h>
+#include <ram.h>
+#include <reset.h>
+#include "sdram_soc64.h"
+#include <wait_bit.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/* MPFE NOC registers */
+#define FPGA2SDRAM_MGR_MAIN_SIDEBANDMGR_FLAGOUTSET0

0xF8024050

Quoted 223 lines
drivers/ddr/altera/Makefile +223 -0
+
+/* Memory reset manager */
+#define MEM_RST_MGR_STATUS     0x8
+
+/* Register and bit in memory reset manager */
+#define MEM_RST_MGR_STATUS_RESET_COMPLETE      BIT(0)
+#define MEM_RST_MGR_STATUS_PWROKIN_STATUS      BIT(1)
+#define MEM_RST_MGR_STATUS_CONTROLLER_RST      BIT(2)
+#define MEM_RST_MGR_STATUS_AXI_RST             BIT(3)
+
+#define TIMEOUT_200MS     200
+#define TIMEOUT_5000MS    5000
+
+/* DDR4 umctl2 */
+#define DDR4_MSTR_OFFSET               0x0
+#define DDR4_FREQ_RATIO                        BIT(22)
+
+#define DDR4_STAT_OFFSET               0x4
+#define DDR4_STAT_SELFREF_TYPE         GENMASK(5, 4)
+#define DDR4_STAT_SELFREF_TYPE_SHIFT   4
+#define DDR4_STAT_OPERATING_MODE       GENMASK(2, 0)
+
+#define DDR4_MRCTRL0_OFFSET            0x10
+#define DDR4_MRCTRL0_MR_TYPE           BIT(0)
+#define DDR4_MRCTRL0_MPR_EN            BIT(1)
+#define DDR4_MRCTRL0_MR_RANK           GENMASK(5, 4)
+#define DDR4_MRCTRL0_MR_RANK_SHIFT     4
+#define DDR4_MRCTRL0_MR_ADDR           GENMASK(15, 12)
+#define DDR4_MRCTRL0_MR_ADDR_SHIFT     12
+#define DDR4_MRCTRL0_MR_WR             BIT(31)
+
+#define DDR4_MRCTRL1_OFFSET            0x14
+#define DDR4_MRCTRL1_MR_DATA           0x3FFFF
+
+#define DDR4_MRSTAT_OFFSET             0x18
+#define DDR4_MRSTAT_MR_WR_BUSY         BIT(0)
+
+#define DDR4_MRCTRL2_OFFSET            0x1C
+
+#define DDR4_PWRCTL_OFFSET                     0x30
+#define DDR4_PWRCTL_SELFREF_EN                 BIT(0)
+#define DDR4_PWRCTL_POWERDOWN_EN               BIT(1)
+#define DDR4_PWRCTL_EN_DFI_DRAM_CLK_DISABLE    BIT(3)
+#define DDR4_PWRCTL_SELFREF_SW                 BIT(5)
+
+#define DDR4_PWRTMG_OFFSET             0x34
+#define DDR4_HWLPCTL_OFFSET            0x38
+#define DDR4_RFSHCTL0_OFFSET           0x50
+#define DDR4_RFSHCTL1_OFFSET           0x54
+
+#define DDR4_RFSHCTL3_OFFSET                   0x60
+#define DDR4_RFSHCTL3_DIS_AUTO_REFRESH         BIT(0)
+#define DDR4_RFSHCTL3_REFRESH_MODE             GENMASK(6, 4)
+#define DDR4_RFSHCTL3_REFRESH_MODE_SHIFT       4
+
+#define DDR4_ECCCFG0_OFFSET            0x70
+#define DDR4_ECC_MODE                  GENMASK(2, 0)
+#define DDR4_DIS_SCRUB                 BIT(4)
+#define LPDDR4_ECCCFG0_ECC_REGION_MAP_GRANU_SHIFT      30
+#define LPDDR4_ECCCFG0_ECC_REGION_MAP_SHIFT    8
+
+#define DDR4_ECCCFG1_OFFSET            0x74
+#define LPDDR4_ECCCFG1_ECC_REGIONS_PARITY_LOCK BIT(4)
+
+#define DDR4_CRCPARCTL0_OFFSET                 0xC0
+#define DDR4_CRCPARCTL0_DFI_ALERT_ERR_INIT_CLR BIT(1)
+
+#define DDR4_CRCPARCTL1_OFFSET                 0xC4
+#define DDR4_CRCPARCTL1_CRC_PARITY_RETRY_ENABLE        BIT(8)
+#define DDR4_CRCPARCTL1_ALERT_WAIT_FOR_SW      BIT(9)
+
+#define DDR4_CRCPARSTAT_OFFSET                 0xCC
+#define DDR4_CRCPARSTAT_DFI_ALERT_ERR_INT      BIT(16)
+#define DDR4_CRCPARSTAT_DFI_ALERT_ERR_FATL_INT BIT(17)
+#define DDR4_CRCPARSTAT_DFI_ALERT_ERR_NO_SW    BIT(19)
+#define DDR4_CRCPARSTAT_CMD_IN_ERR_WINDOW      BIT(29)
+
+#define DDR4_INIT0_OFFSET                      0xD0
+#define DDR4_INIT0_SKIP_RAM_INIT               GENMASK(31, 30)
+
+#define DDR4_RANKCTL_OFFSET                    0xF4
+#define DDR4_RANKCTL_DIFF_RANK_RD_GAP          GENMASK(7, 4)
+#define DDR4_RANKCTL_DIFF_RANK_WR_GAP          GENMASK(11, 8)
+#define DDR4_RANKCTL_DIFF_RANK_RD_GAP_MSB      BIT(24)
+#define DDR4_RANKCTL_DIFF_RANK_WR_GAP_MSB      BIT(26)
+#define DDR4_RANKCTL_DIFF_RANK_RD_GAP_SHIFT    4
+#define DDR4_RANKCTL_DIFF_RANK_WR_GAP_SHIFT    8
+#define DDR4_RANKCTL_DIFF_RANK_RD_GAP_MSB_SHIFT        24
+#define DDR4_RANKCTL_DIFF_RANK_WR_GAP_MSB_SHIFT        26
+
+#define DDR4_RANKCTL1_OFFSET   0xF8
+#define DDR4_RANKCTL1_WR2RD_DR GENMASK(5, 0)
+
+#define DDR4_DRAMTMG2_OFFSET   0x108
+#define DDR4_DRAMTMG2_WR2RD    GENMASK(5, 0)
+#define DDR4_DRAMTMG2_RD2WR    GENMASK(13, 8)
+#define DDR4_DRAMTMG2_RD2WR_SHIFT      8
+
+#define DDR4_DRAMTMG9_OFFSET   0x124
+#define DDR4_DRAMTMG9_W2RD_S   GENMASK(5, 0)
+
+#define DDR4_DFITMG1_OFFSET    0x194
+#define DDR4_DFITMG1_DFI_T_WRDATA_DELAY        GENMASK(20, 16)
+#define DDR4_DFITMG1_DFI_T_WRDATA_SHIFT        16
+
+#define DDR4_DFIMISC_OFFSET                    0x1B0
+#define DDR4_DFIMISC_DFI_INIT_COMPLETE_EN      BIT(0)
+#define DDR4_DFIMISC_DFI_INIT_START            BIT(5)
+
+#define DDR4_DFISTAT_OFFSET            0x1BC
+#define DDR4_DFI_INIT_COMPLETE         BIT(0)
+
+#define DDR4_DBG0_OFFSET               0x300
+
+#define DDR4_DBG1_OFFSET               0x304
+#define DDR4_DBG1_DISDQ                        BIT(0)
+#define DDR4_DBG1_DIS_HIF              BIT(1)
+
+#define DDR4_DBGCAM_OFFSET                     0x308
+#define DDR4_DBGCAM_DBG_RD_Q_EMPTY             BIT(25)
+#define DDR4_DBGCAM_DBG_WR_Q_EMPTY             BIT(26)
+#define DDR4_DBGCAM_RD_DATA_PIPELINE_EMPTY     BIT(28)
+#define DDR4_DBGCAM_WR_DATA_PIPELINE_EMPTY     BIT(29)
+
+#define DDR4_SWCTL_OFFSET              0x320
+#define DDR4_SWCTL_SW_DONE             BIT(0)
+
+#define DDR4_SWSTAT_OFFSET             0x324
+#define DDR4_SWSTAT_SW_DONE_ACK                BIT(0)
+
+#define DDR4_PSTAT_OFFSET              0x3FC
+#define DDR4_PSTAT_RD_PORT_BUSY_0      BIT(0)
+#define DDR4_PSTAT_WR_PORT_BUSY_0      BIT(16)
+
+#define DDR4_PCTRL0_OFFSET             0x490
+#define DDR4_PCTRL0_PORT_EN            BIT(0)
+
+#define DDR4_SBRCTL_OFFSET             0xF24
+#define DDR4_SBRCTL_SCRUB_INTERVAL     0x1FFF00
+#define DDR4_SBRCTL_SCRUB_EN           BIT(0)
+#define DDR4_SBRCTL_SCRUB_WRITE                BIT(2)
+#define DDR4_SBRCTL_SCRUB_BURST_1      BIT(4)
+
+#define DDR4_SBRSTAT_OFFSET            0xF28
+#define DDR4_SBRSTAT_SCRUB_BUSY BIT(0)
+#define DDR4_SBRSTAT_SCRUB_DONE BIT(1)
+
+#define DDR4_SBRWDATA0_OFFSET          0xF2C
+#define DDR4_SBRWDATA1_OFFSET          0xF30
+#define DDR4_SBRSTART0_OFFSET          0xF38
+#define DDR4_SBRSTART1_OFFSET          0xF3C
+#define DDR4_SBRRANGE0_OFFSET          0xF40
+#define DDR4_SBRRANGE1_OFFSET          0xF44
+
+/* DDR PHY */
+#define DDR_PHY_TXODTDRVSTREN_B0_P0            0x2009A
+#define DDR_PHY_RXPBDLYTG0_R0                  0x200D0
+#define DDR_PHY_DBYTE0_TXDQDLYTG0_U0_P0                0x201A0
+
+#define DDR_PHY_DBYTE0_TXDQDLYTG0_U1_P0                0x203A0
+#define DDR_PHY_DBYTE1_TXDQDLYTG0_U0_P0                0x221A0
+#define DDR_PHY_DBYTE1_TXDQDLYTG0_U1_P0                0x223A0
+#define DDR_PHY_TXDQDLYTG0_COARSE_DELAY                GENMASK(9, 6)
+#define DDR_PHY_TXDQDLYTG0_COARSE_DELAY_SHIFT  6
+
+#define DDR_PHY_CALRATE_OFFSET                 0x40110
+#define DDR_PHY_CALZAP_OFFSET                  0x40112
+#define DDR_PHY_SEQ0BDLY0_P0_OFFSET            0x40016
+#define DDR_PHY_SEQ0BDLY1_P0_OFFSET            0x40018
+#define DDR_PHY_SEQ0BDLY2_P0_OFFSET            0x4001A
+#define DDR_PHY_SEQ0BDLY3_P0_OFFSET            0x4001C
+
+#define DDR_PHY_MEMRESETL_OFFSET               0x400C0
+#define DDR_PHY_MEMRESETL_VALUE                        BIT(0)
+#define DDR_PHY_PROTECT_MEMRESET               BIT(1)
+
+#define DDR_PHY_CALBUSY_OFFSET                 0x4012E
+#define DDR_PHY_CALBUSY                                BIT(0)
+
+#define DDR_PHY_TRAIN_IMEM_OFFSET              0xA0000
+#define DDR_PHY_TRAIN_DMEM_OFFSET              0xA8000
+
+#define DMEM_MB_CDD_RR_1_0_OFFSET              0xA802C
+#define DMEM_MB_CDD_RR_0_1_OFFSET              0xA8030
+#define DMEM_MB_CDD_WW_1_0_OFFSET              0xA8038
+#define DMEM_MB_CDD_WW_0_1_OFFSET              0xA803C
+#define DMEM_MB_CDD_RW_1_1_OFFSET              0xA8046
+#define DMEM_MB_CDD_RW_1_0_OFFSET              0xA8048
+#define DMEM_MB_CDD_RW_0_1_OFFSET              0xA804A
+#define DMEM_MB_CDD_RW_0_0_OFFSET              0xA804C
+
+#define DMEM_MB_CDD_CHA_RR_1_0_OFFSET          0xA8026
+#define DMEM_MB_CDD_CHA_RR_0_1_OFFSET          0xA8026
+#define DMEM_MB_CDD_CHB_RR_1_0_OFFSET          0xA8058
+#define DMEM_MB_CDD_CHB_RR_0_1_OFFSET          0xA805A
+#define DMEM_MB_CDD_CHA_WW_1_0_OFFSET          0xA8030
+#define DMEM_MB_CDD_CHA_WW_0_1_OFFSET          0xA8030
+#define DMEM_MB_CDD_CHB_WW_1_0_OFFSET          0xA8062
+#define DMEM_MB_CDD_CHB_WW_0_1_OFFSET          0xA8064
+
+#define DMEM_MB_CDD_CHA_RW_1_1_OFFSET          0xA8028
+#define DMEM_MB_CDD_CHA_RW_1_0_OFFSET          0xA8028
+#define DMEM_MB_CDD_CHA_RW_0_1_OFFSET          0xA802A
+#define DMEM_MB_CDD_CHA_RW_0_0_OFFSET          0xA802A
+
+#define DMEM_MB_CDD_CHB_RW_1_1_OFFSET          0xA805A
+#define DMEM_MB_CDD_CHB_RW_1_0_OFFSET          0xA805C
+#define DMEM_MB_CDD_CHB_RW_0_1_OFFSET          0xA805c
+#define DMEM_MB_CDD_CHB_RW_0_0_OFFSET          0xA805E
+
+#define DDR_PHY_SEQ0DISABLEFLAG0_OFFSET                0x120018
+#define DDR_PHY_SEQ0DISABLEFLAG1_OFFSET                0x12001A
+#define DDR_PHY_SEQ0DISABLEFLAG2_OFFSET                0x12001C
+#define DDR_PHY_SEQ0DISABLEFLAG3_OFFSET                0x12001E
+#define DDR_PHY_SEQ0DISABLEFLAG4_OFFSET                0x120020
+#define DDR_PHY_SEQ0DISABLEFLAG5_OFFSET                0x120022
+#define DDR_PHY_SEQ0DISABLEFLAG6_OFFSET                0x120024
+#define DDR_PHY_SEQ0DISABLEFLAG7_OFFSET                0x120026
+
+#define DDR_PHY_UCCLKHCLKENABLES_OFFSET                0x180100
+#define DDR_PHY_UCCLKHCLKENABLES_UCCLKEN       BIT(0)
+#define DDR_PHY_UCCLKHCLKENABLES_HCLKEN                BIT(1)
+
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+#define DDR_PHY_UCTWRITEPROT_OFFSET            0x180066
+#define DDR_PHY_UCTWRITEPROT                   BIT(0)
+
+#define DDR_PHY_APBONLY0_OFFSET                        0x1A0000
+#define DDR_PHY_MICROCONTMUXSEL                        BIT(0)
+
+#define DDR_PHY_UCTSHADOWREGS_OFFSET                   0x1A0008
+#define DDR_PHY_UCTSHADOWREGS_UCTWRITEPROTESHADOW

BIT(0)

Quoted 22 lines
Quoted 22 lines
drivers/ddr/altera/Makefile +22 -0
+
+#define DDR_PHY_DCTWRITEPROT_OFFSET            0x1A0062
+#define DDR_PHY_DCTWRITEPROT                   BIT(0)
+
+#define DDR_PHY_UCTWRITEONLYSHADOW_OFFSET      0x1A0064
+#define DDR_PHY_UCTDATWRITEONLYSHADOW_OFFSET   0x1A0068
+
+#define DDR_PHY_MICRORESET_OFFSET              0x1A0132
+#define DDR_PHY_MICRORESET_STALL               BIT(0)
+#define DDR_PHY_MICRORESET_RESET               BIT(3)
+
+#define DDR_PHY_TXODTDRVSTREN_B0_P1            0x22009A
+
+/* For firmware training */
+#define HW_DBG_TRACE_CONTROL_OFFSET    0x18
+#define FW_TRAINING_COMPLETED_STAT     0x07
+#define FW_TRAINING_FAILED_STAT                0xFF
+#define FW_COMPLETION_MSG_ONLY_MODE    0xFF
+#define FW_STREAMING_MSG_ID            0x08
+#define GET_LOWHW_DATA(x)              ((x) & 0xFFFF)
+#define GET_LOWB_DATA(x)               ((x) & 0xFF)
+#define GET_HIGHB_DATA(x)              (((x) & 0xFF00) >> 8)
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 7 lines
drivers/ddr/altera/Makefile +7 -0
+
+/* Operating mode */
+#define INIT_OPM                       0x000
+#define NORMAL_OPM                     0x001
+#define PWR_D0WN_OPM                   0x010
+#define SELF_SELFREF_OPM               0x011
+#define DDR4_DEEP_PWR_DOWN_OPM         0x100

Use prefix OPM_xxx

Okay.

Quoted 178 lines
Quoted 90 lines
drivers/ddr/altera/Makefile +89 -0
+
+/* Refresh mode */
+#define FIXED_1X               0
+#define FIXED_2X               BIT(0)
+#define FIXED_4X               BIT(4)
+
+/* Address of mode register */
+#define MR0    0x0000
+#define MR1    0x0001
+#define MR2    0x0010
+#define MR3    0x0011
+#define MR4    0x0100
+#define MR5    0x0101
+#define MR6    0x0110
+#define MR7    0x0111
+
+/* MR rank */
+#define RANK0          0x1
+#define RANK1          0x2
+#define ALL_RANK       0x3
+
+#define MR5_BIT4       BIT(4)
+
+/* Value for ecc_region_map */
+#define ALL_PROTECTED  0x7F
+
+/* Region size for ECCCFG0.ecc_region_map */
+enum region_size {
+       ONE_EIGHT,
+       ONE_SIXTEENTH,
+       ONE_THIRTY_SECOND,
+       ONE_SIXTY_FOURTH
+};
+
+enum ddr_type {
+       DDRTYPE_LPDDR4_0,
+       DDRTYPE_LPDDR4_1,
+       DDRTYPE_DDR4,
+       DDRTYPE_UNKNOWN
+};
+
+/* Reset type */
+enum reset_type {
+       POR_RESET,
+       WARM_RESET,
+       COLD_RESET
+};
+
+/* DDR handoff structure */
+struct ddr_handoff {
+       /* Memory reset manager base */
+       phys_addr_t mem_reset_base;
+
+       /* First controller attributes */
+       phys_addr_t cntlr_handoff_base;
+       phys_addr_t cntlr_base;
+       size_t cntlr_total_length;
+       enum ddr_type cntlr_t;
+       size_t cntlr_handoff_length;
+
+       /* Second controller attributes*/
+       phys_addr_t cntlr2_handoff_base;
+       phys_addr_t cntlr2_base;
+       size_t cntlr2_total_length;
+       enum ddr_type cntlr2_t;
+       size_t cntlr2_handoff_length;
+
+       /* PHY attributes */
+       phys_addr_t phy_handoff_base;
+       phys_addr_t phy_base;
+       size_t phy_total_length;
+       size_t phy_handoff_length;
+
+       /* PHY engine attributes */
+       phys_addr_t phy_engine_handoff_base;
+       size_t phy_engine_total_length;
+       size_t phy_engine_handoff_length;
+
+       /* Calibration attributes */
+       phys_addr_t train_imem_base;
+       phys_addr_t train_dmem_base;
+       size_t train_imem_length;
+       size_t train_dmem_length;
+};
+
+/* Message mode */
+enum message_mode {
+       MAJOR_MESSAGE,
+       STREAMING_MESSAGE

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+};
+
+static int clr_ca_parity_error_status(phys_addr_t umctl2_base)
+{
+       int ret;
+
+       debug("%s: Clear C/A parity error status in MR5[4]\n", __func__);
+
+       /* Set mode register MRS */
+       clrbits_le32(umctl2_base + DDR4_MRCTRL0_OFFSET,

DDR4_MRCTRL0_MPR_EN);

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+
+       /* Set mode register to write operation */
+       setbits_le32(umctl2_base + DDR4_MRCTRL0_OFFSET,

DDR4_MRCTRL0_MR_TYPE);

Quoted 6 lines
drivers/ddr/altera/Makefile +6 -0
+
+       /* Set the address of mode rgister to 0x101(MR5) */
+       setbits_le32(umctl2_base + DDR4_MRCTRL0_OFFSET,
+                    (MR5 << DDR4_MRCTRL0_MR_ADDR_SHIFT) &
+                    DDR4_MRCTRL0_MR_ADDR);
+

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+       /* Set MR rank to rank 1 */
+       setbits_le32(umctl2_base + DDR4_MRCTRL0_OFFSET,
+                    (RANK1 << DDR4_MRCTRL0_MR_RANK_SHIFT) &
+                    DDR4_MRCTRL0_MR_RANK);
+
+       /* Clear C/A parity error status in MR5[4] */
+       clrbits_le32(umctl2_base + DDR4_MRCTRL1_OFFSET, MR5_BIT4);
+
+       /* Trigger mode register read or write operation */
+       setbits_le32(umctl2_base + DDR4_MRCTRL0_OFFSET,

DDR4_MRCTRL0_MR_WR);

Quoted 56 lines
drivers/ddr/altera/Makefile +56 -0
+
+       /* Wait for retry done */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_MRSTAT_OFFSET), DDR4_MRSTAT_MR_WR_BUSY,
+                               false, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" no outstanding MR transaction\n");
+               return ret;
+       }
+
+       return 0;
+}
+
+static int ddr_retry_software_sequence(phys_addr_t umctl2_base)
+{
+       u32 value;
+       int ret;
+
+       /* Check software can perform MRS/MPR/PDA? */
+       value = readl(umctl2_base + DDR4_CRCPARSTAT_OFFSET) &
+                     DDR4_CRCPARSTAT_DFI_ALERT_ERR_NO_SW;
+
+       if (value) {
+               /* Clear interrupt bit for DFI alert error */
+               setbits_le32(umctl2_base + DDR4_CRCPARCTL0_OFFSET,
+                            DDR4_CRCPARCTL0_DFI_ALERT_ERR_INIT_CLR);
+       }
+
+       debug("%s: Software can perform MRS/MPR/PDA\n", __func__);
+
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_MRSTAT_OFFSET),
+                               DDR4_MRSTAT_MR_WR_BUSY,
+                               false, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" no outstanding MR transaction\n");
+               return ret;
+       }
+
+       ret = clr_ca_parity_error_status(umctl2_base);
+       if (ret)
+               return ret;
+
+       if (!value) {
+               /* Clear interrupt bit for DFI alert error */
+               setbits_le32(umctl2_base + DDR4_CRCPARCTL0_OFFSET,
+                            DDR4_CRCPARCTL0_DFI_ALERT_ERR_INIT_CLR);
+       }
+
+       return 0;
+}
+
+static int ensure_retry_procedure_complete(phys_addr_t umctl2_base)
+{
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 7 lines
drivers/ddr/altera/Makefile +7 -0
+       u32 value;
+       u32 start = get_timer(0);
+       int ret;
+
+       /* Check parity/crc/error window is emptied ? */
+       value = readl(umctl2_base + DDR4_CRCPARSTAT_OFFSET) &
+                     DDR4_CRCPARSTAT_CMD_IN_ERR_WINDOW;

Can simplify the code with do...while loop.

Quoted 1 line

Okay.

I think this is a right implementation, the while loop would be skipped if value is zero, that's also means no error. Hence, I'm not agree to use do...while for this case.

Quoted 2,118 lines
Quoted 75 lines
Quoted 54 lines
drivers/ddr/altera/Makefile +52 -0
+
+       /* Polling until parity/crc/error window is emptied */
+       while (value) {
+               if (get_timer(start) > TIMEOUT_200MS) {
+                       debug("%s: Timeout while waiting for",
+                             __func__);
+                       debug(" parity/crc/error window empty\n");
+                       return -ETIMEDOUT;
+               }
+
+               /* Check software intervention is enabled? */
+               value = readl(umctl2_base + DDR4_CRCPARCTL1_OFFSET) &
+                             DDR4_CRCPARCTL1_ALERT_WAIT_FOR_SW;
+               if (value) {
+                       debug("%s: Software intervention is enabled\n",
+                             __func__);
+
+                       /* Check dfi alert error interrupt is set? */
+                       value = readl(umctl2_base + DDR4_CRCPARSTAT_OFFSET) &
+                                     DDR4_CRCPARSTAT_DFI_ALERT_ERR_INT;
+
+                       if (value) {
+                               ret = ddr_retry_software_sequence(umctl2_base);
+                               debug("%s: DFI alert error interrupt ",
+                                     __func__);
+                               debug("is set\n");
+
+                               if (ret)
+                                       return ret;
+                       }
+
+                       /*
+                        * Check fatal parity error interrupt is set?
+                        */
+                       value = readl(umctl2_base + DDR4_CRCPARSTAT_OFFSET) &
+                                     DDR4_CRCPARSTAT_DFI_ALERT_ERR_FATL_INT;
+                       if (value) {
+                               printf("%s: Fatal parity error  ",
+                                      __func__);
+                               printf("interrupt is set, Hang it!!\n");
+                               hang();
+                       }
+               }
+
+               value = readl(umctl2_base + DDR4_CRCPARSTAT_OFFSET) &
+                             DDR4_CRCPARSTAT_CMD_IN_ERR_WINDOW;
+
+               udelay(1);
+               WATCHDOG_RESET();
+       }
+
+       return 0;

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+}
+
+static int enable_quasi_dynamic_reg_grp3(phys_addr_t umctl2_base,
+                                        enum ddr_type umctl2_type)
+{
+       u32 i, value, backup;
+       int ret = 0;
+
+       /* Disable input traffic per port */
+       clrbits_le32(umctl2_base + DDR4_PCTRL0_OFFSET,

DDR4_PCTRL0_PORT_EN);

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+
+       /* Polling AXI port until idle */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_PSTAT_OFFSET),
+                               DDR4_PSTAT_WR_PORT_BUSY_0 |
+                               DDR4_PSTAT_RD_PORT_BUSY_0, false,
+                               TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" controller idle\n");
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+               return ret;
+       }
+
+       /* Backup user setting */
+       backup = readl(umctl2_base + DDR4_DBG1_OFFSET);
+
+       /* Disable input traffic to the controller */
+       setbits_le32(umctl2_base + DDR4_DBG1_OFFSET,

DDR4_DBG1_DIS_HIF);

Quoted 35 lines
Quoted 35 lines
drivers/ddr/altera/Makefile +35 -0
+
+       /*
+        * Ensure CAM/data pipelines are empty.
+        * Poll until CAM/data pipelines are set at least twice,
+        * timeout at 200ms
+        */
+       for (i = 0; i < 2; i++) {
+               ret = wait_for_bit_le32((const void *)(umctl2_base +
+                                       DDR4_DBGCAM_OFFSET),
+                                       DDR4_DBGCAM_WR_DATA_PIPELINE_EMPTY |
+                                       DDR4_DBGCAM_RD_DATA_PIPELINE_EMPTY |
+                                       DDR4_DBGCAM_DBG_WR_Q_EMPTY |
+                                       DDR4_DBGCAM_DBG_RD_Q_EMPTY, true,
+                                       TIMEOUT_200MS, false);
+               if (ret) {
+                       debug("%s: loop(%u): Timeout while waiting for",
+                             __func__, i + 1);
+                       debug(" CAM/data pipelines are empty\n");
+
+                       goto out;
+               }
+       }
+
+       if (umctl2_type == DDRTYPE_DDR4) {
+               /* Check DDR4 retry is enabled ? */
+               value = readl(umctl2_base + DDR4_CRCPARCTL1_OFFSET) &
+                             DDR4_CRCPARCTL1_CRC_PARITY_RETRY_ENABLE;
+
+               if (value) {
+                       debug("%s: DDR4 retry is enabled\n", __func__);
+
+                       ret = ensure_retry_procedure_complete(umctl2_base);
+                       if (ret) {
+                               debug("%s: Timeout while waiting for",
+                                     __func__);
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+                               debug(" retry procedure complete\n");
+
+                               goto out;
+                       }
+               }
+       }
+
+       debug("%s: Quasi-dynamic group 3 registers are enabled\n",

__func__);

Quoted 8 lines
Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+
+out:
+       /* Restore user setting */
+       writel(backup, umctl2_base + DDR4_DBG1_OFFSET);
+
+       return ret;
+}
+
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+static enum ddr_type get_ddr_type(phys_addr_t ddr_type_location)
+{
+       u32 ddr_type_magic = readl(ddr_type_location);
+
+       if (ddr_type_magic == SOC64_HANDOFF_DDR_UMCTL2_DDR4_TYPE)
+               return DDRTYPE_DDR4;
+
+       if (ddr_type_magic ==

SOC64_HANDOFF_DDR_UMCTL2_LPDDR4_0_TYPE)

Quoted 3 lines

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+               return DDRTYPE_LPDDR4_0;
+
+       if (ddr_type_magic ==

SOC64_HANDOFF_DDR_UMCTL2_LPDDR4_1_TYPE)

Quoted 31 lines

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+               return DDRTYPE_LPDDR4_1;
+
+       return DDRTYPE_UNKNOWN;
+}
+
+static void use_lpddr4_interleaving(bool set)
+{
+       if (set) {
+               printf("Starting LPDDR4 interleaving configuration ...\n");
+

setbits_le32(FPGA2SDRAM_MGR_MAIN_SIDEBANDMGR_FLAGOUTSET0,

drivers/ddr/altera/Makefile

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+                            BIT(5));
+       } else {
+               printf("Starting LPDDR4 non-interleaving configuration ...\n");
+

clrbits_le32(FPGA2SDRAM_MGR_MAIN_SIDEBANDMGR_FLAGOUTSET0,

drivers/ddr/altera/Makefile

Quoted 9 lines
drivers/ddr/altera/Makefile +9 -0
+                            BIT(5));
+       }
+}
+
+static void use_ddr4(enum ddr_type type)
+{
+       if (type == DDRTYPE_DDR4) {
+               printf("Starting DDR4 configuration ...\n");
+               setbits_le32(socfpga_get_sysmgr_addr() +

SYSMGR_SOC64_DDR_MODE,

drivers/ddr/altera/Makefile

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+                            SYSMGR_SOC64_DDR_MODE_MSK);
+       } else if (type == DDRTYPE_LPDDR4_0)  {
+               printf("Starting LPDDR4 configuration ...\n");
+               clrbits_le32(socfpga_get_sysmgr_addr() +

SYSMGR_SOC64_DDR_MODE,

Quoted 13 lines

drivers/ddr/altera/Makefile

Quoted 13 lines
drivers/ddr/altera/Makefile +13 -0
+                            SYSMGR_SOC64_DDR_MODE_MSK);
+
+               use_lpddr4_interleaving(false);
+       }
+}
+
+static int scrubber_ddr_config(phys_addr_t umctl2_base,
+                              enum ddr_type umctl2_type)
+{
+       u32 backup[9];
+       int ret;
+
+       /* Reset to default value, prevent scrubber stop due to lower power

*/

Quoted 45 lines
Quoted 12 lines
drivers/ddr/altera/Makefile +12 -0
+       writel(0, umctl2_base + DDR4_PWRCTL_OFFSET);
+
+       /* Backup user settings */
+       backup[0] = readl(umctl2_base + DDR4_SBRCTL_OFFSET);
+       backup[1] = readl(umctl2_base + DDR4_SBRWDATA0_OFFSET);
+       backup[2] = readl(umctl2_base + DDR4_SBRSTART0_OFFSET);
+       if (umctl2_type == DDRTYPE_DDR4) {
+               backup[3] = readl(umctl2_base + DDR4_SBRWDATA1_OFFSET);
+               backup[4] = readl(umctl2_base + DDR4_SBRSTART1_OFFSET);
+       }
+       backup[5] = readl(umctl2_base + DDR4_SBRRANGE0_OFFSET);
+       backup[6] = readl(umctl2_base + DDR4_SBRRANGE1_OFFSET);

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+       backup[7] = readl(umctl2_base + DDR4_ECCCFG0_OFFSET);
+       backup[8] = readl(umctl2_base + DDR4_ECCCFG1_OFFSET);
+
+       if (umctl2_type != DDRTYPE_DDR4) {
+               /* Lock ECC region, ensure this regions is not being accessed */
+               setbits_le32(umctl2_base + DDR4_ECCCFG1_OFFSET,
+                            LPDDR4_ECCCFG1_ECC_REGIONS_PARITY_LOCK);
+       }
+       /* Disable input traffic per port */
+       clrbits_le32(umctl2_base + DDR4_PCTRL0_OFFSET,

DDR4_PCTRL0_PORT_EN);

drivers/ddr/altera/Makefile

Quoted 2 lines
drivers/ddr/altera/Makefile +2 -0
+       /* Disables scrubber */
+       clrbits_le32(umctl2_base + DDR4_SBRCTL_OFFSET,

DDR4_SBRCTL_SCRUB_EN);

Quoted 9 lines
drivers/ddr/altera/Makefile +9 -0
+       /* Polling all scrub writes data have been sent */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SBRSTAT_OFFSET), DDR4_SBRSTAT_SCRUB_BUSY,
+                               false, TIMEOUT_5000MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" sending all scrub data\n");
+               return ret;
+       }

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+
+       /* LPDDR4 supports inline ECC only */
+       if (umctl2_type != DDRTYPE_DDR4) {
+               /*
+                * Setting all regions for protected, this is required for
+                * srubber to init whole LPDDR4 expect ECC region
+                */
+               writel(((ONE_EIGHT <<
+                      LPDDR4_ECCCFG0_ECC_REGION_MAP_GRANU_SHIFT) |
+                      (ALL_PROTECTED <<
Quoted 6 lines

LPDDR4_ECCCFG0_ECC_REGION_MAP_SHIFT)),

Quoted 5 lines
drivers/ddr/altera/Makefile +5 -0
+                      umctl2_base + DDR4_ECCCFG0_OFFSET);
+       }
+
+       /* Scrub_burst = 1, scrub_mode = 1(performs writes) */
+       writel(DDR4_SBRCTL_SCRUB_BURST_1 |

DDR4_SBRCTL_SCRUB_WRITE,

Quoted 23 lines
Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+              umctl2_base + DDR4_SBRCTL_OFFSET);
+
+       /* Zeroing whole DDR */
+       writel(0, umctl2_base + DDR4_SBRWDATA0_OFFSET);

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+       writel(0, umctl2_base + DDR4_SBRSTART0_OFFSET);
+       if (umctl2_type == DDRTYPE_DDR4) {
+               writel(0, umctl2_base + DDR4_SBRWDATA1_OFFSET);
+               writel(0, umctl2_base + DDR4_SBRSTART1_OFFSET);
+       }
+       writel(0, umctl2_base + DDR4_SBRRANGE0_OFFSET);
+       writel(0, umctl2_base + DDR4_SBRRANGE1_OFFSET);
+
+       /* Enables scrubber */
+       setbits_le32(umctl2_base + DDR4_SBRCTL_OFFSET,

DDR4_SBRCTL_SCRUB_EN);

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+       /* Polling all scrub writes commands have been sent */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SBRSTAT_OFFSET), DDR4_SBRSTAT_SCRUB_DONE,
+                               true, TIMEOUT_5000MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" sending all scrub commands\n");
+               return ret;
Quoted 1 line

Need restore user settings before return?

No need because this is considered error, and system would hang for watchdog to kick in.

Quoted 11 lines

drivers/ddr/altera/Makefile

Quoted 11 lines
drivers/ddr/altera/Makefile +10 -0
+       }
+
+       /* Polling all scrub writes data have been sent */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SBRSTAT_OFFSET), DDR4_SBRSTAT_SCRUB_BUSY,
+                               false, TIMEOUT_5000MS, false);
+       if (ret) {
+               printf("%s: Timeout while waiting for", __func__);
+               printf(" sending all scrub data\n");
+               return ret;
Quoted 1 line

Same here.

No need because this is considered error, and system would hang for watchdog to kick in.

Quoted 41 lines

drivers/ddr/altera/Makefile

Quoted 5 lines
drivers/ddr/altera/Makefile +4 -0
+       }
+
+       /* Disables scrubber */
+       clrbits_le32(umctl2_base + DDR4_SBRCTL_OFFSET,

DDR4_SBRCTL_SCRUB_EN);

Quoted 35 lines
drivers/ddr/altera/Makefile +35 -0
+
+       /* Restore user settings */
+       writel(backup[0], umctl2_base + DDR4_SBRCTL_OFFSET);
+       writel(backup[1], umctl2_base + DDR4_SBRWDATA0_OFFSET);
+       writel(backup[2], umctl2_base + DDR4_SBRSTART0_OFFSET);
+       if (umctl2_type == DDRTYPE_DDR4) {
+               writel(backup[3], umctl2_base + DDR4_SBRWDATA1_OFFSET);
+               writel(backup[4], umctl2_base + DDR4_SBRSTART1_OFFSET);
+       }
+       writel(backup[5], umctl2_base + DDR4_SBRRANGE0_OFFSET);
+       writel(backup[6], umctl2_base + DDR4_SBRRANGE1_OFFSET);
+       writel(backup[7], umctl2_base + DDR4_ECCCFG0_OFFSET);
+       writel(backup[8], umctl2_base + DDR4_ECCCFG1_OFFSET);
+
+       /* Enables ECC scrub on scrubber */
+       if (!(readl(umctl2_base + DDR4_SBRCTL_OFFSET) &
+           DDR4_SBRCTL_SCRUB_WRITE)) {
+               /* Enables scrubber */
+               setbits_le32(umctl2_base + DDR4_SBRCTL_OFFSET,
+                            DDR4_SBRCTL_SCRUB_EN);
+       }
+
+       return 0;
+}
+
+static int init_umctl2(phys_addr_t umctl2_handoff_base,
+                      phys_addr_t umctl2_base, enum ddr_type umctl2_type,
+                      size_t umctl2_handoff_length,
+                      u32 *user_backup)
+{
+       u32 handoff_table[umctl2_handoff_length];
+       u32 i;
+       int ret;
+
+       if (umctl2_type == DDRTYPE_DDR4)
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+               printf("Initializing DDR4 controller ...\n");
+       else if (umctl2_type == DDRTYPE_LPDDR4_0)
+               printf("Initializing LPDDR4_0 controller ...\n");
+       else if (umctl2_type == DDRTYPE_LPDDR4_1)
+               printf("Initializing LPDDR4_1 controller ...\n");
+
+       /* Prevent controller from issuing read/write to SDRAM */
+       setbits_le32(umctl2_base + DDR4_DBG1_OFFSET,

DDR4_DBG1_DISDQ);

Quoted 4 lines

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+
+       /* Put SDRAM into self-refresh */
+       setbits_le32(umctl2_base + DDR4_PWRCTL_OFFSET,

DDR4_PWRCTL_SELFREF_EN);

Quoted 9 lines

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+
+       /* Enable quasi-dynamic programing of the controller registers */
+       clrbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+
+       /* Ensure the controller is in initialization mode */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +

DDR4_STAT_OFFSET),

Quoted 1 line

+ DDR4_STAT_OPERATING_MODE, false,

TIMEOUT_200MS,

Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+                               false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" init operating mode\n");
+               return ret;
+       }
+
+       debug("%s: UMCTL2 handoff base address = 0x%p table length =
Quoted 5 lines

0x%08x\n",

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+             __func__, (u32 *)umctl2_handoff_base,
+             (u32)umctl2_handoff_length);
+
+       socfpga_handoff_read((void *)umctl2_handoff_base,

handoff_table,

Quoted 5 lines
Quoted 5 lines
drivers/ddr/altera/Makefile +5 -0
+                            umctl2_handoff_length);
+
+       for (i = 0; i < umctl2_handoff_length; i = i + 2) {
+               debug("%s: Absolute addr: 0x%08llx APB offset: 0x%08x",
+                     __func__, handoff_table[i] + umctl2_base,
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 6 lines
drivers/ddr/altera/Makefile +6 -0
+                     handoff_table[i]);
+               debug(" wr = 0x%08x ", handoff_table[i + 1]);
+
+               writel(handoff_table[i + 1], (uintptr_t)(handoff_table[i] +
+                      umctl2_base));
+

Can have a common function to write the handoff data. Check all code after call to socfpga_handoff_read().

I can create a common function for both PHY and PHY init engine, but not for this umctl because both for loop process are different, handoff_table for both PHY and PHY int engine need some preprocessing before writing into respective registers but this is not required in umctl.

Quoted 26 lines

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +9 -0
+               debug("rd = 0x%08x\n", readl((uintptr_t)(handoff_table[i] +
+                     umctl2_base)));
+       }
+
+       /* Backup user settings, restore after DDR up running */
+       *user_backup = readl(umctl2_base + DDR4_PWRCTL_OFFSET);
+
+       /* Disable self resfresh */
+       clrbits_le32(umctl2_base + DDR4_PWRCTL_OFFSET,

DDR4_PWRCTL_SELFREF_EN);

Quoted 15 lines
drivers/ddr/altera/Makefile +15 -0
+
+       if (umctl2_type == DDRTYPE_LPDDR4_0 ||
+           umctl2_type == DDRTYPE_LPDDR4_1) {
+               /* Setting selfref_sw to 1, based on lpddr4 requirement */
+               setbits_le32(umctl2_base + DDR4_PWRCTL_OFFSET,
+                            DDR4_PWRCTL_SELFREF_SW);
+
+               /* Backup user settings, restore after DDR up running */
+               user_backup++;
+               *user_backup = readl(umctl2_base + DDR4_INIT0_OFFSET) &
+                                    DDR4_INIT0_SKIP_RAM_INIT;
+
+               /*
+                * Setting INIT0.skip_dram_init to 0x3, based on lpddr4
+                * requirement
Quoted 11 lines

drivers/ddr/altera/Makefile

Quoted 7 lines
drivers/ddr/altera/Makefile +7 -0
+                */
+               setbits_le32(umctl2_base + DDR4_INIT0_OFFSET,
+                            DDR4_INIT0_SKIP_RAM_INIT);
+       }
+
+       /* Complete quasi-dynamic register programming */
+       setbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+
+       /* Enable controller from issuing read/write to SDRAM */
+       clrbits_le32(umctl2_base + DDR4_DBG1_OFFSET,

DDR4_DBG1_DISDQ);

Quoted 35 lines
Quoted 20 lines
drivers/ddr/altera/Makefile +20 -0
+
+       return 0;
+}
+
+static int phy_pre_handoff_config(phys_addr_t umctl2_base,
+                                 enum ddr_type umctl2_type)
+{
+       int ret;
+       u32 value;
+
+       if (umctl2_type == DDRTYPE_DDR4) {
+               /* Check DDR4 retry is enabled ? */
+               value = readl(umctl2_base + DDR4_CRCPARCTL1_OFFSET) &
+                             DDR4_CRCPARCTL1_CRC_PARITY_RETRY_ENABLE;
+
+               if (value) {
+                       debug("%s: DDR4 retry is enabled\n", __func__);
+                       debug("%s: Disable auto refresh is not supported\n",
+                             __func__);
+               } else {

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+                       /* Disable auto refresh */
+                       setbits_le32(umctl2_base + DDR4_RFSHCTL3_OFFSET,
+                                    DDR4_RFSHCTL3_DIS_AUTO_REFRESH);
+               }
+       }
+
+       /* Disable selfref_en & powerdown_en, nvr disable dfi dram clk */
+       clrbits_le32(umctl2_base + DDR4_PWRCTL_OFFSET,
+                    DDR4_PWRCTL_EN_DFI_DRAM_CLK_DISABLE |
+                    DDR4_PWRCTL_POWERDOWN_EN |

DDR4_PWRCTL_SELFREF_EN);

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+
+       /* Enable quasi-dynamic programing of the controller registers */
+       clrbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

Quoted 16 lines

drivers/ddr/altera/Makefile

Quoted 11 lines
drivers/ddr/altera/Makefile +11 -0
+
+       ret = enable_quasi_dynamic_reg_grp3(umctl2_base, umctl2_type);
+       if (ret)
+               return ret;
+
+       /* Masking dfi init complete */
+       clrbits_le32(umctl2_base + DDR4_DFIMISC_OFFSET,
+                    DDR4_DFIMISC_DFI_INIT_COMPLETE_EN);
+
+       /* Complete quasi-dynamic register programming */
+       setbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+
+       /* Polling programming done */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SWSTAT_OFFSET),

DDR4_SWSTAT_SW_DONE_ACK,

Quoted 95 lines
Quoted 25 lines
drivers/ddr/altera/Makefile +25 -0
+                               true, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" programming done\n");
+       }
+
+       return ret;
+}
+
+static int init_phy(struct ddr_handoff *ddr_handoff_info)
+{
+       u32 handoff_table[ddr_handoff_info->phy_handoff_length];
+       u32 i, value;
+       int ret;
+
+       printf("Initializing DDR PHY ...\n");
+
+       if (ddr_handoff_info->cntlr_t == DDRTYPE_DDR4 ||
+           ddr_handoff_info->cntlr_t == DDRTYPE_LPDDR4_0) {
+               ret = phy_pre_handoff_config(ddr_handoff_info->cntlr_base,
+                                            ddr_handoff_info->cntlr_t);
+               if (ret)
+                       return ret;
+       }
+

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+       if (ddr_handoff_info->cntlr2_t == DDRTYPE_LPDDR4_1) {
+               ret = phy_pre_handoff_config
+                       (ddr_handoff_info->cntlr2_base,
+                        ddr_handoff_info->cntlr2_t);
+               if (ret)
+                       return ret;
+       }
+
+       /* Execute PHY configuration handoff */
+       socfpga_handoff_read((void *)ddr_handoff_info-

phy_handoff_base,

Quoted 23 lines
drivers/ddr/altera/Makefile +23 -0
+                            handoff_table,
+                            (u32)ddr_handoff_info->phy_handoff_length);
+
+       for (i = 0; i < ddr_handoff_info->phy_handoff_length; i = i + 2) {
+               /*
+                * Convert PHY odd offset to even offset that supported by
+                * ARM processor.
+                */
+               value = handoff_table[i] << 1;
+               debug("%s: Absolute addr: 0x%08llx, APB offset: 0x%08x ",
+                     __func__, value + ddr_handoff_info->phy_base, value);
+               debug("PHY offset: 0x%08x", handoff_table[i]);
+               debug(" wr = 0x%08x ", handoff_table[i + 1]);
+               writew(handoff_table[i + 1], (uintptr_t)(value +
+                      ddr_handoff_info->phy_base));
+               debug("rd = 0x%08x\n", readw((uintptr_t)(value +
+                     ddr_handoff_info->phy_base)));
+       }
+
+       printf("DDR PHY configuration is completed\n");
+
+       return 0;
+}

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+
+static void phy_init_engine(struct ddr_handoff *handoff)
+{
+       u32 i, value;
+       u32 handoff_table[handoff->phy_engine_handoff_length];
+
+       printf("Load PHY Init Engine ...\n");
+
+       /* Execute PIE production code handoff */
+       socfpga_handoff_read((void *)handoff-

phy_engine_handoff_base,

Quoted 25 lines
drivers/ddr/altera/Makefile +25 -0
+                            handoff_table,
+                            (u32)handoff->phy_engine_handoff_length);
+
+       for (i = 0; i < handoff->phy_engine_handoff_length; i = i + 2) {
+               debug("Handoff addr: 0x%8llx ", handoff_table[i] +
+                     handoff->phy_base);
+
+               /*
+                * Convert PHY odd offset to even offset that supported by
+                * ARM processor.
+                */
+               value = handoff_table[i] << 1;
+               debug("%s: Absolute addr: 0x%08llx, APB offset: 0x%08x ",
+                     __func__, value + handoff->phy_base, value);
+               debug("PHY offset: 0x%08x", handoff_table[i]);
+               debug(" wr = 0x%08x ", handoff_table[i + 1]);
+
+               writew(handoff_table[i + 1], (uintptr_t)(value +
+                      handoff->phy_base));
+
+               debug("rd = 0x%08x\n", readw((uintptr_t)(value +
+                     handoff->phy_base)));
+       }
+
+       printf("End of loading PHY Init Engine\n");
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+}
+
+int populate_ddr_handoff(struct ddr_handoff *handoff)
+{
+       phys_addr_t next_section_header;
+
+       /* DDR handoff */
+       handoff->mem_reset_base =

SOC64_HANDOFF_DDR_MEMRESET_BASE;

Quoted 7 lines

drivers/ddr/altera/Makefile

Quoted 7 lines
drivers/ddr/altera/Makefile +7 -0
+       debug("%s: DDR memory reset base = 0x%x\n", __func__,
+             (u32)handoff->mem_reset_base);
+       debug("%s: DDR memory reset address = 0x%x\n", __func__,
+             readl(handoff->mem_reset_base));
+
+       /* Beginning of DDR controller handoff */
+       handoff->cntlr_handoff_base =
Quoted 10 lines

SOC64_HANDOFF_DDR_UMCTL2_SECTION;

Quoted 9 lines
drivers/ddr/altera/Makefile +9 -0
+       debug("%s: cntlr handoff base = 0x%x\n", __func__,
+             (u32)handoff->cntlr_handoff_base);
+
+       /* Get 1st DDR type */
+       handoff->cntlr_t = get_ddr_type(handoff->cntlr_handoff_base +
+                                       SOC64_HANDOFF_DDR_UMCTL2_TYPE_OFFSET);
+       if (handoff->cntlr_t == DDRTYPE_LPDDR4_1 ||
+           handoff->cntlr_t == DDRTYPE_UNKNOWN) {
+               debug("%s: Wrong DDR handoff format, the 1st DDR ",

__func__);

Quoted 7 lines

drivers/ddr/altera/Makefile

Quoted 7 lines
drivers/ddr/altera/Makefile +7 -0
+               debug("type must be DDR4 or LPDDR4_0\n");
+               return -ENOEXEC;
+       }
+
+       /* 1st cntlr base physical address */
+       handoff->cntlr_base = readl(handoff->cntlr_handoff_base +
+

SOC64_HANDOFF_DDR_UMCTL2_BASE_ADDR_OFFSET);

Quoted 13 lines
Quoted 1 line

+ debug("%s: cntlr base = 0x%x\n", __func__, (u32)handoff-

cntlr_base);

drivers/ddr/altera/Makefile

Quoted 11 lines
drivers/ddr/altera/Makefile +11 -0
+
+       /* Get the total length of DDR cntlr handoff section */
+       handoff->cntlr_total_length = readl(handoff->cntlr_handoff_base +
+                                           SOC64_HANDOFF_OFFSET_LENGTH);
+       debug("%s: Umctl2 total length in byte = 0x%x\n", __func__,
+             (u32)handoff->cntlr_total_length);
+
+       /* Get the length of user setting data in DDR cntlr handoff section */
+       handoff->cntlr_handoff_length = socfpga_get_handoff_size((void *)
+                                               handoff->cntlr_handoff_base);
+       debug("%s: Umctl2 handoff length in word(32-bit) = 0x%x\n",

__func__,

Quoted 4 lines
Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+             (u32)handoff->cntlr_handoff_length);
+
+       /* Wrong format on user setting data */
+       if (handoff->cntlr_handoff_length < 0) {
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+               debug("%s: Wrong format on user setting data\n", __func__);
+               return -ENOEXEC;
+       }
+
+       /* Get the next handoff section address */
+       next_section_header = handoff->cntlr_handoff_base +
+                               handoff->cntlr_total_length;
+       debug("%s: Next handoff section header location = 0x%llx\n",

__func__,

Quoted 29 lines

drivers/ddr/altera/Makefile

Quoted 7 lines
drivers/ddr/altera/Makefile +7 -0
+             next_section_header);
+
+       /*
+        * Checking next section handoff is cntlr or PHY, and changing
+        * subsequent implementation accordingly
+        */
+       if (readl(next_section_header) ==

SOC64_HANDOFF_DDR_UMCTL2_MAGIC) {

drivers/ddr/altera/Makefile

Quoted 7 lines
drivers/ddr/altera/Makefile +7 -0
+               /* Get the next cntlr handoff section address */
+               handoff->cntlr2_handoff_base = next_section_header;
+               debug("%s: umctl2 2nd handoff base = 0x%x\n", __func__,
+                     (u32)handoff->cntlr2_handoff_base);
+
+               /* Get 2nd DDR type */
+               handoff->cntlr2_t = get_ddr_type(handoff-

cntlr2_handoff_base +

Quoted 13 lines
drivers/ddr/altera/Makefile +13 -0
+                                       SOC64_HANDOFF_DDR_UMCTL2_TYPE_OFFSET);
+               if (handoff->cntlr2_t == DDRTYPE_LPDDR4_0 ||
+                   handoff->cntlr2_t == DDRTYPE_UNKNOWN) {
+                       debug("%s: Wrong DDR handoff format, the 2nd DDR ",
+                             __func__);
+                       debug("type must be LPDDR4_1\n");
+                       return -ENOEXEC;
+               }
+
+               /* 2nd umctl2 base physical address */
+               handoff->cntlr2_base =
+                       readl(handoff->cntlr2_handoff_base +
+                             SOC64_HANDOFF_DDR_UMCTL2_BASE_ADDR_OFFSET);
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+               debug("%s: cntlr2 base = 0x%x\n", __func__,
+                     (u32)handoff->cntlr2_base);
+
+               /* Get the total length of 2nd DDR umctl2 handoff section */
+               handoff->cntlr2_total_length =
+                       readl(handoff->cntlr2_handoff_base +
+                             SOC64_HANDOFF_OFFSET_LENGTH);
+               debug("%s: Umctl2_2nd total length in byte = 0x%x\n",

__func__,

Quoted 21 lines
Quoted 21 lines
drivers/ddr/altera/Makefile +21 -0
+                     (u32)handoff->cntlr2_total_length);
+
+               /*
+                * Get the length of user setting data in DDR umctl2 handoff
+                * section
+                */
+               handoff->cntlr2_handoff_length =
+                       socfpga_get_handoff_size((void *)
+                                                handoff->cntlr2_handoff_base);
+               debug("%s: cntlr2 handoff length in word(32-bit) = 0x%x\n",
+                     __func__,
+                    (u32)handoff->cntlr2_handoff_length);
+
+               /* Wrong format on user setting data */
+               if (handoff->cntlr2_handoff_length < 0) {
+                       debug("%s: Wrong format on umctl2 user setting data\n",
+                             __func__);
+                       return -ENOEXEC;
+               }
+
+               /* Get the next handoff section address */
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+               next_section_header = handoff->cntlr2_handoff_base +
+                                       handoff->cntlr2_total_length;
+               debug("%s: Next handoff section header location = 0x%llx\n",
+                     __func__, next_section_header);
+       }
+
+       /* Checking next section handoff is PHY ? */
+       if (readl(next_section_header) ==

SOC64_HANDOFF_DDR_PHY_MAGIC) {

Quoted 6 lines
Quoted 6 lines
drivers/ddr/altera/Makefile +6 -0
+               /* DDR PHY handoff */
+               handoff->phy_handoff_base = next_section_header;
+               debug("%s: PHY handoff base = 0x%x\n", __func__,
+                     (u32)handoff->phy_handoff_base);
+
+               /* PHY base physical address */
Quoted 17 lines

drivers/ddr/altera/Makefile

Quoted 7 lines
drivers/ddr/altera/Makefile +7 -0
+               handoff->phy_base = readl(handoff->phy_handoff_base +
+                                       SOC64_HANDOFF_DDR_PHY_BASE_OFFSET);
+               debug("%s: PHY base = 0x%x\n", __func__,
+                     (u32)handoff->phy_base);
+
+               /* Get the total length of PHY handoff section */
+               handoff->phy_total_length = readl(handoff-

phy_handoff_base +

Quoted 9 lines
drivers/ddr/altera/Makefile +9 -0
+                                               SOC64_HANDOFF_OFFSET_LENGTH);
+               debug("%s: PHY total length in byte = 0x%x\n", __func__,
+                     (u32)handoff->phy_total_length);
+
+               /*
+                * Get the length of user setting data in DDR PHY handoff
+                * section
+                */
+               handoff->phy_handoff_length =

socfpga_get_handoff_size((void *)

Quoted 38 lines
Quoted 38 lines
drivers/ddr/altera/Makefile +38 -0
+                                               handoff->phy_handoff_base);
+               debug("%s: PHY handoff length in word(32-bit) = 0x%x\n",
+                     __func__, (u32)handoff->phy_handoff_length);
+
+               /* Wrong format on PHY user setting data */
+               if (handoff->phy_handoff_length < 0) {
+                       debug("%s: Wrong format on PHY user setting data\n",
+                             __func__);
+                       return -ENOEXEC;
+               }
+
+               /* Get the next handoff section address */
+               next_section_header = handoff->phy_handoff_base +
+                                       handoff->phy_total_length;
+               debug("%s: Next handoff section header location = 0x%llx\n",
+                     __func__, next_section_header);
+       } else {
+               debug("%s: Wrong format for DDR handoff, expect PHY",
+                     __func__);
+               debug(" handoff section after umctl2 handoff section\n");
+               return -ENOEXEC;
+       }
+
+       /* Checking next section handoff is PHY init Engine ? */
+       if (readl(next_section_header) ==
+               SOC64_HANDOFF_DDR_PHY_INIT_ENGINE_MAGIC) {
+               /* DDR PHY Engine handoff */
+               handoff->phy_engine_handoff_base = next_section_header;
+               debug("%s: PHY init engine handoff base = 0x%x\n", __func__,
+                     (u32)handoff->phy_engine_handoff_base);
+
+               /* Get the total length of PHY init engine handoff section */
+               handoff->phy_engine_total_length =
+                               readl(handoff->phy_engine_handoff_base +
+                                     SOC64_HANDOFF_OFFSET_LENGTH);
+               debug("%s: PHY engine total length in byte = 0x%x\n", __func__,
+                     (u32)handoff->phy_engine_total_length);
+
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+               /*
+                * Get the length of user setting data in DDR PHY init engine
+                * handoff section
+                */
+               handoff->phy_engine_handoff_length =
+                       socfpga_get_handoff_size((void *)
+                                       handoff->phy_engine_handoff_base);
+               debug("%s: PHY engine handoff length in word(32-bit) =

0x%x\n",

Quoted 193 lines
Quoted 18 lines
drivers/ddr/altera/Makefile +18 -0
+                     __func__, (u32)handoff->phy_engine_handoff_length);
+
+               /* Wrong format on PHY init engine setting data */
+               if (handoff->phy_engine_handoff_length < 0) {
+                       debug("%s: Wrong format on PHY init engine ",
+                             __func__);
+                       debug("user setting data\n");
+                       return -ENOEXEC;
+               }
+       } else {
+               debug("%s: Wrong format for DDR handoff, expect PHY",
+                     __func__);
+               debug(" init engine handoff section after PHY handoff\n");
+               debug(" section\n");
+               return -ENOEXEC;
+       }
+
+       handoff->train_imem_base = handoff->phy_base +

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+                                               DDR_PHY_TRAIN_IMEM_OFFSET;
+       debug("%s: PHY train IMEM base = 0x%x\n",
+             __func__, (u32)handoff->train_imem_base);
+
+       handoff->train_dmem_base = handoff->phy_base +
+                                               DDR_PHY_TRAIN_DMEM_OFFSET;
+       debug("%s: PHY train DMEM base = 0x%x\n",
+             __func__, (u32)handoff->train_dmem_base);
+
+       handoff->train_imem_length =

SOC64_HANDOFF_DDR_TRAIN_IMEM_LENGTH;

drivers/ddr/altera/Makefile

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+       debug("%s: PHY train IMEM length = 0x%x\n",
+             __func__, (u32)handoff->train_imem_length);
+
+       handoff->train_dmem_length =

SOC64_HANDOFF_DDR_TRAIN_DMEM_LENGTH;

Quoted 29 lines
drivers/ddr/altera/Makefile +29 -0
+       debug("%s: PHY train DMEM length = 0x%x\n",
+             __func__, (u32)handoff->train_dmem_length);
+
+       return 0;
+}
+
+int enable_ddr_clock(struct udevice *dev)
+{
+       struct clk *ddr_clk;
+       int ret;
+
+       /* Enable clock before init DDR */
+       ddr_clk = devm_clk_get(dev, "mem_clk");
+       if (!IS_ERR(ddr_clk)) {
+               ret = clk_enable(ddr_clk);
+               if (ret) {
+                       printf("%s: Failed to enable DDR clock\n", __func__);
+                       return ret;
+               }
+       } else {
+               ret = PTR_ERR(ddr_clk);
+               debug("%s: Failed to get DDR clock from dts\n", __func__);
+               return ret;
+       }
+
+       printf("%s: DDR clock is enabled\n", __func__);
+
+       return 0;
+}

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+
+static int ddr_start_dfi_init(phys_addr_t umctl2_base,
+                             enum ddr_type umctl2_type)
+{
+       int ret;
+
+       debug("%s: Start DFI init\n", __func__);
+
+       /* Enable quasi-dynamic programing of controller registers */
+       clrbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

drivers/ddr/altera/Makefile

Quoted 11 lines
drivers/ddr/altera/Makefile +11 -0
+
+       ret = enable_quasi_dynamic_reg_grp3(umctl2_base, umctl2_type);
+       if (ret)
+               return ret;
+
+       /* Start DFI init sequence */
+       setbits_le32(umctl2_base + DDR4_DFIMISC_OFFSET,
+                    DDR4_DFIMISC_DFI_INIT_START);
+
+       /* Complete quasi-dynamic register programming */
+       setbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

Quoted 24 lines
drivers/ddr/altera/Makefile +24 -0
+
+       /* Polling programming done */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SWSTAT_OFFSET),
+                               DDR4_SWSTAT_SW_DONE_ACK, true,
+                               TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" programming done\n");
+       }
+
+       return ret;
+}
+
+static int ddr_check_dfi_init_complete(phys_addr_t umctl2_base,
+                                      enum ddr_type umctl2_type)
+{
+       int ret;
+
+       /* Polling DFI init complete */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_DFISTAT_OFFSET),
+                               DDR4_DFI_INIT_COMPLETE, true,
+                               TIMEOUT_200MS, false);

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" DFI init done\n");
+               return ret;
+       }
+
+       debug("%s: DFI init completed.\n", __func__);
+
+       /* Enable quasi-dynamic programing of controller registers */
+       clrbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

drivers/ddr/altera/Makefile

Quoted 11 lines
drivers/ddr/altera/Makefile +11 -0
+
+       ret = enable_quasi_dynamic_reg_grp3(umctl2_base, umctl2_type);
+       if (ret)
+               return ret;
+
+       /* Stop DFI init sequence */
+       clrbits_le32(umctl2_base + DDR4_DFIMISC_OFFSET,
+                    DDR4_DFIMISC_DFI_INIT_START);
+
+       /* Complete quasi-dynamic register programming */
+       setbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

Quoted 14 lines
drivers/ddr/altera/Makefile +14 -0
+
+       /* Polling programming done */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SWSTAT_OFFSET),
+                               DDR4_SWSTAT_SW_DONE_ACK, true,
+                               TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" programming done\n");
+               return ret;
+       }
+
+       debug("%s:DDR programming done\n", __func__);
+

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+       return ret;
+}
+
+static int ddr_trigger_sdram_init(phys_addr_t umctl2_base,
+                                 enum ddr_type umctl2_type)
+{
+       int ret;
+
+       /* Enable quasi-dynamic programing of controller registers */
+       clrbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

drivers/ddr/altera/Makefile

Quoted 11 lines
drivers/ddr/altera/Makefile +11 -0
+
+       ret = enable_quasi_dynamic_reg_grp3(umctl2_base, umctl2_type);
+       if (ret)
+               return ret;
+
+       /* Unmasking dfi init complete */
+       setbits_le32(umctl2_base + DDR4_DFIMISC_OFFSET,
+                    DDR4_DFIMISC_DFI_INIT_COMPLETE_EN);
+
+       /* Software exit from self-refresh */
+       clrbits_le32(umctl2_base + DDR4_PWRCTL_OFFSET,

DDR4_PWRCTL_SELFREF_SW);

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+
+       /* Complete quasi-dynamic register programming */
+       setbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

Quoted 19 lines
drivers/ddr/altera/Makefile +19 -0
+
+       /* Polling programming done */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SWSTAT_OFFSET),
+                               DDR4_SWSTAT_SW_DONE_ACK, true,
+                               TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" programming done\n");
+               return ret;
+       }
+
+       debug("%s:DDR programming done\n", __func__);
+       return ret;
+}
+
+static int ddr_post_handoff_config(phys_addr_t umctl2_base,
+                                  enum ddr_type umctl2_type)
+{
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 7 lines
drivers/ddr/altera/Makefile +7 -0
+       int ret = 0;
+       u32 value;
+       u32 start = get_timer(0);
+
+       /* Polling until SDRAM entered normal operating mode */
+       value = readl(umctl2_base + DDR4_STAT_OFFSET) &
+                     DDR4_STAT_OPERATING_MODE;

Can merge to "do..while" loop below.

Okay.

Quoted 25 lines
Quoted 14 lines
drivers/ddr/altera/Makefile +13 -0
+       while (value != NORMAL_OPM) {
+               if (get_timer(start) > TIMEOUT_200MS) {
+                       debug("%s: Timeout while waiting for",
+                             __func__);
+                       debug(" DDR enters normal operating mode\n");
+                       return -ETIMEDOUT;
+               }
+
+               value = readl(umctl2_base + DDR4_STAT_OFFSET) &
+                             DDR4_STAT_OPERATING_MODE;
+
+               udelay(1);
+               WATCHDOG_RESET();

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+       }
+
+       printf("DDR entered normal operating mode\n");
+
+       /* Enabling auto refresh */
+       clrbits_le32(umctl2_base + DDR4_RFSHCTL3_OFFSET,
+                    DDR4_RFSHCTL3_DIS_AUTO_REFRESH);
+
+       /* Checking ECC is enabled? */
+       value = readl(umctl2_base + DDR4_ECCCFG0_OFFSET) &

DDR4_ECC_MODE;

Quoted 11 lines

drivers/ddr/altera/Makefile

Quoted 11 lines
drivers/ddr/altera/Makefile +11 -0
+       if (value) {
+               printf("ECC is enabled\n");
+               ret = scrubber_ddr_config(umctl2_base, umctl2_type);
+               if (ret)
+                       printf("Failed to enable ECC\n");
+       }
+
+       return ret;
+}
+
+static int configure_training_firmware(struct ddr_handoff

*ddr_handoff_info,

Quoted 14 lines

drivers/ddr/altera/Makefile

Quoted 13 lines
drivers/ddr/altera/Makefile +13 -0
+       const void *train_imem, const void *train_dmem)
+{
+       int ret = 0;
+
+       printf("Configuring training firmware ...\n");
+
+       /* Reset SDRAM */
+       writew(DDR_PHY_PROTECT_MEMRESET,
+              (uintptr_t)(ddr_handoff_info->phy_base +
+              DDR_PHY_MEMRESETL_OFFSET));
+
+       /* Enable access to the PHY configuration registers */
+       clrbits_le16(ddr_handoff_info->phy_base +

DDR_PHY_APBONLY0_OFFSET,

Quoted 7 lines

drivers/ddr/altera/Makefile

Quoted 7 lines
drivers/ddr/altera/Makefile +7 -0
+                    DDR_PHY_MICROCONTMUXSEL);
+
+       /* Copy train IMEM bin */
+       memcpy((void *)ddr_handoff_info->train_imem_base, train_imem,
+              ddr_handoff_info->train_imem_length);
+
+       ret = memcmp((void *)ddr_handoff_info->train_imem_base,

train_imem,

Quoted 11 lines

drivers/ddr/altera/Makefile

Quoted 6 lines
drivers/ddr/altera/Makefile +6 -0
+                    ddr_handoff_info->train_imem_length);
+       if (ret) {
+               debug("%s: Failed to copy train IMEM binary\n", __func__);
+               /* Isolate the APB access from internal CSRs */
+               setbits_le16(ddr_handoff_info->phy_base +
+                            DDR_PHY_APBONLY0_OFFSET,

DDR_PHY_MICROCONTMUXSEL);

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+               return ret;
+       }
+
+       memcpy((void *)ddr_handoff_info->train_dmem_base,

train_dmem,

Quoted 25 lines

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+              ddr_handoff_info->train_dmem_length);
+
+       ret = memcmp((void *)ddr_handoff_info->train_dmem_base,

train_dmem,

drivers/ddr/altera/Makefile

Quoted 6 lines
drivers/ddr/altera/Makefile +6 -0
+                    ddr_handoff_info->train_dmem_length);
+       if (ret)
+               debug("%s: Failed to copy train DMEM binary\n", __func__);
+
+       /* Isolate the APB access from internal CSRs */
+       setbits_le16(ddr_handoff_info->phy_base +

DDR_PHY_APBONLY0_OFFSET,

drivers/ddr/altera/Makefile

Quoted 9 lines
drivers/ddr/altera/Makefile +9 -0
+                    DDR_PHY_MICROCONTMUXSEL);
+
+       return ret;
+}
+
+static void calibrating_sdram(struct ddr_handoff *ddr_handoff_info)
+{
+       /* Init mailbox protocol - set 1 to DCTWRITEPROT[0] */
+       setbits_le16(ddr_handoff_info->phy_base +

DDR_PHY_DCTWRITEPROT_OFFSET,

drivers/ddr/altera/Makefile

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+                    DDR_PHY_DCTWRITEPROT);
+
+       /* Init mailbox protocol - set 1 to UCTWRITEPROT[0] */
+       setbits_le16(ddr_handoff_info->phy_base +
Quoted 7 lines

DDR_PHY_UCTWRITEPROT_OFFSET,

drivers/ddr/altera/Makefile

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+                    DDR_PHY_UCTWRITEPROT);
+
+       /* Reset and stalling ARC processor */
+       setbits_le16(ddr_handoff_info->phy_base +

DDR_PHY_MICRORESET_OFFSET,

Quoted 1 line

+ DDR_PHY_MICRORESET_RESET |

DDR_PHY_MICRORESET_STALL);

Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+
+       /* Release ARC processor */
+       clrbits_le16(ddr_handoff_info->phy_base +

DDR_PHY_MICRORESET_OFFSET,

drivers/ddr/altera/Makefile

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+                    DDR_PHY_MICRORESET_RESET);
+
+       /* Starting PHY firmware execution */
+       clrbits_le16(ddr_handoff_info->phy_base +
Quoted 5 lines

DDR_PHY_MICRORESET_OFFSET,

drivers/ddr/altera/Makefile

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+                    DDR_PHY_MICRORESET_STALL);
+}
+
+static int get_mail(struct ddr_handoff *handoff, enum message_mode

mode,

Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+                   u32 *message_id)
+{
+       int ret;
+
+       /* Polling major messages from PMU */
+       ret = wait_for_bit_le16((const void *)(handoff->phy_base +
+                               DDR_PHY_UCTSHADOWREGS_OFFSET),
+

DDR_PHY_UCTSHADOWREGS_UCTWRITEPROTESHADOW,

Quoted 10 lines
Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+                               false, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for",
+                     __func__);
+               debug(" major messages from PMU\n");
+               return ret;
+       }
+
+       *message_id = readw((uintptr_t)(handoff->phy_base +
+                           DDR_PHY_UCTWRITEONLYSHADOW_OFFSET));
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+
+       if (mode == STREAMING_MESSAGE)
+               *message_id |= readw((uintptr_t)((handoff->phy_base +
+                                    DDR_PHY_UCTDATWRITEONLYSHADOW_OFFSET))) <<
+                                    SZ_16;
+
+       /* Ack the receipt of the major message */
+       clrbits_le16(handoff->phy_base +

DDR_PHY_DCTWRITEPROT_OFFSET,

Quoted 5 lines

drivers/ddr/altera/Makefile

Quoted 5 lines
drivers/ddr/altera/Makefile +5 -0
+                    DDR_PHY_DCTWRITEPROT);
+
+       ret = wait_for_bit_le16((const void *)(handoff->phy_base +
+                               DDR_PHY_UCTSHADOWREGS_OFFSET),
+

DDR_PHY_UCTSHADOWREGS_UCTWRITEPROTESHADOW,

Quoted 10 lines

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+                               true, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for",
+                     __func__);
+               debug(" ack the receipt of the major message completed\n");
+               return ret;
+       }
+
+       /* Complete protocol */
+       setbits_le16(handoff->phy_base +

DDR_PHY_DCTWRITEPROT_OFFSET,

Quoted 12 lines
Quoted 12 lines
drivers/ddr/altera/Makefile +12 -0
+                    DDR_PHY_DCTWRITEPROT);
+
+       return ret;
+}
+
+static int get_mail_streaming(struct ddr_handoff *handoff,
+                             enum message_mode mode, u32 *index)
+{
+       int ret;
+
+       *index = readw((uintptr_t)(handoff->phy_base +
+                      DDR_PHY_UCTWRITEONLYSHADOW_OFFSET));
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+
+       if (mode == STREAMING_MESSAGE)
+               *index |= readw((uintptr_t)((handoff->phy_base +
+                               DDR_PHY_UCTDATWRITEONLYSHADOW_OFFSET))) <<
+                               SZ_16;
+
+       /* Ack the receipt of the major message */
+       clrbits_le16(handoff->phy_base +

DDR_PHY_DCTWRITEPROT_OFFSET,

Quoted 5 lines

drivers/ddr/altera/Makefile

Quoted 5 lines
drivers/ddr/altera/Makefile +5 -0
+                    DDR_PHY_DCTWRITEPROT);
+
+       ret = wait_for_bit_le16((const void *)(handoff->phy_base +
+                               DDR_PHY_UCTSHADOWREGS_OFFSET),
+

DDR_PHY_UCTSHADOWREGS_UCTWRITEPROTESHADOW,

Quoted 10 lines

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+                               true, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for",
+                     __func__);
+               debug(" ack the receipt of the major message completed\n");
+               return ret;
+       }
+
+       /* Complete protocol */
+       setbits_le16(handoff->phy_base +

DDR_PHY_DCTWRITEPROT_OFFSET,

Quoted 6 lines

drivers/ddr/altera/Makefile

Quoted 6 lines
drivers/ddr/altera/Makefile +6 -0
+                    DDR_PHY_DCTWRITEPROT);
+
+       return 0;
+}
+
+static int decode_streaming_message(struct ddr_handoff

*ddr_handoff_info,

Quoted 13 lines
Quoted 13 lines
drivers/ddr/altera/Makefile +13 -0
+                                   u32 *streaming_index)
+{
+       int i = 0, ret;
+       u32 temp;
+
+       temp = *streaming_index;
+
+       while (i < GET_LOWHW_DATA(temp)) {
+               ret = get_mail(ddr_handoff_info, STREAMING_MESSAGE,
+                              streaming_index);
+               if (ret)
+                       return ret;
+
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+               printf("args[%d]: 0x%x ", i, *streaming_index);
+               i++;
+       }
+
+       return 0;
+}
+
+static int poll_for_training_complete(struct ddr_handoff

*ddr_handoff_info)

Quoted 7 lines

drivers/ddr/altera/Makefile

Quoted 7 lines
drivers/ddr/altera/Makefile +7 -0
+{
+       int ret;
+       u32 message_id = 0;
+       u32 streaming_index = 0;
+
+       do {
+               ret = get_mail(ddr_handoff_info, MAJOR_MESSAGE,

&message_id);

Quoted 43 lines
Quoted 43 lines
drivers/ddr/altera/Makefile +43 -0
+               if (ret)
+                       return ret;
+
+                printf("Major message id = 0%x\n", message_id);
+
+               if (message_id == FW_STREAMING_MSG_ID) {
+                       ret = get_mail_streaming(ddr_handoff_info,
+                                                STREAMING_MESSAGE,
+                                                &streaming_index);
+                       if (ret)
+                               return ret;
+
+                       printf("streaming index 0%x : ", streaming_index);
+
+                       decode_streaming_message(ddr_handoff_info,
+                                                &streaming_index);
+
+                       printf("\n");
+               }
+       } while ((message_id != FW_TRAINING_COMPLETED_STAT) &&
+              (message_id != FW_TRAINING_FAILED_STAT));
+
+       if (message_id == FW_TRAINING_COMPLETED_STAT) {
+               printf("DDR firmware training completed\n");
+       } else if (message_id == FW_TRAINING_FAILED_STAT) {
+               printf("DDR firmware training failed\n");
+               hang();
+       }
+
+       return 0;
+}
+
+static void enable_phy_clk_for_csr_access(struct ddr_handoff *handoff,
+                                         bool enable)
+{
+       if (enable) {
+               /* Enable PHY clk */
+               setbits_le16((uintptr_t)(handoff->phy_base +
+                            DDR_PHY_UCCLKHCLKENABLES_OFFSET),
+                            DDR_PHY_UCCLKHCLKENABLES_UCCLKEN |
+                            DDR_PHY_UCCLKHCLKENABLES_HCLKEN);
+       } else {
+               /* Disable PHY clk */
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+               clrbits_le16((uintptr_t)(handoff->phy_base +
+                            DDR_PHY_UCCLKHCLKENABLES_OFFSET),
+                            DDR_PHY_UCCLKHCLKENABLES_UCCLKEN |
+                            DDR_PHY_UCCLKHCLKENABLES_HCLKEN);
+       }
+}
+
+/* helper function for updating train result to umctl2 RANKCTL register

*/

Quoted 27 lines
Quoted 27 lines
drivers/ddr/altera/Makefile +27 -0
+static void set_cal_res_to_rankctrl(u32 reg_addr, u16 update_value,
+                                   u32 mask, u32 msb_mask, u32 shift)
+{
+       u32 reg, value;
+
+       reg = readl((uintptr_t)reg_addr);
+
+       debug("max value divided by 2 is 0x%x\n", update_value);
+       debug("umclt2 register 0x%x value is 0%x before ", reg_addr, reg);
+       debug("update with train result\n");
+
+       value = (reg & mask) >> shift;
+
+       value += update_value + 3;
+
+       /* reg value greater than 0xF, set one to diff_rank_wr_gap_msb */
+       if (value > 0xF)
+               setbits_le32((u32 *)(uintptr_t)reg_addr, msb_mask);
+       else
+               clrbits_le32((u32 *)(uintptr_t)reg_addr, msb_mask);
+
+       reg = readl((uintptr_t)reg_addr);
+
+       value = (value << shift) & mask;
+
+       /* update register */
+       writel((reg & (~mask)) | value, (uintptr_t)reg_addr);
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+
+       reg = readl((uintptr_t)reg_addr);
+       debug("umclt2 register 0x%x value is 0%x before ", reg_addr, reg);
+       debug("update with train result\n");
+}
+
+/* helper function for updating train result to register */
+static void set_cal_res_to_reg(u32 reg_addr, u16 update_value, u32

mask,

Quoted 15 lines
Quoted 15 lines
drivers/ddr/altera/Makefile +15 -0
+                              u32 shift)
+{
+       u32 reg, value;
+
+       reg = readl((uintptr_t)reg_addr);
+
+       debug("max value divided by 2 is 0x%x\n", update_value);
+       debug("umclt2 register 0x%x value is 0%x before ", reg_addr, reg);
+       debug("update with train result\n");
+
+       value = (reg & mask) >> shift;
+
+       value = ((value + update_value + 3) << shift) & mask;
+
+       /* update register */
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+       writel((reg & (~mask)) | value, (uintptr_t)reg_addr);
+
+       reg = readl((uintptr_t)reg_addr);
+       debug("umclt2 register 0x%x value is 0%x before ", reg_addr, reg);
+       debug("update with train result\n");
+}
+
+static u16 get_max_txdqsdlytg0_ux_p0(struct ddr_handoff *handoff,

u32 reg,

Quoted 34 lines
Quoted 23 lines
drivers/ddr/altera/Makefile +23 -0
+                                    u8 numdbyte, u16 upd_val)
+{
+       u32 b_addr;
+       u16 val;
+       u8 byte;
+
+       /* Getting max value from DBYTEx TxDqsDlyTg0_ux_p0 */
+       for (byte = 0; byte < numdbyte; byte++) {
+               b_addr = byte << 13;
+
+               /* TxDqsDlyTg0[9:6] is the coarse delay */
+               val = (readw((uintptr_t)(handoff->phy_base +
+                            reg + b_addr)) &
+                            DDR_PHY_TXDQDLYTG0_COARSE_DELAY) >>
+                            DDR_PHY_TXDQDLYTG0_COARSE_DELAY_SHIFT;
+
+               upd_val = max(val, upd_val);
+       }
+
+       return upd_val;
+}
+
+static int set_cal_res_to_umctl2(struct ddr_handoff *handoff,

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+                                phys_addr_t umctl2_base,
+                                enum ddr_type umctl2_type)
+{
+       int ret;
+       u8 numdbyte = 0x8;
+       u16 upd_val, val;
+       u32 dramtmg2_reg_addr, rankctl_reg_addr, reg_addr;
+
+       /* Enable quasi-dynamic programing of the controller registers */
+       clrbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

Quoted 11 lines

drivers/ddr/altera/Makefile

Quoted 11 lines
drivers/ddr/altera/Makefile +11 -0
+
+       ret = enable_quasi_dynamic_reg_grp3(umctl2_base, umctl2_type);
+       if (ret)
+               return ret;
+
+       /* Enable access to the PHY configuration registers */
+       clrbits_le16(handoff->phy_base + DDR_PHY_APBONLY0_OFFSET,
+                    DDR_PHY_MICROCONTMUXSEL);
+
+       if (umctl2_type == DDRTYPE_DDR4) {
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base

+

Quoted 14 lines

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+                                    DMEM_MB_CDD_WW_1_0_OFFSET)));
+
+               upd_val = GET_LOWB_DATA(readw((uintptr_t)(handoff-

phy_base +

drivers/ddr/altera/Makefile

Quoted 6 lines
drivers/ddr/altera/Makefile +6 -0
+                                       DMEM_MB_CDD_WW_0_1_OFFSET)));
+       } else if (umctl2_type == DDRTYPE_LPDDR4_0) {
+               val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                   DMEM_MB_CDD_CHA_WW_1_0_OFFSET)));
+
+               upd_val = GET_HIGHB_DATA(readw((uintptr_t)(handoff-

phy_base +

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+                                        DMEM_MB_CDD_CHA_WW_0_1_OFFSET)));
+       } else if (umctl2_type == DDRTYPE_LPDDR4_1) {
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base

+

Quoted 4 lines

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+                                    DMEM_MB_CDD_CHB_WW_1_0_OFFSET)));
+
+               upd_val = GET_LOWB_DATA(readw((uintptr_t)(handoff-

phy_base +

Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+                                       DMEM_MB_CDD_CHB_WW_0_1_OFFSET)));
+       }
+
+       upd_val = max(val, upd_val);
+       debug("max value is 0x%x\n", upd_val);
+
+       /* Divided by two is required when running in freq ratio 1:2 */
+       if (!(readl(umctl2_base + DDR4_MSTR_OFFSET) &

DDR4_FREQ_RATIO))

Quoted 3 lines

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+               upd_val = DIV_ROUND_CLOSEST(upd_val, 2);
+
+       debug("Update train value to umctl2

RANKCTL.diff_rank_wr_gap\n");

Quoted 11 lines

drivers/ddr/altera/Makefile

Quoted 11 lines
drivers/ddr/altera/Makefile +11 -0
+       rankctl_reg_addr = umctl2_base + DDR4_RANKCTL_OFFSET;
+       /* Update train value to umctl2 RANKCTL.diff_rank_wr_gap */
+       set_cal_res_to_rankctrl(rankctl_reg_addr, upd_val,
+                               DDR4_RANKCTL_DIFF_RANK_WR_GAP,
+                               DDR4_RANKCTL_DIFF_RANK_WR_GAP_MSB,
+                               DDR4_RANKCTL_DIFF_RANK_WR_GAP_SHIFT);
+
+       debug("Update train value to umctl2 DRAMTMG2.W2RD\n");
+       dramtmg2_reg_addr = umctl2_base + DDR4_DRAMTMG2_OFFSET;
+       /* Update train value to umctl2 dramtmg2.wr2rd */
+       set_cal_res_to_reg(dramtmg2_reg_addr, upd_val,
Quoted 7 lines

DDR4_DRAMTMG2_WR2RD, 0);

Quoted 6 lines
drivers/ddr/altera/Makefile +6 -0
+
+       if (umctl2_type == DDRTYPE_DDR4) {
+               debug("Update train value to umctl2 DRAMTMG9.W2RD_S\n");
+               reg_addr = umctl2_base + DDR4_DRAMTMG9_OFFSET;
+               /* Update train value to umctl2 dramtmg9.wr2rd_s */
+               set_cal_res_to_reg(reg_addr, upd_val,

DDR4_DRAMTMG9_W2RD_S,

Quoted 5 lines

0);

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+       }
+
+       if (umctl2_type == DDRTYPE_DDR4) {
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base

+

Quoted 14 lines

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+                                    DMEM_MB_CDD_RR_1_0_OFFSET)));
+
+               upd_val = GET_LOWB_DATA(readw((uintptr_t)(handoff-

phy_base +

drivers/ddr/altera/Makefile

Quoted 6 lines
drivers/ddr/altera/Makefile +6 -0
+                                       DMEM_MB_CDD_RR_0_1_OFFSET)));
+       } else if (umctl2_type == DDRTYPE_LPDDR4_0) {
+               val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                   DMEM_MB_CDD_CHA_RR_1_0_OFFSET)));
+
+               upd_val = GET_HIGHB_DATA(readw((uintptr_t)(handoff-

phy_base +

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+                                        DMEM_MB_CDD_CHA_RR_0_1_OFFSET)));
+       } else if (umctl2_type == DDRTYPE_LPDDR4_1) {
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base

+

Quoted 4 lines

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+                                    DMEM_MB_CDD_CHB_RR_1_0_OFFSET)));
+
+               upd_val = GET_LOWB_DATA(readw((uintptr_t)(handoff-

phy_base +

Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+                                       DMEM_MB_CDD_CHB_RR_0_1_OFFSET)));
+       }
+
+       upd_val = max(val, upd_val);
+       debug("max value is 0x%x\n", upd_val);
+
+       /* Divided by two is required when running in freq ratio 1:2 */
+       if (!(readl(umctl2_base + DDR4_MSTR_OFFSET) &

DDR4_FREQ_RATIO))

Quoted 11 lines

drivers/ddr/altera/Makefile

Quoted 11 lines
drivers/ddr/altera/Makefile +11 -0
+               upd_val = DIV_ROUND_CLOSEST(upd_val, 2);
+
+       debug("Update train value to umctl2 RANKCTL.diff_rank_rd_gap\n");
+       /* Update train value to umctl2 RANKCTL.diff_rank_rd_gap */
+       set_cal_res_to_rankctrl(rankctl_reg_addr, upd_val,
+                               DDR4_RANKCTL_DIFF_RANK_RD_GAP,
+                               DDR4_RANKCTL_DIFF_RANK_RD_GAP_MSB,
+                               DDR4_RANKCTL_DIFF_RANK_RD_GAP_SHIFT);
+
+       if (umctl2_type == DDRTYPE_DDR4) {
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base

+

Quoted 9 lines

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+                                    DMEM_MB_CDD_RW_1_1_OFFSET)));
+
+               upd_val = GET_LOWB_DATA(readw((uintptr_t)(handoff-

phy_base +

drivers/ddr/altera/Makefile

Quoted 5 lines
drivers/ddr/altera/Makefile +5 -0
+                                       DMEM_MB_CDD_RW_1_0_OFFSET)));
+
+               upd_val = max(val, upd_val);
+
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base

+

Quoted 14 lines

drivers/ddr/altera/Makefile

Quoted 13 lines
drivers/ddr/altera/Makefile +13 -0
+                                    DMEM_MB_CDD_RW_0_1_OFFSET)));
+
+               upd_val = max(val, upd_val);
+
+               val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                   DMEM_MB_CDD_RW_0_0_OFFSET)));
+
+               upd_val = max(val, upd_val);
+       } else if (umctl2_type == DDRTYPE_LPDDR4_0) {
+               val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                   DMEM_MB_CDD_CHA_RW_1_1_OFFSET)));
+
+               upd_val = GET_HIGHB_DATA(readw((uintptr_t)(handoff-

phy_base +

Quoted 10 lines

drivers/ddr/altera/Makefile

Quoted 10 lines
drivers/ddr/altera/Makefile +10 -0
+                                        DMEM_MB_CDD_CHA_RW_1_0_OFFSET)));
+
+               upd_val = max(val, upd_val);
+
+               val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                   DMEM_MB_CDD_CHA_RW_0_1_OFFSET)));
+
+               upd_val = max(val, upd_val);
+
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base

+

Quoted 5 lines

drivers/ddr/altera/Makefile

Quoted 5 lines
drivers/ddr/altera/Makefile +5 -0
+                                    DMEM_MB_CDD_CHA_RW_0_0_OFFSET)));
+
+               upd_val = max(val, upd_val);
+       } else if (umctl2_type == DDRTYPE_LPDDR4_1) {
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base

+

Quoted 9 lines

drivers/ddr/altera/Makefile

Quoted 3 lines
drivers/ddr/altera/Makefile +3 -0
+                                    DMEM_MB_CDD_CHB_RW_1_1_OFFSET)));
+
+               upd_val = GET_LOWB_DATA(readw((uintptr_t)(handoff-

phy_base +

drivers/ddr/altera/Makefile

Quoted 5 lines
drivers/ddr/altera/Makefile +5 -0
+                                       DMEM_MB_CDD_CHB_RW_1_0_OFFSET)));
+
+               upd_val = max(val, upd_val);
+
+               val = GET_HIGHB_DATA(readw((uintptr_t)(handoff->phy_base

+

Quoted 6 lines
Quoted 6 lines
drivers/ddr/altera/Makefile +6 -0
+                                    DMEM_MB_CDD_CHB_RW_0_1_OFFSET)));
+
+               upd_val = max(val, upd_val);
+
+               val = GET_LOWB_DATA(readw((uintptr_t)(handoff->phy_base +
+                                   DMEM_MB_CDD_CHB_RW_0_0_OFFSET)));
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+
+               upd_val = max(val, upd_val);
+       }
+
+       debug("max value is 0x%x\n", upd_val);
+
+       /* Divided by two is required when running in freq ratio 1:2 */
+       if (!(readl(umctl2_base + DDR4_MSTR_OFFSET) &

DDR4_FREQ_RATIO))

Quoted 10 lines

drivers/ddr/altera/Makefile

Quoted 5 lines
drivers/ddr/altera/Makefile +5 -0
+               upd_val = DIV_ROUND_CLOSEST(upd_val, 2);
+
+       debug("Update train value to umctl2 dramtmg2.rd2wr\n");
+       /* Update train value to umctl2 dramtmg2.rd2wr */
+       set_cal_res_to_reg(dramtmg2_reg_addr, upd_val,

DDR4_DRAMTMG2_RD2WR,

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+                          DDR4_DRAMTMG2_RD2WR_SHIFT);
+
+       /* Checking ECC is enabled?, lpddr4 using inline ECC */
+       val = readl(umctl2_base + DDR4_ECCCFG0_OFFSET) &

DDR4_ECC_MODE;

Quoted 11 lines
Quoted 11 lines
drivers/ddr/altera/Makefile +11 -0
+       if (val && umctl2_type == DDRTYPE_DDR4)
+               numdbyte = 0x9;
+
+       upd_val = 0;
+
+       /* Getting max value from DBYTEx TxDqsDlyTg0_u0_p0 */
+       upd_val = get_max_txdqsdlytg0_ux_p0(handoff,
+                                           DDR_PHY_DBYTE0_TXDQDLYTG0_U0_P0,
+                                           numdbyte, upd_val);
+
+       /* Getting max value from DBYTEx TxDqsDlyTg0_u1_p0 */
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+       upd_val = get_max_txdqsdlytg0_ux_p0(handoff,
+                                           DDR_PHY_DBYTE0_TXDQDLYTG0_U1_P0,
+                                           numdbyte, upd_val);
+
+       debug("TxDqsDlyTg0 max value is 0x%x\n", upd_val);
+
+       /* Divided by two is required when running in freq ratio 1:2 */
+       if (!(readl(umctl2_base + DDR4_MSTR_OFFSET) &

DDR4_FREQ_RATIO))

Quoted 5 lines

drivers/ddr/altera/Makefile

Quoted 5 lines
drivers/ddr/altera/Makefile +5 -0
+               upd_val = DIV_ROUND_CLOSEST(upd_val, 2);
+
+       reg_addr = umctl2_base + DDR4_DFITMG1_OFFSET;
+       /* Update train value to umctl2 dfitmg1.dfi_wrdata_delay */
+       set_cal_res_to_reg(reg_addr, upd_val,
Quoted 10 lines

DDR4_DFITMG1_DFI_T_WRDATA_DELAY,

drivers/ddr/altera/Makefile

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+                          DDR4_DFITMG1_DFI_T_WRDATA_SHIFT);
+
+       /* Complete quasi-dynamic register programming */
+       setbits_le32(umctl2_base + DDR4_SWCTL_OFFSET,

DDR4_SWCTL_SW_DONE);

Quoted 4 lines
drivers/ddr/altera/Makefile +4 -0
+
+       /* Polling programming done */
+       ret = wait_for_bit_le32((const void *)(umctl2_base +
+                               DDR4_SWSTAT_OFFSET),

DDR4_SWSTAT_SW_DONE_ACK,

Quoted 12 lines
Quoted 12 lines
drivers/ddr/altera/Makefile +12 -0
+                               true, TIMEOUT_200MS, false);
+       if (ret) {
+               debug("%s: Timeout while waiting for", __func__);
+               debug(" programming done\n");
+       }
+
+       /* Isolate the APB access from internal CSRs */
+       setbits_le16(handoff->phy_base + DDR_PHY_APBONLY0_OFFSET,
+                    DDR_PHY_MICROCONTMUXSEL);
+
+       return ret;
+}
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+
+static int start_ddr_calibration(struct ddr_handoff *ddr_handoff_info)
+{
+       int ret;
+
+       /* Implement 1D training firmware */
+       ret = configure_training_firmware(ddr_handoff_info,
+               (const void

*)SOC64_HANDOFF_DDR_TRAIN_IMEM_1D_SECTION,

Quoted 1 line
Quoted 1 line

+ (const void

*)SOC64_HANDOFF_DDR_TRAIN_DMEM_1D_SECTION);

Quoted 23 lines
Quoted 23 lines
drivers/ddr/altera/Makefile +23 -0
+       if (ret) {
+               debug("%s: Failed to configure 1D training firmware\n",
+                     __func__);
+               return ret;
+       }
+
+       calibrating_sdram(ddr_handoff_info);
+
+       ret = poll_for_training_complete(ddr_handoff_info);
+       if (ret) {
+               debug("%s: Failed to get FW training completed\n",
+                     __func__);
+               return ret;
+       }
+
+       /* Updating training result to DDR controller */
+       if (ddr_handoff_info->cntlr_t == DDRTYPE_DDR4) {
+               ret = set_cal_res_to_umctl2(ddr_handoff_info,
+                                           ddr_handoff_info->cntlr_base,
+                                           ddr_handoff_info->cntlr_t);
+               if (ret) {
+                       debug("%s: Failed to update train result to ",
+                             __func__);
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+                       debug("DDR controller\n");
+                       return ret;
+               }
+       }
+
+       /* Implement 2D training firmware */
+       ret = configure_training_firmware(ddr_handoff_info,
+               (const void

*)SOC64_HANDOFF_DDR_TRAIN_IMEM_2D_SECTION,

Quoted 1 line
Quoted 1 line

+ (const void

*)SOC64_HANDOFF_DDR_TRAIN_DMEM_2D_SECTION);

Quoted 3 lines

drivers/ddr/altera/Makefile

Quoted 2 lines
drivers/ddr/altera/Makefile +2 -0
+       if (ret) {
+               if (ret) {

Why need 2 checking for "ret"?

Good catch !! I think this was accidently duplicated

Quoted 116 lines
Quoted 116 lines
drivers/ddr/altera/Makefile +115 -0
+                       debug("%s: Failed to update train result to ",
+                             __func__);
+                       debug("DDR controller\n");
+                       return ret;
+               }
+       }
+
+       calibrating_sdram(ddr_handoff_info);
+
+       ret = poll_for_training_complete(ddr_handoff_info);
+       if (ret)
+               debug("%s: Failed to get FW training completed\n",
+                     __func__);
+
+       return ret;
+}
+
+static int init_controller(struct ddr_handoff *ddr_handoff_info,
+                          u32 *user_backup, u32 *user_backup_2nd)
+{
+       int ret = 0;
+
+       if (ddr_handoff_info->cntlr_t == DDRTYPE_DDR4  ||
+           ddr_handoff_info->cntlr_t == DDRTYPE_LPDDR4_0) {
+               /* Initialize 1st DDR controller */
+               ret = init_umctl2(ddr_handoff_info->cntlr_handoff_base,
+                                 ddr_handoff_info->cntlr_base,
+                                 ddr_handoff_info->cntlr_t,
+                                 ddr_handoff_info->cntlr_handoff_length,
+                                 user_backup);
+               if (ret) {
+                       debug("%s: Failed to inilialize first controller\n",
+                             __func__);
+                       return ret;
+               }
+       }
+
+       if (ddr_handoff_info->cntlr2_t == DDRTYPE_LPDDR4_1) {
+               /* Initialize 2nd DDR controller */
+               ret = init_umctl2(ddr_handoff_info->cntlr2_handoff_base,
+                                 ddr_handoff_info->cntlr2_base,
+                                 ddr_handoff_info->cntlr2_t,
+                                 ddr_handoff_info->cntlr2_handoff_length,
+                                 user_backup_2nd);
+               if (ret)
+                       debug("%s: Failed to inilialize 2nd controller\n",
+                             __func__);
+       }
+
+       return ret;
+}
+
+static int dfi_init(struct ddr_handoff *ddr_handoff_info)
+{
+       int ret;
+
+       ret = ddr_start_dfi_init(ddr_handoff_info->cntlr_base,
+                                ddr_handoff_info->cntlr_t);
+       if (ret)
+               return ret;
+
+       if (ddr_handoff_info->cntlr2_t == DDRTYPE_LPDDR4_1)
+               ret = ddr_start_dfi_init(ddr_handoff_info->cntlr2_base,
+                                        ddr_handoff_info->cntlr2_t);
+
+       return ret;
+}
+
+static int check_dfi_init(struct ddr_handoff *handoff)
+{
+       int ret;
+
+       ret = ddr_check_dfi_init_complete(handoff->cntlr_base,
+                                         handoff->cntlr_t);
+       if (ret)
+               return ret;
+
+       if (handoff->cntlr2_t == DDRTYPE_LPDDR4_1)
+               ret = ddr_check_dfi_init_complete(handoff->cntlr2_base,
+                                                 handoff->cntlr2_t);
+
+       return ret;
+}
+
+static int trigger_sdram_init(struct ddr_handoff *handoff)
+{
+       int ret;
+
+       ret = ddr_trigger_sdram_init(handoff->cntlr_base,
+                                    handoff->cntlr_t);
+       if (ret)
+               return ret;
+
+       if (handoff->cntlr2_t == DDRTYPE_LPDDR4_1)
+               ret = ddr_trigger_sdram_init(handoff->cntlr2_base,
+                                            handoff->cntlr2_t);
+
+       return ret;
+}
+
+static int ddr_post_config(struct ddr_handoff *handoff)
+{
+       int ret;
+
+       ret = ddr_post_handoff_config(handoff->cntlr_base,
+                                     handoff->cntlr_t);
+       if (ret)
+               return ret;
+
+       if (handoff->cntlr2_t == DDRTYPE_LPDDR4_1)
+               ret = ddr_post_handoff_config(handoff->cntlr2_base,
+                                             handoff->cntlr2_t);
+
+       return ret;
+}
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+
+static bool is_ddr_retention_enabled(u32 boot_scratch_cold0_reg)
+{
+       return boot_scratch_cold0_reg &
+              ALT_SYSMGR_SCRATCH_REG_0_DDR_RETENTION_MASK;
+}
+
+static bool is_ddr_bitstream_sha_matching(u32

boot_scratch_cold0_reg)

Quoted 76 lines

drivers/ddr/altera/Makefile

Quoted 2 lines
drivers/ddr/altera/Makefile +2 -0
+{
+       return boot_scratch_cold0_reg &

ALT_SYSMGR_SCRATCH_REG_0_DDR_SHA_MASK;

Quoted 73 lines
drivers/ddr/altera/Makefile +73 -0
+}
+
+static enum reset_type get_reset_type(u32 boot_scratch_cold0_reg)
+{
+       return (boot_scratch_cold0_reg &
+               ALT_SYSMGR_SCRATCH_REG_0_DDR_RESET_TYPE_MASK) >>
+               ALT_SYSMGR_SCRATCH_REG_0_DDR_RESET_TYPE_SHIFT;
+}
+
+void reset_type_debug_print(u32 boot_scratch_cold0_reg)
+{
+       switch (get_reset_type(boot_scratch_cold0_reg)) {
+       case POR_RESET:
+               debug("%s: POR is triggered\n", __func__);
+               break;
+       case WARM_RESET:
+               debug("%s: Warm reset is triggered\n", __func__);
+               break;
+       case COLD_RESET:
+               debug("%s: Cold reset is triggered\n", __func__);
+               break;
+       default:
+               debug("%s: Invalid reset type\n", __func__);
+       }
+}
+
+bool is_ddr_init(void)
+{
+       u32 reg = readl(socfpga_get_sysmgr_addr() +
+                       SYSMGR_SOC64_BOOT_SCRATCH_COLD0);
+
+       reset_type_debug_print(reg);
+
+       if (get_reset_type(reg) == POR_RESET) {
+               debug("%s: DDR init is required\n", __func__);
+               return true;
+       }
+
+       if (get_reset_type(reg) == WARM_RESET) {
+               debug("%s: DDR init is skipped\n", __func__);
+               return false;
+       }
+
+       if (get_reset_type(reg) == COLD_RESET) {
+               if (is_ddr_retention_enabled(reg) &&
+                   is_ddr_bitstream_sha_matching(reg)) {
+                       debug("%s: DDR retention bit is set\n", __func__);
+                       debug("%s: Matching in DDR bistream\n", __func__);
+                       debug("%s: DDR init is skipped\n", __func__);
+                       return false;
+               }
+       }
+
+       debug("%s: DDR init is required\n", __func__);
+       return true;
+}
+
+int sdram_mmr_init_full(struct udevice *dev)
+{
+       u32 user_backup[2], user_backup_2nd[2];
+       int ret;
+       struct bd_info bd;
+       struct ddr_handoff ddr_handoff_info;
+       struct altera_sdram_priv *priv = dev_get_priv(dev);
+
+       printf("Checking SDRAM configuration in progress ...\n");
+       ret = populate_ddr_handoff(&ddr_handoff_info);
+               if (ret) {
+                       debug("%s: Failed to populate DDR handoff\n",
+                             __func__);
+                       return ret;
+               }
+
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+       /* Set the MPFE NoC mux to correct DDR controller type */
+       use_ddr4(ddr_handoff_info.cntlr_t);
+
+       if (is_ddr_init()) {
+               printf("SDRAM init in progress ...\n");
+
+               /*
+                * Polling reset complete, must be high to ensure DDR

subsystem

Quoted 22 lines
Quoted 22 lines
drivers/ddr/altera/Makefile +22 -0
+                * in complete reset state before init DDR clock and DDR
+                * controller
+                */
+               ret = wait_for_bit_le32((const void *)((uintptr_t)(readl
+                                       (ddr_handoff_info.mem_reset_base) +
+                                       MEM_RST_MGR_STATUS)),
+                                       MEM_RST_MGR_STATUS_RESET_COMPLETE,
+                                       true, TIMEOUT_200MS, false);
+               if (ret) {
+                       debug("%s: Timeout while waiting for", __func__);
+                       debug(" reset complete done\n");
+                       return ret;
+               }
+
+               ret = enable_ddr_clock(dev);
+               if (ret)
+                       return ret;
+
+               ret = init_controller(&ddr_handoff_info, user_backup,
+                                     user_backup_2nd);
+               if (ret) {
+                       debug("%s: Failed to inilialize DDR controller\n",
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+                             __func__);
+                       return ret;
+               }
+
+               /* Release the controller from reset */
+               setbits_le32((uintptr_t)
+                            (readl(ddr_handoff_info.mem_reset_base) +
+                            MEM_RST_MGR_STATUS),

MEM_RST_MGR_STATUS_AXI_RST

Quoted 59 lines

|

Quoted 58 lines
drivers/ddr/altera/Makefile +58 -0
+                            MEM_RST_MGR_STATUS_CONTROLLER_RST |
+                            MEM_RST_MGR_STATUS_RESET_COMPLETE);
+
+               printf("DDR controller configuration is completed\n");
+
+               /* Initialize DDR PHY */
+               ret = init_phy(&ddr_handoff_info);
+               if (ret) {
+                       debug("%s: Failed to inilialize DDR PHY\n", __func__);
+                       return ret;
+               }
+
+               enable_phy_clk_for_csr_access(&ddr_handoff_info, true);
+
+               ret = start_ddr_calibration(&ddr_handoff_info);
+               if (ret) {
+                       debug("%s: Failed to calibrate DDR\n", __func__);
+                       return ret;
+               }
+
+               enable_phy_clk_for_csr_access(&ddr_handoff_info, false);
+
+               /* Reset ARC processor when no using for security purpose */
+               setbits_le16(ddr_handoff_info.phy_base +
+                            DDR_PHY_MICRORESET_OFFSET,
+                            DDR_PHY_MICRORESET_RESET);
+
+               /* DDR freq set to support DDR4-3200 */
+               phy_init_engine(&ddr_handoff_info);
+
+               ret = dfi_init(&ddr_handoff_info);
+               if (ret)
+                       return ret;
+
+               ret = check_dfi_init(&ddr_handoff_info);
+               if (ret)
+                       return ret;
+
+               ret = trigger_sdram_init(&ddr_handoff_info);
+               if (ret)
+                       return ret;
+
+               ret = ddr_post_config(&ddr_handoff_info);
+               if (ret)
+                       return ret;
+
+               /* Restore user settings */
+               writel(user_backup[0], ddr_handoff_info.cntlr_base +
+                      DDR4_PWRCTL_OFFSET);
+
+               if (ddr_handoff_info.cntlr2_t == DDRTYPE_LPDDR4_0)
+                       setbits_le32(ddr_handoff_info.cntlr_base +
+                                    DDR4_INIT0_OFFSET, user_backup[1]);
+
+               if (ddr_handoff_info.cntlr2_t == DDRTYPE_LPDDR4_1) {
+                       /* Restore user settings */
+                       writel(user_backup_2nd[0],
+                              ddr_handoff_info.cntlr2_base +
Quoted 8 lines

drivers/ddr/altera/Makefile

Quoted 8 lines
drivers/ddr/altera/Makefile +8 -0
+                              DDR4_PWRCTL_OFFSET);
+
+                       setbits_le32(ddr_handoff_info.cntlr2_base +
+                                    DDR4_INIT0_OFFSET, user_backup_2nd[1]);
+               }
+
+               /* Enable input traffic per port */
+               setbits_le32(ddr_handoff_info.cntlr_base +

DDR4_PCTRL0_OFFSET,

Quoted 39 lines

Review

Quoted 31 lines
drivers/ddr/altera/Makefile +30 -0
+                            DDR4_PCTRL0_PORT_EN);
+
+               if (ddr_handoff_info.cntlr2_t == DDRTYPE_LPDDR4_1) {
+                       /* Enable input traffic per port */
+                       setbits_le32(ddr_handoff_info.cntlr2_base +
+                                    DDR4_PCTRL0_OFFSET, DDR4_PCTRL0_PORT_EN);
+               }
+
+               printf("DDR init success\n");
+       }
+
+       /* Get bank configuration from devicetree */
+       ret = fdtdec_decode_ram_size(gd->fdt_blob, NULL, 0, NULL,
+                                    (phys_size_t *)&gd->ram_size, &bd);
+       if (ret) {
+               debug("%s: Failed to decode memory node\n",  __func__);
+               return -1;
+       }
+
+       printf("DDR: %lld MiB\n", gd->ram_size >> 20);
+
+       priv->info.base = bd.bi_dram[0].start;
+       priv->info.size = gd->ram_size;
+
+       sdram_size_check(&bd);
+
+       sdram_set_firewall(&bd);
+
+       return 0;
+}
(quoted diff) +0 -0

b/drivers/ddr/altera/sdram_soc64.c

Quoted 7 lines

index cc656db97c..d6baac2410 100644

drivers/ddr/altera/sdram_soc64.c +0 -0
@@ -100,12 +100,14 @@ int emif_reset(struct altera_sdram_plat *plat)
        return 0;
 }
 
Quoted 4 lines

drivers/ddr/altera/sdram_soc64.c int emif_reset(struct altera_sdram_plat *plat)

Quoted 4 lines
drivers/ddr/altera/sdram_soc64.c +1 -0
+#if !IS_ENABLED(CONFIG_TARGET_SOCFPGA_N5X)
 int poll_hmc_clock_status(void)
 {
        return wait_for_bit_le32((const void *)(socfpga_get_sysmgr_addr()

+

Quoted 12 lines

drivers/ddr/altera/sdram_soc64.c phys_size_t sdram_calculate_size(struct

Quoted 8 lines
drivers/ddr/altera/sdram_soc64.c +1 -0
                                 SYSMGR_SOC64_HMC_CLK),
                                 SYSMGR_HMC_CLK_STATUS_MSK, true, 1000, false);
 }
+#endif
 
 void sdram_clear_mem(phys_addr_t addr, phys_size_t size)
 {
@@ -249,11 +251,78 @@ phys_size_t sdram_calculate_size(struct

altera_sdram_plat *plat)

Quoted 3 lines
drivers/ddr/altera/sdram_soc64.c +0 -0
        return size;
 }
 
Quoted 13 lines

drivers/ddr/altera/sdram_soc64.c phys_size_t sdram_calculate_size(struct altera_sdram_plat *plat)

Quoted 13 lines
drivers/ddr/altera/sdram_soc64.c +13 -0
+void sdram_set_firewall(struct bd_info *bd)
+{
+       u32 i;
+       phys_size_t value;
+       u32 lower, upper;
+
+       for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
+               if (!bd->bi_dram[i].size)
+                       continue;
+
+               value = bd->bi_dram[i].start;
+
+               /* Keep first 1MB of SDRAM memory region as secure region

when

Quoted 8 lines
Quoted 8 lines
drivers/ddr/altera/sdram_soc64.c +8 -0
+                * using ATF flow, where the ATF code is located.
+                */
+               if (IS_ENABLED(CONFIG_SPL_ATF) && i == 0)
+                       value += SZ_1M;
+
+               /* Setting non-secure MPU region base and base extended */
+               lower = lower_32_bits(value);
+               upper = upper_32_bits(value);
Quoted 8 lines

drivers/ddr/altera/sdram_soc64.c phys_size_t sdram_calculate_size(struct altera_sdram_plat *plat)

Quoted 8 lines
drivers/ddr/altera/sdram_soc64.c +8 -0
+               FW_MPU_DDR_SCR_WRITEL(lower,
+                                     FW_MPU_DDR_SCR_MPUREGION0ADDR_BASE +
+                                     (i * 4 * sizeof(u32)));
+               FW_MPU_DDR_SCR_WRITEL(upper & 0xff,
+                                     FW_MPU_DDR_SCR_MPUREGION0ADDR_BASEEXT +
+                                     (i * 4 * sizeof(u32)));
+
+               /* Setting non-secure Non-MPU region base and base extended

*/

Quoted 2 lines

drivers/ddr/altera/sdram_soc64.c phys_size_t sdram_calculate_size(struct · line 284

Quoted 2 lines
drivers/ddr/altera/sdram_soc64.c +2 -0
+               FW_MPU_DDR_SCR_WRITEL(lower,
+                                     FW_MPU_DDR_SCR_NONMPUREGION0ADDR_BASE

+

Quoted 3 lines

drivers/ddr/altera/sdram_soc64.c phys_size_t sdram_calculate_size(struct altera_sdram_plat *plat) · line 281

Quoted 3 lines
drivers/ddr/altera/sdram_soc64.c +3 -0
+                                     (i * 4 * sizeof(u32)));
+               FW_MPU_DDR_SCR_WRITEL(upper & 0xff,
+

FW_MPU_DDR_SCR_NONMPUREGION0ADDR_BASEEXT

Quoted 11 lines

+

Quoted 10 lines
drivers/ddr/altera/sdram_soc64.c +10 -0
+                                     (i * 4 * sizeof(u32)));
+
+               /* Setting non-secure MPU limit and limit extexded */
+               value = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
+
+               lower = lower_32_bits(value);
+               upper = upper_32_bits(value);
+
+               FW_MPU_DDR_SCR_WRITEL(lower,
+                                     FW_MPU_DDR_SCR_MPUREGION0ADDR_LIMIT +
Quoted 8 lines

drivers/ddr/altera/sdram_soc64.c phys_size_t sdram_calculate_size(struct altera_sdram_plat *plat)

Quoted 8 lines
drivers/ddr/altera/sdram_soc64.c +8 -0
+                                     (i * 4 * sizeof(u32)));
+               FW_MPU_DDR_SCR_WRITEL(upper & 0xff,
+                                     FW_MPU_DDR_SCR_MPUREGION0ADDR_LIMITEXT +
+                                     (i * 4 * sizeof(u32)));
+
+               /* Setting non-secure Non-MPU limit and limit extexded */
+               FW_MPU_DDR_SCR_WRITEL(lower,
+                                     FW_MPU_DDR_SCR_NONMPUREGION0ADDR_LIMIT

+

Quoted 3 lines

drivers/ddr/altera/sdram_soc64.c phys_size_t sdram_calculate_size(struct altera_sdram_plat *plat) · line 281

Quoted 3 lines
drivers/ddr/altera/sdram_soc64.c +3 -0
+                                     (i * 4 * sizeof(u32)));
+               FW_MPU_DDR_SCR_WRITEL(upper & 0xff,
+

FW_MPU_DDR_SCR_NONMPUREGION0ADDR_LIMITEXT

Quoted 45 lines

+

Review

Quoted 29 lines
drivers/ddr/altera/sdram_soc64.c +13 -0
+                                     (i * 4 * sizeof(u32)));
+
+               FW_MPU_DDR_SCR_WRITEL(BIT(i) | BIT(i + 8),
+                                     FW_MPU_DDR_SCR_EN_SET);
+       }
+}
+
 static int altera_sdram_of_to_plat(struct udevice *dev)
 {
        struct altera_sdram_plat *plat = dev_get_plat(dev);
        fdt_addr_t addr;
 
+       /* These regs info are part of DDR handoff in bitstream */
+#if IS_ENABLED(CONFIG_TARGET_SOCFPGA_N5X)
+       return 0;
+#endif
+
        addr = dev_read_addr_index(dev, 0);
        if (addr == FDT_ADDR_T_NONE)
                return -EINVAL;
@@ -314,6 +383,7 @@ static struct ram_ops altera_sdram_ops = {
 static const struct udevice_id altera_sdram_ids[] = {
        { .compatible = "altr,sdr-ctl-s10" },
        { .compatible = "intel,sdr-ctl-agilex" },
+       { .compatible = "intel,sdr-ctl-n5x" },
        { /* sentinel */ }
 };
 
(quoted diff) +0 -0

b/drivers/ddr/altera/sdram_soc64.h

Quoted 14 lines

index 8af0afc410..7460f8c220 100644

drivers/ddr/altera/sdram_soc64.h +1 -1
@@ -180,6 +180,7 @@ int emif_reset(struct altera_sdram_plat *plat);
 int poll_hmc_clock_status(void);
 void sdram_clear_mem(phys_addr_t addr, phys_size_t size);
 void sdram_init_ecc_bits(struct bd_info *bd);
+void sdram_set_firewall(struct bd_info *bd);
 void sdram_size_check(struct bd_info *bd);
 phys_size_t sdram_calculate_size(struct altera_sdram_plat *plat);
 int sdram_mmr_init_full(struct udevice *dev);
--

2.19.0

#24 lore raw

PATCH v2 13/17 arm: socfpga: Add SPL for Intel N5X device

In reply to Siew Chin Lim

Add SPL for N5X.

---
 .../mach-socfpga/{spl_agilex.c => spl_n5x.c}  | 37 +++++++++++--------
 1 file changed, 22 insertions(+), 15 deletions(-)
 copy arch/arm/mach-socfpga/{spl_agilex.c => spl_n5x.c} (83%)
arch/arm/mach-socfpga/spl_n5x.c renamed from arch/arm/mach-socfpga/spl_agilex.c +22 -15
similarity index 83%
copy from arch/arm/mach-socfpga/spl_agilex.c
copy to arch/arm/mach-socfpga/spl_n5x.c
index ee5a9dc1e2..d056871d29 100644
@@ -1,27 +1,26 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (C) 2019 Intel Corporation <www.intel.com>
+ * Copyright (C) 2020-2021 Intel Corporation <www.intel.com>
  *
  */
 
-#include <init.h>
-#include <log.h>
-#include <asm/global_data.h>
-#include <asm/io.h>
-#include <asm/u-boot.h>
-#include <asm/utils.h>
 #include <common.h>
-#include <hang.h>
-#include <image.h>
-#include <spl.h>
 #include <asm/arch/clock_manager.h>
 #include <asm/arch/firewall.h>
 #include <asm/arch/mailbox_s10.h>
 #include <asm/arch/misc.h>
 #include <asm/arch/reset_manager.h>
 #include <asm/arch/system_manager.h>
-#include <watchdog.h>
+#include <asm/global_data.h>
+#include <asm/io.h>
+#include <asm/u-boot.h>
+#include <asm/utils.h>
 #include <dm/uclass.h>
+#include <hang.h>
+#include <image.h>
+#include <init.h>
+#include <spl.h>
+#include <watchdog.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -54,27 +53,35 @@ void board_init_f(ulong dummy)
 
 	sysmgr_pinmux_init();
 
+	preloader_console_init();
+
 	ret = uclass_get_device(UCLASS_CLK, 0, &dev);
 	if (ret) {
-		debug("Clock init failed: %d\n", ret);
+		printf("Clock init failed: %d\n", ret);
+		hang();
+	}
+
+	ret = uclass_get_device(UCLASS_CLK, 1, &dev);
+	if (ret) {
+		printf("Memory clock init failed: %d\n", ret);
 		hang();
 	}
 
-	preloader_console_init();
 	print_reset_info();
 	cm_print_clock_quick_summary();
 
 	firewall_setup();
+
 	ret = uclass_get_device(UCLASS_CACHE, 0, &dev);
 	if (ret) {
-		debug("CCU init failed: %d\n", ret);
+		printf("CCU init failed: %d\n", ret);
 		hang();
 	}
 
 #if CONFIG_IS_ENABLED(ALTERA_SDRAM)
 	ret = uclass_get_device(UCLASS_RAM, 0, &dev);
 	if (ret) {
-		debug("DRAM init failed: %d\n", ret);
+		printf("DRAM init failed: %d\n", ret);
 		hang();
 	}
 #endif
Signature · 1 line
2.19.0
Reviewed-by on v2 13/17
#25 lore raw

Re: [v2 13/17] arm: socfpga: Add SPL for Intel N5X device

Quoted 17 lines · Siew Chin Lim

Add SPL for N5X.

---
 .../mach-socfpga/{spl_agilex.c => spl_n5x.c}  | 37 +++++++++++--------
 1 file changed, 22 insertions(+), 15 deletions(-)
 copy arch/arm/mach-socfpga/{spl_agilex.c => spl_n5x.c} (83%)
arch/arm/mach-socfpga/spl_n5x.c renamed from arch/arm/mach-socfpga/spl_agilex.c +0 -0
similarity index 83%
copy from arch/arm/mach-socfpga/spl_agilex.c
copy to arch/arm/mach-socfpga/spl_n5x.c
index ee5a9dc1e2..d056871d29 100644

arch/arm/mach-socfpga/spl_n5x.c line 2

Quoted 2 lines
arch/arm/mach-socfpga/spl_n5x.c renamed from arch/arm/mach-socfpga/spl_agilex.c +0 -0
@@ -1,27 +1,26 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
#26 lore raw

PATCH v2 14/17 board: intel: Add socdk board support for Intel N5X device

In reply to Siew Chin Lim

Add N5X SoC devkit board.

---
 board/intel/n5x-socdk/MAINTAINERS                          | 7 +++++++
 board/{altera/stratix10-socdk => intel/n5x-socdk}/Makefile | 2 +-
 .../{altera/stratix10-socdk => intel/n5x-socdk}/socfpga.c  | 2 +-
 3 files changed, 9 insertions(+), 2 deletions(-)
 create mode 100644 board/intel/n5x-socdk/MAINTAINERS
 copy board/{altera/stratix10-socdk => intel/n5x-socdk}/Makefile (50%)
 copy board/{altera/stratix10-socdk => intel/n5x-socdk}/socfpga.c (52%)
board/intel/n5x-socdk/MAINTAINERS new file +7 -0
new file mode 100644
index 0000000000..c1059f092c
@@ -0,0 +1,7 @@
+SOCFPGA BOARD
+M:	Chee Tien Fong <[email protected]>
+M:	Lim Siew Chin <[email protected]>
+S:	Maintained
+F:	board/intel/n5x-socdk/
+F:	include/configs/socfpga_n5x_socdk.h
+F:	configs/socfpga_n5x_atf_defconfig
board/intel/n5x-socdk/Makefile renamed from board/altera/stratix10-socdk/Makefile +1 -1
similarity index 50%
copy from board/altera/stratix10-socdk/Makefile
copy to board/intel/n5x-socdk/Makefile
index 02a9cadf76..accfdcddcb 100644
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2016-2017 Intel Corporation <www.intel.com>
+# Copyright (C) 2020-2021 Intel Corporation <www.intel.com>
 #
 # SPDX-License-Identifier:	GPL-2.0
 #
board/intel/n5x-socdk/socfpga.c renamed from board/altera/stratix10-socdk/socfpga.c +1 -1
similarity index 52%
copy from board/altera/stratix10-socdk/socfpga.c
copy to board/intel/n5x-socdk/socfpga.c
index 043fc543f1..985ba190d0 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (C) 2016-2018 Intel Corporation <www.intel.com>
+ * Copyright (C) 2020-2021 Intel Corporation <www.intel.com>
  *
  */
 
Signature · 1 line
2.19.0
#27 lore raw

PATCH v2 15/17 arm: dts: Add base dtsi and devkit dts for Intel N5X device

In reply to Siew Chin Lim

Add device tree for N5X.

---
v2:
- Remove socfpga_n5x.dtsi
- Reuse socfpga_agilex.dtsi in socfpga_n5x_socdk.dts and update n5x data accordingly.

---
 arch/arm/dts/Makefile                         |   1 +
 ...ex-u-boot.dtsi => socfpga_n5x-u-boot.dtsi} |  13 ++-
 arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi    |  67 +++++++++++
 ...agilex_socdk.dts => socfpga_n5x_socdk.dts} | 110 +++++++++++++++++-
 4 files changed, 182 insertions(+), 9 deletions(-)
 copy arch/arm/dts/{socfpga_agilex-u-boot.dtsi => socfpga_n5x-u-boot.dtsi} (85%)
 create mode 100644 arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi
 copy arch/arm/dts/{socfpga_agilex_socdk.dts => socfpga_n5x_socdk.dts} (57%)
arch/arm/dts/Makefile +1 -0
index aec5020a0f..2e13277816 100644
@@ -381,6 +381,7 @@ dtb-$(CONFIG_ARCH_SOCFPGA) +=				\
 	socfpga_cyclone5_socrates.dtb			\
 	socfpga_cyclone5_sr1500.dtb			\
 	socfpga_cyclone5_vining_fpga.dtb		\
+	socfpga_n5x_socdk.dtb				\
 	socfpga_stratix10_socdk.dtb
 
 dtb-$(CONFIG_TARGET_DRA7XX_EVM) += dra72-evm.dtb dra7-evm.dtb	\
arch/arm/dts/socfpga_n5x-u-boot.dtsi renamed from arch/arm/dts/socfpga_agilex-u-boot.dtsi +8 -5
similarity index 85%
copy from arch/arm/dts/socfpga_agilex-u-boot.dtsi
copy to arch/arm/dts/socfpga_n5x-u-boot.dtsi
index 08f7cf7f7a..2f63f4a4e6 100644
@@ -2,7 +2,7 @@
 /*
  * U-Boot additions
  *
- * Copyright (C) 2019-2020 Intel Corporation <www.intel.com>
+ * Copyright (C) 2020-2021 Intel Corporation <www.intel.com>
  */
 
 #include "socfpga_soc64_fit-u-boot.dtsi"
@@ -53,6 +53,10 @@
 	reset-names = "i2c";
 };
 
+&memclkmgr {
+	u-boot,dm-pre-reloc;
+};
+
 &mmc {
 	resets = <&rst SDMMC_RESET>, <&rst SDMMC_OCP_RESET>;
 };
@@ -76,11 +80,10 @@
 };
 
 &sdr {
-	compatible = "intel,sdr-ctl-agilex";
-	reg = <0xf8000400 0x80>,
-	      <0xf8010000 0x190>,
-	      <0xf8011000 0x500>;
+	compatible = "intel,sdr-ctl-n5x";
 	resets = <&rst DDRSCH_RESET>;
+	clocks = <&memclkmgr>;
+	clock-names = "mem_clk";
 	u-boot,dm-pre-reloc;
 };
 
arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi new file +67 -0

67 lines not on this page · raw message

arch/arm/dts/socfpga_n5x_socdk.dts renamed from arch/arm/dts/socfpga_agilex_socdk.dts +106 -4

175 lines not on this page · raw message

Signature · 1 line
2.19.0
#28 lore raw

Re: [v2 15/17] arm: dts: Add base dtsi and devkit dts for Intel N5X device

Quoted 100 lines · Siew Chin Lim

Add device tree for N5X.

---
v2:
- Remove socfpga_n5x.dtsi
- Reuse socfpga_agilex.dtsi in socfpga_n5x_socdk.dts and update n5x data accordingly.

---
 arch/arm/dts/Makefile                         |   1 +
 ...ex-u-boot.dtsi => socfpga_n5x-u-boot.dtsi} |  13 ++-
 arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi    |  67 +++++++++++
 ...agilex_socdk.dts => socfpga_n5x_socdk.dts} | 110 +++++++++++++++++-
 4 files changed, 182 insertions(+), 9 deletions(-)
 copy arch/arm/dts/{socfpga_agilex-u-boot.dtsi => socfpga_n5x-u-boot.dtsi} (85%)
 create mode 100644 arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi
 copy arch/arm/dts/{socfpga_agilex_socdk.dts => socfpga_n5x_socdk.dts} (57%)
arch/arm/dts/Makefile +1 -0
index aec5020a0f..2e13277816 100644
@@ -381,6 +381,7 @@ dtb-$(CONFIG_ARCH_SOCFPGA) +=                               \
        socfpga_cyclone5_socrates.dtb                   \
        socfpga_cyclone5_sr1500.dtb                     \
        socfpga_cyclone5_vining_fpga.dtb                \
+       socfpga_n5x_socdk.dtb                           \
        socfpga_stratix10_socdk.dtb
 
 dtb-$(CONFIG_TARGET_DRA7XX_EVM) += dra72-evm.dtb dra7-evm.dtb  \
arch/arm/dts/socfpga_n5x-u-boot.dtsi renamed from arch/arm/dts/socfpga_agilex-u-boot.dtsi +8 -5
similarity index 85%
copy from arch/arm/dts/socfpga_agilex-u-boot.dtsi
copy to arch/arm/dts/socfpga_n5x-u-boot.dtsi
index 08f7cf7f7a..2f63f4a4e6 100644
@@ -2,7 +2,7 @@
 /*
  * U-Boot additions
  *
- * Copyright (C) 2019-2020 Intel Corporation <www.intel.com>
+ * Copyright (C) 2020-2021 Intel Corporation <www.intel.com>
  */
 
 #include "socfpga_soc64_fit-u-boot.dtsi"
@@ -53,6 +53,10 @@
        reset-names = "i2c";
 };
 
+&memclkmgr {
+       u-boot,dm-pre-reloc;
+};
+
 &mmc {
        resets = <&rst SDMMC_RESET>, <&rst SDMMC_OCP_RESET>;
 };
@@ -76,11 +80,10 @@
 };
 
 &sdr {
-       compatible = "intel,sdr-ctl-agilex";
-       reg = <0xf8000400 0x80>,
-             <0xf8010000 0x190>,
-             <0xf8011000 0x500>;
+       compatible = "intel,sdr-ctl-n5x";
        resets = <&rst DDRSCH_RESET>;
+       clocks = <&memclkmgr>;
+       clock-names = "mem_clk";
        u-boot,dm-pre-reloc;
 };
 
arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi new file +19 -0
new file mode 100644
index 0000000000..57509f083e
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * U-Boot additions
+ *
+ * Copyright (C) 2020-2021 Intel Corporation <www.intel.com>
+ */
+
+#include "socfpga_n5x-u-boot.dtsi"
+
+/{
+       aliases {
+               spi0 = &qspi;
+               i2c0 = &i2c1;
+       };
+
+       memory {
+               /*
+                * Memory type: DDR4
+                * 16GB

arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi line 29

Quoted 10 lines
arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi new file +10 -0
+                *     <0 0x00000000 0 0x80000000>,
+                *     <4 0x80000000 3 0x80000000>;
+                *
+                * 8GB
+                *     <0 0x00000000 0 0x80000000>,
+                *     <2 0x80000000 1 0x80000000>;
+                *
+                * 4GB
+                *     <0 0x00000000 0 0x80000000>,
+                *     <1 0x80000000 0 0x80000000>;

These example ranges only work for interleaving mode? If yes, add the comment.

arch/arm/dts/socfpga_n5x_socdk.dts

Quoted 45 lines
arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi new file +38 -0
+                *
+                * Memory type: LPDDR4 (non-interleaving mode)
+                * Total memory size 3GB, usable = 2.5GB, 0.5GB trade off for secure
+                * region.
+                */
+               reg = <0 0x00000000 0 0x60000000>,
+                         <0x10 0x00100000 0 0x40000000>;
+       };
+};
+
+&flash0 {
+       compatible = "jedec,spi-nor";
+       spi-tx-bus-width = <4>;
+       spi-rx-bus-width = <4>;
+       u-boot,dm-pre-reloc;
+};
+
+&i2c1 {
+       status = "okay";
+};
+
+&nand {
+       u-boot,dm-pre-reloc;
+};
+
+&mmc {
+       drvsel = <3>;
+       smplsel = <0>;
+       u-boot,dm-pre-reloc;
+};
+
+&qspi {
+       status = "okay";
+};
+
+&watchdog0 {
+       u-boot,dm-pre-reloc;
+};
arch/arm/dts/socfpga_n5x_socdk.dts renamed from arch/arm/dts/socfpga_agilex_socdk.dts +0 -0
similarity index 57%
copy from arch/arm/dts/socfpga_agilex_socdk.dts
copy to arch/arm/dts/socfpga_n5x_socdk.dts
index bcdeecc0e0..30130bb910 100644

This file sync from Linux dts?

Quoted 29 lines
arch/arm/dts/socfpga_n5x_socdk.dts renamed from arch/arm/dts/socfpga_agilex_socdk.dts +6 -2
@@ -1,11 +1,12 @@
 // SPDX-License-Identifier:     GPL-2.0
 /*
- * Copyright (C) 2019, Intel Corporation
+ * Copyright (C) 2020-2021, Intel Corporation
  */
 #include "socfpga_agilex.dtsi"
+#include <dt-bindings/clock/n5x-clock.h>
 
 / {
-       model = "SoCFPGA Agilex SoCDK";
+       model = "eASIC N5X SoCDK";
 
        aliases {
                serial0 = &uart0;
@@ -16,6 +17,7 @@
 
        chosen {
                stdout-path = "serial0:115200n8";
+               u-boot,boot0 = <&mmc>;
        };
 
        leds {
@@ -47,10 +49,26 @@
                        osc1 {
                                clock-frequency = <25000000>;
                        };
+
+                       dram_eosc_clk: dram-eosc-clk {

arch/arm/dts/socfpga_n5x_socdk.dts line 63

Quoted 10 lines
arch/arm/dts/socfpga_n5x_socdk.dts renamed from arch/arm/dts/socfpga_agilex_socdk.dts +10 -0
+                               #clock-cells = <0>;
+                               compatible = "fixed-clock";
+                       };
+               };
+
+               memclkmgr: mem-clock-controller@f8040000 {
+                       compatible = "intel,n5x-mem-clkmgr";
+                       reg = <0xf8040000 0x1000>;
+                       #clock-cells = <0>;
+                       clocks = <&dram_eosc_clk>, <&f2s_free_clk>;

All these should use for all N5X devices, right? Then these should move to socfpga_n5x-u-boot.dtsi.

arch/arm/dts/socfpga_n5x_socdk.dts line 70

Quoted 7 lines
arch/arm/dts/socfpga_n5x_socdk.dts renamed from arch/arm/dts/socfpga_agilex_socdk.dts +3 -0
                };
        };
 };
 
+&clkmgr {
+       compatible = "intel,n5x-clkmgr";
+};

Same here and all the clocks parameters below.

Quoted 138 lines
arch/arm/dts/socfpga_n5x_socdk.dts renamed from arch/arm/dts/socfpga_agilex_socdk.dts +87 -3
+
 &gpio1 {
        status = "okay";
 };
@@ -59,8 +77,8 @@
        status = "okay";
        phy-mode = "rgmii";
        phy-handle = <&phy0>;
-
        max-frame-size = <9000>;
+       clocks = <&clkmgr N5X_EMAC0_CLK>;
 
        mdio0 {
                #address-cells = <1>;
@@ -85,27 +103,111 @@
        };
 };
 
+&gmac1 {
+       clocks = <&clkmgr N5X_EMAC1_CLK>;
+};
+
+&gmac2 {
+       clocks = <&clkmgr N5X_EMAC2_CLK>;
+};
+
+&i2c0 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>;
+};
+
+&i2c1 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>;
+};
+
+&i2c2 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>;
+};
+
+&i2c3 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>;
+};
+
+&i2c4 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>;
+};
+
 &mmc {
        status = "okay";
        cap-sd-highspeed;
        broken-cd;
        bus-width = <4>;
+
+       clocks = <&clkmgr N5X_L4_MP_CLK>,
+                <&clkmgr N5X_SDMMC_CLK>;
+};
+
+&pdma {
+       clocks = <&clkmgr N5X_L4_MAIN_CLK>;
+};
+
+&spi0 {
+       clocks = <&clkmgr N5X_L4_MAIN_CLK>;
+};
+
+&spi1 {
+       clocks = <&clkmgr N5X_L4_MAIN_CLK>;
+};
+
+&timer0 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>;
+};
+
+&timer1 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>;
+};
+
+&timer2 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>;
+};
+
+&timer3 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>;
 };
 
 &uart0 {
        status = "okay";
+       clocks = <&clkmgr N5X_L4_SP_CLK>;
+};
+
+&uart1 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>;
 };
 
 &usb0 {
        status = "okay";
+       clocks = <&clkmgr N5X_USB_CLK>;
        disable-over-current;
 };
 
+&usb1 {
+       status = "okay";
+       clocks = <&clkmgr N5X_USB_CLK>;
+};
+
 &watchdog0 {
        status = "okay";
+       clocks = <&clkmgr N5X_L4_SYS_FREE_CLK>;
+};
+
+&watchdog1 {
+       clocks = <&clkmgr N5X_L4_SYS_FREE_CLK>;
+};
+
+&watchdog2 {
+       clocks = <&clkmgr N5X_L4_SYS_FREE_CLK>;
+};
+
+&watchdog3 {
+       clocks = <&clkmgr N5X_L4_SYS_FREE_CLK>;
 };
 
 &qspi {
+       status = "okay";
        flash0: flash@0 {
                #address-cells = <1>;
                #size-cells = <1>;
@@ -116,7 +218,7 @@
                m25p,fast-read;
                cdns,page-size = <256>;
                cdns,block-size = <16>;
-               cdns,read-delay = <1>;
+               cdns,read-delay = <3>;
                cdns,tshsl-ns = <50>;
                cdns,tsd2d-ns = <50>;
                cdns,tchsh-ns = <4>;
--

2.19.0

#29 lore raw

Re: [v2 15/17] arm: dts: Add base dtsi and devkit dts for Intel N5X device

Quoted 175 lines · Ley Foon Tan
Quoted 100 lines · Siew Chin Lim

Add device tree for N5X.

---
v2:
- Remove socfpga_n5x.dtsi
- Reuse socfpga_agilex.dtsi in socfpga_n5x_socdk.dts and update n5x data accordingly.

---
 arch/arm/dts/Makefile                         |   1 +
 ...ex-u-boot.dtsi => socfpga_n5x-u-boot.dtsi} |  13 ++-
 arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi    |  67 +++++++++++
 ...agilex_socdk.dts => socfpga_n5x_socdk.dts} | 110 +++++++++++++++++-
 4 files changed, 182 insertions(+), 9 deletions(-)
 copy arch/arm/dts/{socfpga_agilex-u-boot.dtsi => socfpga_n5x-u-boot.dtsi} (85%)
 create mode 100644 arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi
 copy arch/arm/dts/{socfpga_agilex_socdk.dts => socfpga_n5x_socdk.dts} (57%)
arch/arm/dts/Makefile +1 -0
index aec5020a0f..2e13277816 100644
@@ -381,6 +381,7 @@ dtb-$(CONFIG_ARCH_SOCFPGA) +=                               \
        socfpga_cyclone5_socrates.dtb                   \
        socfpga_cyclone5_sr1500.dtb                     \
        socfpga_cyclone5_vining_fpga.dtb                \
+       socfpga_n5x_socdk.dtb                           \
        socfpga_stratix10_socdk.dtb
 
 dtb-$(CONFIG_TARGET_DRA7XX_EVM) += dra72-evm.dtb dra7-evm.dtb  \
arch/arm/dts/socfpga_n5x-u-boot.dtsi renamed from arch/arm/dts/socfpga_agilex-u-boot.dtsi +8 -5
similarity index 85%
copy from arch/arm/dts/socfpga_agilex-u-boot.dtsi
copy to arch/arm/dts/socfpga_n5x-u-boot.dtsi
index 08f7cf7f7a..2f63f4a4e6 100644
@@ -2,7 +2,7 @@
 /*
  * U-Boot additions
  *
- * Copyright (C) 2019-2020 Intel Corporation <www.intel.com>
+ * Copyright (C) 2020-2021 Intel Corporation <www.intel.com>
  */
 
 #include "socfpga_soc64_fit-u-boot.dtsi"
@@ -53,6 +53,10 @@
        reset-names = "i2c";
 };
 
+&memclkmgr {
+       u-boot,dm-pre-reloc;
+};
+
 &mmc {
        resets = <&rst SDMMC_RESET>, <&rst SDMMC_OCP_RESET>;
 };
@@ -76,11 +80,10 @@
 };
 
 &sdr {
-       compatible = "intel,sdr-ctl-agilex";
-       reg = <0xf8000400 0x80>,
-             <0xf8010000 0x190>,
-             <0xf8011000 0x500>;
+       compatible = "intel,sdr-ctl-n5x";
        resets = <&rst DDRSCH_RESET>;
+       clocks = <&memclkmgr>;
+       clock-names = "mem_clk";
        u-boot,dm-pre-reloc;
 };
 
arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi new file +19 -0
new file mode 100644
index 0000000000..57509f083e
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * U-Boot additions
+ *
+ * Copyright (C) 2020-2021 Intel Corporation <www.intel.com>
+ */
+
+#include "socfpga_n5x-u-boot.dtsi"
+
+/{
+       aliases {
+               spi0 = &qspi;
+               i2c0 = &i2c1;
+       };
+
+       memory {
+               /*
+                * Memory type: DDR4
+                * 16GB

arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi line 29

Quoted 10 lines
arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi new file +10 -0
+                *     <0 0x00000000 0 0x80000000>,
+                *     <4 0x80000000 3 0x80000000>;
+                *
+                * 8GB
+                *     <0 0x00000000 0 0x80000000>,
+                *     <2 0x80000000 1 0x80000000>;
+                *
+                * 4GB
+                *     <0 0x00000000 0 0x80000000>,
+                *     <1 0x80000000 0 0x80000000>;

These example ranges only work for interleaving mode? If yes, add the comment.

arch/arm/dts/socfpga_n5x_socdk.dts

Quoted 45 lines
arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi new file +38 -0
+                *
+                * Memory type: LPDDR4 (non-interleaving mode)
+                * Total memory size 3GB, usable = 2.5GB, 0.5GB trade off for secure
+                * region.
+                */
+               reg = <0 0x00000000 0 0x60000000>,
+                         <0x10 0x00100000 0 0x40000000>;
+       };
+};
+
+&flash0 {
+       compatible = "jedec,spi-nor";
+       spi-tx-bus-width = <4>;
+       spi-rx-bus-width = <4>;
+       u-boot,dm-pre-reloc;
+};
+
+&i2c1 {
+       status = "okay";
+};
+
+&nand {
+       u-boot,dm-pre-reloc;
+};
+
+&mmc {
+       drvsel = <3>;
+       smplsel = <0>;
+       u-boot,dm-pre-reloc;
+};
+
+&qspi {
+       status = "okay";
+};
+
+&watchdog0 {
+       u-boot,dm-pre-reloc;
+};
arch/arm/dts/socfpga_n5x_socdk.dts renamed from arch/arm/dts/socfpga_agilex_socdk.dts +0 -0
similarity index 57%
copy from arch/arm/dts/socfpga_agilex_socdk.dts
copy to arch/arm/dts/socfpga_n5x_socdk.dts
index bcdeecc0e0..30130bb910 100644

This file sync from Linux dts?

Quoted 13 lines
arch/arm/dts/socfpga_n5x_socdk.dts renamed from arch/arm/dts/socfpga_agilex_socdk.dts +3 -2
@@ -1,11 +1,12 @@
 // SPDX-License-Identifier:     GPL-2.0
 /*
- * Copyright (C) 2019, Intel Corporation
+ * Copyright (C) 2020-2021, Intel Corporation
  */
 #include "socfpga_agilex.dtsi"
+#include <dt-bindings/clock/n5x-clock.h>
 
 / {
-       model = "SoCFPGA Agilex SoCDK";
+       model = "eASIC N5X SoCDK";
 
Quoted 7 lines

arch/arm/dts/socfpga_n5x_socdk.dts line 20

Quoted 7 lines
arch/arm/dts/socfpga_n5x_socdk.dts renamed from arch/arm/dts/socfpga_agilex_socdk.dts +1 -0
        aliases {
                serial0 = &uart0;
@@ -16,6 +17,7 @@
 
        chosen {
                stdout-path = "serial0:115200n8";
+               u-boot,boot0 = <&mmc>;

Unused parameter, " u-boot,boot0" should be removed.

Regards
Ley Foon

#30 lore raw

RE: [v2 15/17] arm: dts: Add base dtsi and devkit dts for Intel N5X device

Quoted 196 lines

-----Original Message-----
From: Ley Foon Tan <[email protected]>
Sent: Friday, May 28, 2021 4:37 PM
To: Lim, Elly Siew Chin <[email protected]>
Cc: ZY - u-boot <[email protected]>; Marek Vasut <[email protected]>; Simon Goldschmidt <[email protected]>; Chee, Tien Fong <[email protected]>; Westergreen, Dalon <[email protected]>; Simon Glass <[email protected]>; Gan, Yau Wai <[email protected]>
Subject: Re: [v2 15/17] arm: dts: Add base dtsi and devkit dts for Intel N5X device

Quoted 26 lines · Ley Foon Tan
Quoted 23 lines · Siew Chin Lim

Add device tree for N5X.

---
v2:
- Remove socfpga_n5x.dtsi
- Reuse socfpga_agilex.dtsi in socfpga_n5x_socdk.dts and update n5x data accordingly.

---
 arch/arm/dts/Makefile                         |   1 +
 ...ex-u-boot.dtsi => socfpga_n5x-u-boot.dtsi} |  13 ++-
 arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi    |  67 +++++++++++
 ...agilex_socdk.dts => socfpga_n5x_socdk.dts} | 110
+++++++++++++++++-
 4 files changed, 182 insertions(+), 9 deletions(-)  copy
arch/arm/dts/{socfpga_agilex-u-boot.dtsi => socfpga_n5x-u-boot.dtsi}
(85%)  create mode 100644 arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi
 copy arch/arm/dts/{socfpga_agilex_socdk.dts =>

socfpga_n5x_socdk.dts} (57%)

Quoted 5 lines

arch/arm/dts/Makefile dtb-$(CONFIG_ARCH_SOCFPGA) +=

Quoted 5 lines
arch/arm/dts/Makefile index renamed from arch/arm/dts/Makefile +0 -0

aec5020a0f..2e13277816 100644

arch/arm/dts/Makefile +0 -0
@@ -381,6 +381,7 @@ dtb-$(CONFIG_ARCH_SOCFPGA) +=

\

Quoted 7 lines

arch/arm/dts/Makefile dtb-$(CONFIG_ARCH_SOCFPGA) += \

Quoted 7 lines
arch/arm/dts/Makefile +1 -0
        socfpga_cyclone5_socrates.dtb                   \
        socfpga_cyclone5_sr1500.dtb                     \
        socfpga_cyclone5_vining_fpga.dtb                \
+       socfpga_n5x_socdk.dtb                           \
        socfpga_stratix10_socdk.dtb
 
 dtb-$(CONFIG_TARGET_DRA7XX_EVM) += dra72-evm.dtb dra7-evm.dtb

\

Quoted 69 lines
Quoted 69 lines
arch/arm/dts/socfpga_n5x-u-boot.dtsi renamed from arch/arm/dts/socfpga_agilex-u-boot.dtsi +8 -6
similarity index 85%
copy from arch/arm/dts/socfpga_agilex-u-boot.dtsi
copy to arch/arm/dts/socfpga_n5x-u-boot.dtsi
index 08f7cf7f7a..2f63f4a4e6 100644
@@ -2,7 +2,7 @@
 /*
  * U-Boot additions
  *
- * Copyright (C) 2019-2020 Intel Corporation <www.intel.com>
+ * Copyright (C) 2020-2021 Intel Corporation <www.intel.com>
  */
 
 #include "socfpga_soc64_fit-u-boot.dtsi"
@@ -53,6 +53,10 @@
        reset-names = "i2c";
 };
 
+&memclkmgr {
+       u-boot,dm-pre-reloc;
+};
+
 &mmc {
        resets = <&rst SDMMC_RESET>, <&rst SDMMC_OCP_RESET>;  }; @@
-76,11 +80,10 @@  };
 
 &sdr {
-       compatible = "intel,sdr-ctl-agilex";
-       reg = <0xf8000400 0x80>,
-             <0xf8010000 0x190>,
-             <0xf8011000 0x500>;
+       compatible = "intel,sdr-ctl-n5x";
        resets = <&rst DDRSCH_RESET>;
+       clocks = <&memclkmgr>;
+       clock-names = "mem_clk";
        u-boot,dm-pre-reloc;
 };
arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi new file +21 -0
new file mode 100644
index 0000000000..57509f083e
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * U-Boot additions
+ *
+ * Copyright (C) 2020-2021 Intel Corporation <www.intel.com>  */
+
+#include "socfpga_n5x-u-boot.dtsi"
+
+/{
+       aliases {
+               spi0 = &qspi;
+               i2c0 = &i2c1;
+       };
+
+       memory {
+               /*
+                * Memory type: DDR4
+                * 16GB
+                *     <0 0x00000000 0 0x80000000>,
+                *     <4 0x80000000 3 0x80000000>;
+                *
Quoted 8 lines

arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi line 29

Quoted 7 lines
arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi new file +7 -0
+                * 8GB
+                *     <0 0x00000000 0 0x80000000>,
+                *     <2 0x80000000 1 0x80000000>;
+                *
+                * 4GB
+                *     <0 0x00000000 0 0x80000000>,
+                *     <1 0x80000000 0 0x80000000>;

These example ranges only work for interleaving mode? If yes, add the

comment.

Quoted 4 lines

arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi

Quoted 4 lines
arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi new file +3 -0
+                *
+                * Memory type: LPDDR4 (non-interleaving mode)
+                * Total memory size 3GB, usable = 2.5GB, 0.5GB trade off for

secure

Quoted 58 lines

arch/arm/dts/socfpga_n5x_socdk.dts

Quoted 43 lines
arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi new file +35 -0
+                * region.
+                */
+               reg = <0 0x00000000 0 0x60000000>,
+                         <0x10 0x00100000 0 0x40000000>;
+       };
+};
+
+&flash0 {
+       compatible = "jedec,spi-nor";
+       spi-tx-bus-width = <4>;
+       spi-rx-bus-width = <4>;
+       u-boot,dm-pre-reloc;
+};
+
+&i2c1 {
+       status = "okay";
+};
+
+&nand {
+       u-boot,dm-pre-reloc;
+};
+
+&mmc {
+       drvsel = <3>;
+       smplsel = <0>;
+       u-boot,dm-pre-reloc;
+};
+
+&qspi {
+       status = "okay";
+};
+
+&watchdog0 {
+       u-boot,dm-pre-reloc;
+};
arch/arm/dts/socfpga_n5x_socdk.dts renamed from arch/arm/dts/socfpga_agilex_socdk.dts +0 -0
similarity index 57%
copy from arch/arm/dts/socfpga_agilex_socdk.dts
copy to arch/arm/dts/socfpga_n5x_socdk.dts
index bcdeecc0e0..30130bb910 100644

This file sync from Linux dts?

Quoted 13 lines
arch/arm/dts/socfpga_n5x_socdk.dts renamed from arch/arm/dts/socfpga_agilex_socdk.dts +3 -2
@@ -1,11 +1,12 @@
 // SPDX-License-Identifier:     GPL-2.0
 /*
- * Copyright (C) 2019, Intel Corporation
+ * Copyright (C) 2020-2021, Intel Corporation
  */
 #include "socfpga_agilex.dtsi"
+#include <dt-bindings/clock/n5x-clock.h>
 
 / {
-       model = "SoCFPGA Agilex SoCDK";
+       model = "eASIC N5X SoCDK";
 
Quoted 8 lines
Quoted 7 lines

arch/arm/dts/socfpga_n5x_socdk.dts line 20

Quoted 7 lines
arch/arm/dts/socfpga_n5x_socdk.dts renamed from arch/arm/dts/socfpga_agilex_socdk.dts +1 -0
        aliases {
                serial0 = &uart0;
@@ -16,6 +17,7 @@
 
        chosen {
                stdout-path = "serial0:115200n8";
+               u-boot,boot0 = <&mmc>;

Unused parameter, " u-boot,boot0" should be removed.

Noted.

Quoted 3 lines

Regards
Ley Foon

#31 lore raw

RE: [v2 15/17] arm: dts: Add base dtsi and devkit dts for Intel N5X device

In reply to Ley Foon Tan
Quoted 123 lines

-----Original Message-----
From: Ley Foon Tan <[email protected]>
Sent: Friday, May 28, 2021 4:34 PM
To: Lim, Elly Siew Chin <[email protected]>
Cc: ZY - u-boot <[email protected]>; Marek Vasut <[email protected]>; Simon Goldschmidt <[email protected]>; Chee, Tien Fong <[email protected]>; Westergreen, Dalon <[email protected]>; Simon Glass <[email protected]>; Gan, Yau Wai <[email protected]>; LeyFoon Tan <[email protected]>
Subject: Re: [v2 15/17] arm: dts: Add base dtsi and devkit dts for Intel N5X device

arch/arm/dts/Makefile dtb-$(CONFIG_ARCH_SOCFPGA) +=

Quoted 28 lines · Siew Chin Lim

Add device tree for N5X.

---
v2:
- Remove socfpga_n5x.dtsi
- Reuse socfpga_agilex.dtsi in socfpga_n5x_socdk.dts and update n5x data accordingly.

---
 arch/arm/dts/Makefile                         |   1 +
 ...ex-u-boot.dtsi => socfpga_n5x-u-boot.dtsi} |  13 ++-
 arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi    |  67 +++++++++++
 ...agilex_socdk.dts => socfpga_n5x_socdk.dts} | 110
+++++++++++++++++-
 4 files changed, 182 insertions(+), 9 deletions(-)  copy
arch/arm/dts/{socfpga_agilex-u-boot.dtsi => socfpga_n5x-u-boot.dtsi}
(85%)  create mode 100644 arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi
 copy arch/arm/dts/{socfpga_agilex_socdk.dts => socfpga_n5x_socdk.dts}

(57%)

arch/arm/dts/Makefile index renamed from arch/arm/dts/Makefile +0 -0

aec5020a0f..2e13277816 100644

arch/arm/dts/Makefile +0 -0
@@ -381,6 +381,7 @@ dtb-$(CONFIG_ARCH_SOCFPGA) +=

\

arch/arm/dts/Makefile dtb-$(CONFIG_ARCH_SOCFPGA) += \ · line 387

Quoted 7 lines
arch/arm/dts/Makefile +1 -0
        socfpga_cyclone5_socrates.dtb                   \
        socfpga_cyclone5_sr1500.dtb                     \
        socfpga_cyclone5_vining_fpga.dtb                \
+       socfpga_n5x_socdk.dtb                           \
        socfpga_stratix10_socdk.dtb
 
 dtb-$(CONFIG_TARGET_DRA7XX_EVM) += dra72-evm.dtb dra7-evm.dtb  \

diff

Quoted 70 lines

--git a/arch/arm/dts/socfpga_agilex-u-boot.dtsi
b/arch/arm/dts/socfpga_n5x-u-boot.dtsi
similarity index 85%
copy from arch/arm/dts/socfpga_agilex-u-boot.dtsi
copy to arch/arm/dts/socfpga_n5x-u-boot.dtsi
index 08f7cf7f7a..2f63f4a4e6 100644

arch/arm/dts/socfpga_n5x-u-boot.dtsi renamed from arch/arm/dts/socfpga_agilex-u-boot.dtsi +8 -6
@@ -2,7 +2,7 @@
 /*
  * U-Boot additions
  *
- * Copyright (C) 2019-2020 Intel Corporation <www.intel.com>
+ * Copyright (C) 2020-2021 Intel Corporation <www.intel.com>
  */
 
 #include "socfpga_soc64_fit-u-boot.dtsi"
@@ -53,6 +53,10 @@
        reset-names = "i2c";
 };
 
+&memclkmgr {
+       u-boot,dm-pre-reloc;
+};
+
 &mmc {
        resets = <&rst SDMMC_RESET>, <&rst SDMMC_OCP_RESET>;  }; @@
-76,11 +80,10 @@  };
 
 &sdr {
-       compatible = "intel,sdr-ctl-agilex";
-       reg = <0xf8000400 0x80>,
-             <0xf8010000 0x190>,
-             <0xf8011000 0x500>;
+       compatible = "intel,sdr-ctl-n5x";
        resets = <&rst DDRSCH_RESET>;
+       clocks = <&memclkmgr>;
+       clock-names = "mem_clk";
        u-boot,dm-pre-reloc;
 };
arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi new file +22 -0
new file mode 100644
index 0000000000..57509f083e
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * U-Boot additions
+ *
+ * Copyright (C) 2020-2021 Intel Corporation <www.intel.com>  */
+
+#include "socfpga_n5x-u-boot.dtsi"
+
+/{
+       aliases {
+               spi0 = &qspi;
+               i2c0 = &i2c1;
+       };
+
+       memory {
+               /*
+                * Memory type: DDR4
+                * 16GB
+                *     <0 0x00000000 0 0x80000000>,
+                *     <4 0x80000000 3 0x80000000>;
+                *
+                * 8GB
Quoted 9 lines

arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi line 29

Quoted 6 lines
arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi new file +6 -0
+                *     <0 0x00000000 0 0x80000000>,
+                *     <2 0x80000000 1 0x80000000>;
+                *
+                * 4GB
+                *     <0 0x00000000 0 0x80000000>,
+                *     <1 0x80000000 0 0x80000000>;

These example ranges only work for interleaving mode? If yes, add the comment.

Noted

Quoted 40 lines

arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi

Quoted 3 lines
arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi new file +3 -0
+                *
+                * Memory type: LPDDR4 (non-interleaving mode)
+                * Total memory size 3GB, usable = 2.5GB, 0.5GB trade off for

secure

Quoted 36 lines
arch/arm/dts/socfpga_n5x_socdk-u-boot.dtsi new file +35 -0
+                * region.
+                */
+               reg = <0 0x00000000 0 0x60000000>,
+                         <0x10 0x00100000 0 0x40000000>;
+       };
+};
+
+&flash0 {
+       compatible = "jedec,spi-nor";
+       spi-tx-bus-width = <4>;
+       spi-rx-bus-width = <4>;
+       u-boot,dm-pre-reloc;
+};
+
+&i2c1 {
+       status = "okay";
+};
+
+&nand {
+       u-boot,dm-pre-reloc;
+};
+
+&mmc {
+       drvsel = <3>;
+       smplsel = <0>;
+       u-boot,dm-pre-reloc;
+};
+
+&qspi {
+       status = "okay";
+};
+
+&watchdog0 {
+       u-boot,dm-pre-reloc;
+};
(quoted diff) +0 -0
Quoted 8 lines

arch/arm/dts/socfpga_n5x_socdk.dts

Quoted 7 lines

b/arch/arm/dts/socfpga_n5x_socdk.dts
similarity index 57%
copy from arch/arm/dts/socfpga_agilex_socdk.dts
copy to arch/arm/dts/socfpga_n5x_socdk.dts
index bcdeecc0e0..30130bb910 100644

arch/arm/dts/socfpga_n5x_socdk.dts renamed from arch/arm/dts/socfpga_agilex_socdk.dts +0 -0

This file sync from Linux dts?

I have compared with Linux dts and implemented in similar way, it is not directly copied from Linux. The clock ID is not the same in Linux.

Quoted 34 lines
Quoted 34 lines
arch/arm/dts/socfpga_n5x_socdk.dts renamed from arch/arm/dts/socfpga_agilex_socdk.dts +10 -2
@@ -1,11 +1,12 @@
 // SPDX-License-Identifier:     GPL-2.0
 /*
- * Copyright (C) 2019, Intel Corporation
+ * Copyright (C) 2020-2021, Intel Corporation
  */
 #include "socfpga_agilex.dtsi"
+#include <dt-bindings/clock/n5x-clock.h>
 
 / {
-       model = "SoCFPGA Agilex SoCDK";
+       model = "eASIC N5X SoCDK";
 
        aliases {
                serial0 = &uart0;
@@ -16,6 +17,7 @@
 
        chosen {
                stdout-path = "serial0:115200n8";
+               u-boot,boot0 = <&mmc>;
        };
 
        leds {
@@ -47,10 +49,26 @@
                        osc1 {
                                clock-frequency = <25000000>;
                        };
+
+                       dram_eosc_clk: dram-eosc-clk {
+                               #clock-cells = <0>;
+                               compatible = "fixed-clock";
+                       };
+               };
Quoted 9 lines

arch/arm/dts/socfpga_n5x_socdk.dts line 63

Quoted 6 lines
arch/arm/dts/socfpga_n5x_socdk.dts renamed from arch/arm/dts/socfpga_agilex_socdk.dts +6 -0
+
+               memclkmgr: mem-clock-controller@f8040000 {
+                       compatible = "intel,n5x-mem-clkmgr";
+                       reg = <0xf8040000 0x1000>;
+                       #clock-cells = <0>;
+                       clocks = <&dram_eosc_clk>, <&f2s_free_clk>;

All these should use for all N5X devices, right? Then these should move to socfpga_n5x-u-boot.dtsi.

Noted

Quoted 8 lines

arch/arm/dts/socfpga_n5x_socdk.dts

Quoted 6 lines
arch/arm/dts/socfpga_n5x_socdk.dts renamed from arch/arm/dts/socfpga_agilex_socdk.dts +2 -0
                };
        };
 };
 
+&clkmgr {
+       compatible = "intel,n5x-clkmgr"; };

Same here and all the clocks parameters below.

Do you mean move to socfpga_n5x-u-boot.dtsi?

Quoted 119 lines
Quoted 119 lines
arch/arm/dts/socfpga_n5x_socdk.dts renamed from arch/arm/dts/socfpga_agilex_socdk.dts +68 -3
+
 &gpio1 {
        status = "okay";
 };
@@ -59,8 +77,8 @@
        status = "okay";
        phy-mode = "rgmii";
        phy-handle = <&phy0>;
-
        max-frame-size = <9000>;
+       clocks = <&clkmgr N5X_EMAC0_CLK>;
 
        mdio0 {
                #address-cells = <1>;
@@ -85,27 +103,111 @@
        };
 };
 
+&gmac1 {
+       clocks = <&clkmgr N5X_EMAC1_CLK>; };
+
+&gmac2 {
+       clocks = <&clkmgr N5X_EMAC2_CLK>; };
+
+&i2c0 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>; };
+
+&i2c1 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>; };
+
+&i2c2 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>; };
+
+&i2c3 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>; };
+
+&i2c4 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>; };
+
 &mmc {
        status = "okay";
        cap-sd-highspeed;
        broken-cd;
        bus-width = <4>;
+
+       clocks = <&clkmgr N5X_L4_MP_CLK>,
+                <&clkmgr N5X_SDMMC_CLK>; };
+
+&pdma {
+       clocks = <&clkmgr N5X_L4_MAIN_CLK>; };
+
+&spi0 {
+       clocks = <&clkmgr N5X_L4_MAIN_CLK>; };
+
+&spi1 {
+       clocks = <&clkmgr N5X_L4_MAIN_CLK>; };
+
+&timer0 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>; };
+
+&timer1 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>; };
+
+&timer2 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>; };
+
+&timer3 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>;
 };
 
 &uart0 {
        status = "okay";
+       clocks = <&clkmgr N5X_L4_SP_CLK>; };
+
+&uart1 {
+       clocks = <&clkmgr N5X_L4_SP_CLK>;
 };
 
 &usb0 {
        status = "okay";
+       clocks = <&clkmgr N5X_USB_CLK>;
        disable-over-current;
 };
 
+&usb1 {
+       status = "okay";
+       clocks = <&clkmgr N5X_USB_CLK>; };
+
 &watchdog0 {
        status = "okay";
+       clocks = <&clkmgr N5X_L4_SYS_FREE_CLK>; };
+
+&watchdog1 {
+       clocks = <&clkmgr N5X_L4_SYS_FREE_CLK>; };
+
+&watchdog2 {
+       clocks = <&clkmgr N5X_L4_SYS_FREE_CLK>; };
+
+&watchdog3 {
+       clocks = <&clkmgr N5X_L4_SYS_FREE_CLK>;
 };
 
 &qspi {
+       status = "okay";
        flash0: flash@0 {
                #address-cells = <1>;
                #size-cells = <1>;
@@ -116,7 +218,7 @@
                m25p,fast-read;
                cdns,page-size = <256>;
                cdns,block-size = <16>;
-               cdns,read-delay = <1>;
+               cdns,read-delay = <3>;
                cdns,tshsl-ns = <50>;
                cdns,tsd2d-ns = <50>;
                cdns,tchsh-ns = <4>;
--

2.19.0

#32 lore raw

PATCH v2 16/17 include: configs: Add Intel N5X device CONFIGs

In reply to Siew Chin Lim

Add CONFIGs for N5X.

---
 include/configs/socfpga_n5x_socdk.h | 45 +++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 include/configs/socfpga_n5x_socdk.h
include/configs/socfpga_n5x_socdk.h new file +45 -0
new file mode 100644
index 0000000000..c295e91e3d
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2020-2021 Intel Corporation <www.intel.com>
+ *
+ */
+
+#ifndef __CONFIG_SOCFGPA_N5X_H__
+#define __CONFIG_SOCFGPA_N5X_H__
+
+#include <configs/socfpga_soc64_common.h>
+
+#undef CONFIG_EXTRA_ENV_SETTINGS
+#define CONFIG_EXTRA_ENV_SETTINGS \
+	"loadaddr=" __stringify(CONFIG_SYS_LOAD_ADDR) "\0" \
+	"bootfile=" CONFIG_BOOTFILE "\0" \
+	"fdt_addr=1100000\0" \
+	"fdtimage=" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0" \
+	"mmcroot=/dev/mmcblk0p2\0" \
+	"mmcboot=setenv bootargs " CONFIG_BOOTARGS \
+		" root=${mmcroot} rw rootwait;" \
+		"booti ${loadaddr} - ${fdt_addr}\0" \
+	"mmcload=mmc rescan;" \
+		"load mmc 0:1 ${loadaddr} ${bootfile};" \
+		"load mmc 0:1 ${fdt_addr} ${fdtimage}\0" \
+	"mmcfitboot=setenv bootargs " CONFIG_BOOTARGS \
+		" root=${mmcroot} rw rootwait;" \
+		"bootm ${loadaddr}\0" \
+	"mmcfitload=mmc rescan;" \
+		"load mmc 0:1 ${loadaddr} ${bootfile}\0" \
+	"ramboot=setenv bootargs " CONFIG_BOOTARGS";" \
+		"booti ${loadaddr} - ${fdt_addr}\0" \
+	"linux_qspi_enable=if sf probe; then " \
+		"echo Enabling QSPI at Linux DTB...;" \
+		"fdt addr ${fdt_addr}; fdt resize;" \
+		"fdt set /soc/spi at ff8d2000 status okay;" \
+		"if fdt set /soc/clocks/qspi-clk clock-frequency" \
+		" ${qspi_clock}; then" \
+		" else fdt set /soc/clkmgr/clocks/qspi_clk clock-frequency" \
+		" ${qspi_clock}; fi; fi\0" \
+	"scriptaddr=0x02100000\0" \
+	"scriptfile=u-boot.scr\0" \
+	"fatscript=if fatload mmc 0:1 ${scriptaddr} ${scriptfile};" \
+		   "then source ${scriptaddr}; fi\0"
+
+#endif	/* __CONFIG_SOCFGPA_N5X_H__ */
Signature · 1 line
2.19.0
#33 lore raw

PATCH v2 17/17 arm: socfpga: Enable Intel N5X device build

In reply to Siew Chin Lim

Add defconfig for N5X to support legacy, ATF and VAB boot flow.

---
v2:
- Move linux_qspi_enable from bootcommand

---
 arch/arm/mach-socfpga/Kconfig                 | 21 +++++++++++++-
 arch/arm/mach-socfpga/Makefile                | 28 +++++++++++++++----
 ...ab_defconfig => socfpga_n5x_atf_defconfig} | 12 ++++----
 ...agilex_defconfig => socfpga_n5x_defconfig} | 14 ++++------
 ...ab_defconfig => socfpga_n5x_vab_defconfig} | 11 ++++----
 5 files changed, 61 insertions(+), 25 deletions(-)
 copy configs/{socfpga_agilex_vab_defconfig => socfpga_n5x_atf_defconfig} (87%)
 copy configs/{socfpga_agilex_defconfig => socfpga_n5x_defconfig} (82%)
 copy configs/{socfpga_agilex_vab_defconfig => socfpga_n5x_vab_defconfig} (87%)
arch/arm/mach-socfpga/Kconfig +20 -1
index 0c35406232..a4d733c756 100644
@@ -8,7 +8,7 @@ config NR_DRAM_BANKS
 
 config SOCFPGA_SECURE_VAB_AUTH
 	bool "Enable boot image authentication with Secure Device Manager"
-	depends on TARGET_SOCFPGA_AGILEX
+	depends on TARGET_SOCFPGA_AGILEX || TARGET_SOCFPGA_N5X
 	select FIT_IMAGE_POST_PROCESS
 	select SHA384
 	select SHA512_ALGO
@@ -91,6 +91,22 @@ config TARGET_SOCFPGA_GEN5
 	imply SPL_SYS_MALLOC_SIMPLE
 	imply SPL_USE_TINY_PRINTF
 
+config TARGET_SOCFPGA_N5X
+	bool
+	select ARMV8_MULTIENTRY
+	select ARMV8_SET_SMPEN
+	select BINMAN if SPL_ATF
+	select CLK
+	select FPGA_INTEL_SDM_MAILBOX
+	select NCORE_CACHE
+	select SPL_ALTERA_SDRAM
+	select SPL_CLK if SPL
+	select TARGET_SOCFPGA_SOC64
+
+config TARGET_SOCFPGA_N5X_SOCDK
+	bool "Intel eASIC SoCDK (N5X)"
+	select TARGET_SOCFPGA_N5X
+
 config TARGET_SOCFPGA_SOC64
 	bool
 
@@ -183,6 +199,7 @@ config SYS_BOARD
 	default "de0-nano-soc" if TARGET_SOCFPGA_TERASIC_DE0_NANO
 	default "de1-soc" if TARGET_SOCFPGA_TERASIC_DE1_SOC
 	default "de10-nano" if TARGET_SOCFPGA_TERASIC_DE10_NANO
+	default "n5x-socdk" if TARGET_SOCFPGA_N5X_SOCDK
 	default "is1" if TARGET_SOCFPGA_IS1
 	default "mcvevk" if TARGET_SOCFPGA_ARIES_MCVEVK
 	default "secu1" if TARGET_SOCFPGA_ARRIA5_SECU1
@@ -194,6 +211,7 @@ config SYS_BOARD
 
 config SYS_VENDOR
 	default "intel" if TARGET_SOCFPGA_AGILEX_SOCDK
+	default "intel" if TARGET_SOCFPGA_N5X_SOCDK
 	default "altera" if TARGET_SOCFPGA_ARRIA5_SOCDK
 	default "altera" if TARGET_SOCFPGA_ARRIA10_SOCDK
 	default "altera" if TARGET_SOCFPGA_CYCLONE5_SOCDK
@@ -221,6 +239,7 @@ config SYS_CONFIG_NAME
 	default "socfpga_de0_nano_soc" if TARGET_SOCFPGA_TERASIC_DE0_NANO
 	default "socfpga_de1_soc" if TARGET_SOCFPGA_TERASIC_DE1_SOC
 	default "socfpga_de10_nano" if TARGET_SOCFPGA_TERASIC_DE10_NANO
+	default "socfpga_n5x_socdk" if TARGET_SOCFPGA_N5X_SOCDK
 	default "socfpga_is1" if TARGET_SOCFPGA_IS1
 	default "socfpga_mcvevk" if TARGET_SOCFPGA_ARIES_MCVEVK
 	default "socfpga_sockit" if TARGET_SOCFPGA_TERASIC_SOCKIT
arch/arm/mach-socfpga/Makefile +23 -5
index 58afde950f..ec38b64dd4 100644
@@ -4,7 +4,7 @@
 # Wolfgang Denk, DENX Software Engineering, wd at denx.de.
 #
 # Copyright (C) 2012-2017 Altera Corporation <www.altera.com>
-# Copyright (C) 2017-2020 Intel Corporation <www.intel.com>
+# Copyright (C) 2017-2021 Intel Corporation <www.intel.com>
 
 obj-y	+= board.o
 obj-y	+= clock_manager.o
@@ -56,6 +56,21 @@ obj-y	+= wrap_handoff_soc64.o
 obj-y	+= wrap_pll_config_soc64.o
 endif
 
+ifdef CONFIG_TARGET_SOCFPGA_N5X
+obj-y	+= clock_manager_n5x.o
+obj-y	+= lowlevel_init_soc64.o
+obj-y	+= mailbox_s10.o
+obj-y	+= misc_soc64.o
+obj-y	+= mmu-arm64_s10.o
+obj-y	+= reset_manager_s10.o
+obj-$(CONFIG_SOCFPGA_SECURE_VAB_AUTH)	+= secure_vab.o
+obj-y	+= system_manager_soc64.o
+obj-y	+= timer_s10.o
+obj-$(CONFIG_SOCFPGA_SECURE_VAB_AUTH)	+= vab.o
+obj-y	+= wrap_handoff_soc64.o
+obj-y	+= wrap_pll_config_soc64.o
+endif
+
 ifdef CONFIG_SPL_BUILD
 ifdef CONFIG_TARGET_SOCFPGA_GEN5
 obj-y	+= spl_gen5.o
@@ -64,18 +79,21 @@ obj-y	+= wrap_iocsr_config.o
 obj-y	+= wrap_pinmux_config.o
 obj-y	+= wrap_sdram_config.o
 endif
+ifdef CONFIG_TARGET_SOCFPGA_SOC64
+obj-y	+= firewall.o
+obj-y	+= spl_soc64.o
+endif
 ifdef CONFIG_TARGET_SOCFPGA_ARRIA10
 obj-y	+= spl_a10.o
 endif
 ifdef CONFIG_TARGET_SOCFPGA_STRATIX10
-obj-y	+= firewall.o
 obj-y	+= spl_s10.o
-obj-y	+= spl_soc64.o
 endif
 ifdef CONFIG_TARGET_SOCFPGA_AGILEX
-obj-y	+= firewall.o
 obj-y	+= spl_agilex.o
-obj-y	+= spl_soc64.o
+endif
+ifdef CONFIG_TARGET_SOCFPGA_N5X
+obj-y	+= spl_n5x.o
 endif
 else
 obj-$(CONFIG_SPL_ATF) += secure_reg_helper.o
configs/socfpga_n5x_atf_defconfig renamed from configs/socfpga_agilex_vab_defconfig +6 -6
similarity index 87%
copy from configs/socfpga_agilex_vab_defconfig
copy to configs/socfpga_n5x_atf_defconfig
index d575dadcfb..384e065c76 100644
@@ -9,11 +9,10 @@ CONFIG_ENV_OFFSET=0x200
 CONFIG_SYS_SPI_U_BOOT_OFFS=0x02000000
 CONFIG_DM_GPIO=y
 CONFIG_SPL_TEXT_BASE=0xFFE00000
-CONFIG_SOCFPGA_SECURE_VAB_AUTH=y
-CONFIG_TARGET_SOCFPGA_AGILEX_SOCDK=y
-CONFIG_IDENT_STRING="socfpga_agilex"
+CONFIG_TARGET_SOCFPGA_N5X_SOCDK=y
+CONFIG_IDENT_STRING="socfpga_n5x"
 CONFIG_SPL_FS_FAT=y
-CONFIG_DEFAULT_DEVICE_TREE="socfpga_agilex_socdk"
+CONFIG_DEFAULT_DEVICE_TREE="socfpga_n5x_socdk"
 CONFIG_FIT=y
 CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
@@ -21,7 +20,7 @@ CONFIG_SPL_LOAD_FIT_ADDRESS=0x02000000
 # CONFIG_USE_SPL_FIT_GENERATOR is not set
 CONFIG_BOOTDELAY=5
 CONFIG_USE_BOOTARGS=y
-CONFIG_BOOTARGS="earlycon"
+CONFIG_BOOTARGS="earlycon panic=-1 earlyprintk=ttyS0,115200"
 CONFIG_USE_BOOTCOMMAND=y
 CONFIG_BOOTCOMMAND="run fatscript; run mmcfitload; run mmcfitboot"
 CONFIG_SPL_CRC32_SUPPORT=y
@@ -30,7 +29,7 @@ CONFIG_SPL_SPI_LOAD=y
 CONFIG_SPL_ATF=y
 CONFIG_SPL_ATF_NO_PLATFORM_PARAM=y
 CONFIG_HUSH_PARSER=y
-CONFIG_SYS_PROMPT="SOCFPGA_AGILEX # "
+CONFIG_SYS_PROMPT="SOCFPGA_N5X # "
 CONFIG_CMD_MEMTEST=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_I2C=y
@@ -44,6 +43,7 @@ CONFIG_CMD_CACHE=y
 CONFIG_CMD_EXT4=y
 CONFIG_CMD_FAT=y
 CONFIG_CMD_FS_GENERIC=y
+CONFIG_CMD_WDT=y
 CONFIG_ENV_IS_IN_MMC=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_SPL_DM_SEQ_ALIAS=y
configs/socfpga_n5x_defconfig renamed from configs/socfpga_agilex_defconfig +6 -8
similarity index 82%
copy from configs/socfpga_agilex_defconfig
copy to configs/socfpga_n5x_defconfig
index 3d5d39fe0f..0ce9231b21 100644
@@ -3,27 +3,25 @@ CONFIG_ARCH_SOCFPGA=y
 CONFIG_SYS_TEXT_BASE=0x1000
 CONFIG_SYS_MALLOC_F_LEN=0x2000
 CONFIG_NR_DRAM_BANKS=2
-CONFIG_SYS_MEMTEST_START=0x00000000
-CONFIG_SYS_MEMTEST_END=0x3fe00000
 CONFIG_ENV_SIZE=0x1000
 CONFIG_ENV_OFFSET=0x200
 CONFIG_SYS_SPI_U_BOOT_OFFS=0x3c00000
 CONFIG_DM_GPIO=y
 CONFIG_SPL_TEXT_BASE=0xFFE00000
-CONFIG_TARGET_SOCFPGA_AGILEX_SOCDK=y
-CONFIG_IDENT_STRING="socfpga_agilex"
+CONFIG_TARGET_SOCFPGA_N5X_SOCDK=y
+CONFIG_IDENT_STRING="socfpga_n5x"
 CONFIG_SPL_FS_FAT=y
 # CONFIG_PSCI_RESET is not set
-CONFIG_DEFAULT_DEVICE_TREE="socfpga_agilex_socdk"
+CONFIG_DEFAULT_DEVICE_TREE="socfpga_n5x_socdk"
 CONFIG_BOOTDELAY=5
 CONFIG_USE_BOOTARGS=y
-CONFIG_BOOTARGS="earlycon"
+CONFIG_BOOTARGS="earlycon panic=-1 earlyprintk=ttyS0,115200"
 CONFIG_USE_BOOTCOMMAND=y
 CONFIG_BOOTCOMMAND="run fatscript; run mmcload; run linux_qspi_enable; run mmcboot"
 CONFIG_SPL_CACHE=y
 CONFIG_SPL_SPI_LOAD=y
 CONFIG_HUSH_PARSER=y
-CONFIG_SYS_PROMPT="SOCFPGA_AGILEX # "
+CONFIG_SYS_PROMPT="SOCFPGA_N5X # "
 CONFIG_CMD_MEMTEST=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_I2C=y
@@ -37,10 +35,10 @@ CONFIG_CMD_CACHE=y
 CONFIG_CMD_EXT4=y
 CONFIG_CMD_FAT=y
 CONFIG_CMD_FS_GENERIC=y
+CONFIG_CMD_WDT=y
 CONFIG_ENV_IS_IN_MMC=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_SPL_DM_SEQ_ALIAS=y
-CONFIG_SPL_ALTERA_SDRAM=y
 CONFIG_DWAPB_GPIO=y
 CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_DW=y
configs/socfpga_n5x_vab_defconfig renamed from configs/socfpga_agilex_vab_defconfig +6 -5
similarity index 87%
copy from configs/socfpga_agilex_vab_defconfig
copy to configs/socfpga_n5x_vab_defconfig
index d575dadcfb..6c641fcf87 100644
@@ -10,10 +10,10 @@ CONFIG_SYS_SPI_U_BOOT_OFFS=0x02000000
 CONFIG_DM_GPIO=y
 CONFIG_SPL_TEXT_BASE=0xFFE00000
 CONFIG_SOCFPGA_SECURE_VAB_AUTH=y
-CONFIG_TARGET_SOCFPGA_AGILEX_SOCDK=y
-CONFIG_IDENT_STRING="socfpga_agilex"
+CONFIG_TARGET_SOCFPGA_N5X_SOCDK=y
+CONFIG_IDENT_STRING="socfpga_n5x"
 CONFIG_SPL_FS_FAT=y
-CONFIG_DEFAULT_DEVICE_TREE="socfpga_agilex_socdk"
+CONFIG_DEFAULT_DEVICE_TREE="socfpga_n5x_socdk"
 CONFIG_FIT=y
 CONFIG_SPL_FIT_SIGNATURE=y
 CONFIG_SPL_LOAD_FIT=y
@@ -21,7 +21,7 @@ CONFIG_SPL_LOAD_FIT_ADDRESS=0x02000000
 # CONFIG_USE_SPL_FIT_GENERATOR is not set
 CONFIG_BOOTDELAY=5
 CONFIG_USE_BOOTARGS=y
-CONFIG_BOOTARGS="earlycon"
+CONFIG_BOOTARGS="earlycon panic=-1 earlyprintk=ttyS0,115200"
 CONFIG_USE_BOOTCOMMAND=y
 CONFIG_BOOTCOMMAND="run fatscript; run mmcfitload; run mmcfitboot"
 CONFIG_SPL_CRC32_SUPPORT=y
@@ -30,7 +30,7 @@ CONFIG_SPL_SPI_LOAD=y
 CONFIG_SPL_ATF=y
 CONFIG_SPL_ATF_NO_PLATFORM_PARAM=y
 CONFIG_HUSH_PARSER=y
-CONFIG_SYS_PROMPT="SOCFPGA_AGILEX # "
+CONFIG_SYS_PROMPT="SOCFPGA_N5X # "
 CONFIG_CMD_MEMTEST=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_I2C=y
@@ -44,6 +44,7 @@ CONFIG_CMD_CACHE=y
 CONFIG_CMD_EXT4=y
 CONFIG_CMD_FAT=y
 CONFIG_CMD_FS_GENERIC=y
+CONFIG_CMD_WDT=y
 CONFIG_ENV_IS_IN_MMC=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_SPL_DM_SEQ_ALIAS=y
Signature · 1 line
2.19.0
Reviewed-by on v2 17/17
#34 lore raw

Re: [v2 17/17] arm: socfpga: Enable Intel N5X device build

Quoted 8 lines · Siew Chin Lim

Add defconfig for N5X to support legacy, ATF and VAB boot flow.

---
v2:
- Move linux_qspi_enable from bootcommand

Quoted 11 lines
---
 arch/arm/mach-socfpga/Kconfig                 | 21 +++++++++++++-
 arch/arm/mach-socfpga/Makefile                | 28 +++++++++++++++----
 ...ab_defconfig => socfpga_n5x_atf_defconfig} | 12 ++++----
 ...agilex_defconfig => socfpga_n5x_defconfig} | 14 ++++------
 ...ab_defconfig => socfpga_n5x_vab_defconfig} | 11 ++++----
 5 files changed, 61 insertions(+), 25 deletions(-)
 copy configs/{socfpga_agilex_vab_defconfig => socfpga_n5x_atf_defconfig} (87%)
 copy configs/{socfpga_agilex_defconfig => socfpga_n5x_defconfig} (82%)
 copy configs/{socfpga_agilex_vab_defconfig => socfpga_n5x_vab_defconfig} (87%)