Skip to contentSkip to conversation

Add Intel Diamond Mesa SoC support

PATCH RESEND New Siew Chin Lim 2 participants 44 messages Nov 10, 2020 – Nov 23, 2020

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

v2 cover Add Intel Diamond Mesa SoC support

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

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

Patch status:
Have changes: Patch 20, 22
Other patches unchanged.

Detail changelog can find in commit message.

v1->v2:
--------
Patch 20:
- Include binman node device tree object (socfpga_soc64_fit-u-boot.dtsi_ in socfpga_dm-u-boot.dtsi

Patch 22:
- Add "CONFIG_USE_SPL_FIT_GENERATE is not set" to socfpga_dm_atf_defconfig. Use binman to generate FIT image instead of local script.

History:
--------
[v1]: https://patchwork.ozlabs.org/project/uboot/cover/20200922094930.100855-1-elly.siew.chin.lim at intel.com/

These patchsets have dependency on:
--------
Enable ARM Trusted Firmware for U-Boot
https://patchwork.ozlabs.org/project/uboot/cover/20201015122955.10259-1-elly.siew.chin.lim at intel.com/

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

Siew Chin Lim (22):
arm: socfpga: Move Stratix10 and Agilex to use TARGET_SOCFPGA_SOC64
arm: socfpga: dm: Add base address for Intel Diamond Mesa
arm: socfpga: dm: Add firewall support for Agilex and Diamond Mesa
arm: socfpga: Rename Stratix10 and Agilex handoff common macros
arm: socfpga: Changed wrap_pll_config_s10.c to wrap_pll_config_soc64.c
arm: socfpga: Changed system_manager_s10.c to system_manager_soc64.c
arm: socfpga: Rearrange sequence of macros in handoff_soc64.h
arm: socfpga: Restructure Stratix10 and Agilex handoff code
arm: socfpga: Add handoff data support for Diamond Mesa
drivers: clk: dm: Add clock driver for Diamond Mesa
arm: socfpga: dm: Get clock manager base address for Diamond Mesa
drivers: clk: dm: Add memory clock driver for Diamond Mesa
arm: socfpga: Move Stratix10 and Agilex clock manager common code
arm: socfpga: Changed to store QSPI reference clock in kHz
arm: socfpga: dm: Add clock manager for Diamond Mesa
ddr: altera: dm: Add SDRAM driver for Diamond Mesa
arm: socfpga: Move Stratix10 and Agilex SPL common code
arm: socfpga: dm: Add SPL for Diamond Mesa
board: intel: dm: Add socdk board support for Diamond Mesa
arm: dts: dm: Add base dtsi and devkit dts for Diamond Mesa
configs: dm: Add Diamond Mesa CONFIGs
arm: socfpga: dm: Enable Intel Diamond Mesa build

 arch/arm/Kconfig                                   |    6 +-
 arch/arm/dts/Makefile                              |    1 +
 arch/arm/dts/socfpga_dm-u-boot.dtsi                |  102 ++
 arch/arm/dts/socfpga_dm.dtsi                       |  640 ++++++++++
 arch/arm/dts/socfpga_dm_socdk-u-boot.dtsi          |   50 +
 arch/arm/dts/socfpga_dm_socdk.dts                  |  144 +++
 arch/arm/mach-socfpga/Kconfig                      |   24 +
 arch/arm/mach-socfpga/Makefile                     |   33 +-
 arch/arm/mach-socfpga/clock_manager.c              |   11 +
 arch/arm/mach-socfpga/clock_manager_agilex.c       |    6 -
 .../{clock_manager_agilex.c => clock_manager_dm.c} |   32 +-
 arch/arm/mach-socfpga/clock_manager_s10.c          |    8 +-
 arch/arm/mach-socfpga/firewall.c                   |   10 +
 arch/arm/mach-socfpga/include/mach/base_addr_s10.h |    3 +-
 arch/arm/mach-socfpga/include/mach/clock_manager.h |    6 +
 .../mach-socfpga/include/mach/clock_manager_dm.h   |   14 +
 .../mach-socfpga/include/mach/clock_manager_s10.h  |    1 -
 arch/arm/mach-socfpga/include/mach/firewall.h      |    7 +
 arch/arm/mach-socfpga/include/mach/handoff_s10.h   |   39 -
 arch/arm/mach-socfpga/include/mach/handoff_soc64.h |   81 ++
 arch/arm/mach-socfpga/include/mach/reset_manager.h |    3 +-
 .../arm/mach-socfpga/include/mach/system_manager.h |    3 +-
 .../include/mach/system_manager_soc64.h            |   20 +-
 arch/arm/mach-socfpga/mailbox_s10.c                |   28 +-
 arch/arm/mach-socfpga/misc.c                       |    3 +
 arch/arm/mach-socfpga/spl_agilex.c                 |   16 -
 arch/arm/mach-socfpga/{spl_agilex.c => spl_dm.c}   |   37 +-
 arch/arm/mach-socfpga/spl_s10.c                    |   17 -
 arch/arm/mach-socfpga/spl_soc64.c                  |   26 +
 ...system_manager_s10.c => system_manager_soc64.c} |   53 +-
 arch/arm/mach-socfpga/wrap_handoff_soc64.c         |  113 ++
 arch/arm/mach-socfpga/wrap_pinmux_config_s10.c     |   56 -
 ...ap_pll_config_s10.c => wrap_pll_config_soc64.c} |   18 +-
 board/intel/dm-socdk/MAINTAINERS                   |    7 +
 board/intel/dm-socdk/Makefile                      |    7 +
 board/intel/dm-socdk/socfpga.c                     |    7 +
 configs/socfpga_dm_atf_defconfig                   |   76 ++
 configs/socfpga_dm_defconfig                       |   69 ++
 drivers/clk/altera/Makefile                        |    3 +-
 drivers/clk/altera/clk-dm.c                        |  504 ++++++++
 drivers/clk/altera/clk-dm.h                        |  213 ++++
 drivers/clk/altera/clk-mem-dm.c                    |  135 ++
 drivers/clk/altera/clk-mem-dm.h                    |   80 ++
 drivers/ddr/altera/Kconfig                         |    6 +-
 drivers/ddr/altera/Makefile                        |    1 +
 drivers/ddr/altera/sdram_dm.c                      | 1294 ++++++++++++++++++++
 drivers/ddr/altera/sdram_soc64.c                   |    6 +
 drivers/fpga/Kconfig                               |    2 +-
 drivers/sysreset/Kconfig                           |    2 +-
 include/configs/socfpga_dm_socdk.h                 |   46 +
 include/configs/socfpga_soc64_common.h             |    4 +-
 include/dt-bindings/clock/dm-clock.h               |   71 ++
 52 files changed, 3902 insertions(+), 242 deletions(-)
 create mode 100644 arch/arm/dts/socfpga_dm-u-boot.dtsi
 create mode 100644 arch/arm/dts/socfpga_dm.dtsi
 create mode 100644 arch/arm/dts/socfpga_dm_socdk-u-boot.dtsi
 create mode 100644 arch/arm/dts/socfpga_dm_socdk.dts
 copy arch/arm/mach-socfpga/{clock_manager_agilex.c => clock_manager_dm.c} (59%)
 create mode 100644 arch/arm/mach-socfpga/include/mach/clock_manager_dm.h
 delete mode 100644 arch/arm/mach-socfpga/include/mach/handoff_s10.h
 create mode 100644 arch/arm/mach-socfpga/include/mach/handoff_soc64.h
 copy arch/arm/mach-socfpga/{spl_agilex.c => spl_dm.c} (77%)
 create mode 100644 arch/arm/mach-socfpga/spl_soc64.c
 rename arch/arm/mach-socfpga/{system_manager_s10.c => system_manager_soc64.c} (55%)
 create mode 100644 arch/arm/mach-socfpga/wrap_handoff_soc64.c
 delete mode 100644 arch/arm/mach-socfpga/wrap_pinmux_config_s10.c
 rename arch/arm/mach-socfpga/{wrap_pll_config_s10.c => wrap_pll_config_soc64.c} (71%)
 create mode 100644 board/intel/dm-socdk/MAINTAINERS
 create mode 100644 board/intel/dm-socdk/Makefile
 create mode 100644 board/intel/dm-socdk/socfpga.c
 create mode 100644 configs/socfpga_dm_atf_defconfig
 create mode 100644 configs/socfpga_dm_defconfig
 create mode 100644 drivers/clk/altera/clk-dm.c
 create mode 100644 drivers/clk/altera/clk-dm.h
 create mode 100644 drivers/clk/altera/clk-mem-dm.c
 create mode 100644 drivers/clk/altera/clk-mem-dm.h
 create mode 100644 drivers/ddr/altera/sdram_dm.c
 create mode 100644 include/configs/socfpga_dm_socdk.h
 create mode 100644 include/dt-bindings/clock/dm-clock.h
Signature · 1 line
2.13.0
#1 lore raw

PATCH RESEND v2 1/22 arm: socfpga: Move Stratix10 and Agilex to use TARGET_SOCFPGA_SOC64

Create common macro TARGET_SOCFPGA_SOC64 for Stratix10 and Agilex.

---
 arch/arm/Kconfig                                    | 6 +++---
 arch/arm/mach-socfpga/Kconfig                       | 5 +++++
 arch/arm/mach-socfpga/include/mach/reset_manager.h  | 3 +--
 arch/arm/mach-socfpga/include/mach/system_manager.h | 3 +--
 drivers/ddr/altera/Kconfig                          | 6 +++---
 drivers/fpga/Kconfig                                | 2 +-
 drivers/sysreset/Kconfig                            | 2 +-
 7 files changed, 15 insertions(+), 12 deletions(-)
arch/arm/Kconfig +3 -3
index b2f7fcbd6e..663ea07341 100644
@@ -974,7 +974,7 @@ config ARCH_SOCFPGA
 	bool "Altera SOCFPGA family"
 	select ARCH_EARLY_INIT_R
 	select ARCH_MISC_INIT if !TARGET_SOCFPGA_ARRIA10
-	select ARM64 if TARGET_SOCFPGA_STRATIX10 || TARGET_SOCFPGA_AGILEX
+	select ARM64 if TARGET_SOCFPGA_SOC64
 	select CPU_V7A if TARGET_SOCFPGA_GEN5 || TARGET_SOCFPGA_ARRIA10
 	select DM
 	select DM_SERIAL
@@ -986,7 +986,7 @@ config ARCH_SOCFPGA
 	select SPL_LIBGENERIC_SUPPORT
 	select SPL_NAND_SUPPORT if SPL_NAND_DENALI
 	select SPL_OF_CONTROL
-	select SPL_SEPARATE_BSS if TARGET_SOCFPGA_STRATIX10 || TARGET_SOCFPGA_AGILEX
+	select SPL_SEPARATE_BSS if TARGET_SOCFPGA_SOC64
 	select SPL_SERIAL_SUPPORT
 	select SPL_SYSRESET
 	select SPL_WATCHDOG_SUPPORT
@@ -995,7 +995,7 @@ config ARCH_SOCFPGA
 	select SYS_THUMB_BUILD if TARGET_SOCFPGA_GEN5 || TARGET_SOCFPGA_ARRIA10
 	select SYSRESET
 	select SYSRESET_SOCFPGA if TARGET_SOCFPGA_GEN5 || TARGET_SOCFPGA_ARRIA10
-	select SYSRESET_SOCFPGA_SOC64 if TARGET_SOCFPGA_STRATIX10 || TARGET_SOCFPGA_AGILEX
+	select SYSRESET_SOCFPGA_SOC64 if TARGET_SOCFPGA_SOC64
 	imply CMD_DM
 	imply CMD_MTDPARTS
 	imply CRC32_VERIFY
arch/arm/mach-socfpga/Kconfig +5 -0
index 7fdb52dd83..4d061a9d0d 100644
@@ -31,6 +31,7 @@ config SYS_TEXT_BASE
 
 config TARGET_SOCFPGA_AGILEX
 	bool
+	select TARGET_SOCFPGA_SOC64
 	select ARMV8_MULTIENTRY
 	select ARMV8_SET_SMPEN
 	select CLK
@@ -75,8 +76,12 @@ config TARGET_SOCFPGA_GEN5
 	imply SPL_SYS_MALLOC_SIMPLE
 	imply SPL_USE_TINY_PRINTF
 
+config TARGET_SOCFPGA_SOC64
+	bool
+
 config TARGET_SOCFPGA_STRATIX10
 	bool
+	select TARGET_SOCFPGA_SOC64
 	select ARMV8_MULTIENTRY
 	select ARMV8_SET_SMPEN
 	select FPGA_INTEL_SDM_MAILBOX
arch/arm/mach-socfpga/include/mach/reset_manager.h +1 -2
index 7844ad14cb..8c25325e45 100644
@@ -43,8 +43,7 @@ void socfpga_per_reset_all(void);
 #include <asm/arch/reset_manager_gen5.h>
 #elif defined(CONFIG_TARGET_SOCFPGA_ARRIA10)
 #include <asm/arch/reset_manager_arria10.h>
-#elif defined(CONFIG_TARGET_SOCFPGA_STRATIX10) || \
-	defined(CONFIG_TARGET_SOCFPGA_AGILEX)
+#elif defined(CONFIG_TARGET_SOCFPGA_SOC64)
 #include <asm/arch/reset_manager_soc64.h>
 #endif
 
arch/arm/mach-socfpga/include/mach/system_manager.h +1 -2
index f816954717..5603eaa3d0 100644
@@ -8,8 +8,7 @@
 
 phys_addr_t socfpga_get_sysmgr_addr(void);
 
-#if defined(CONFIG_TARGET_SOCFPGA_STRATIX10) || \
-	defined(CONFIG_TARGET_SOCFPGA_AGILEX)
+#if defined(CONFIG_TARGET_SOCFPGA_SOC64)
 #include <asm/arch/system_manager_soc64.h>
 #else
 #define SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGPINMUX	BIT(0)
drivers/ddr/altera/Kconfig +3 -3
index 8f590dc5f6..4660d20def 100644
@@ -1,8 +1,8 @@
 config SPL_ALTERA_SDRAM
 	bool "SoCFPGA DDR SDRAM driver in SPL"
 	depends on SPL
-	depends on TARGET_SOCFPGA_GEN5 || TARGET_SOCFPGA_ARRIA10 || TARGET_SOCFPGA_STRATIX10 || TARGET_SOCFPGA_AGILEX
-	select RAM if TARGET_SOCFPGA_GEN5 || TARGET_SOCFPGA_STRATIX10 || TARGET_SOCFPGA_AGILEX
-	select SPL_RAM if TARGET_SOCFPGA_GEN5 || TARGET_SOCFPGA_STRATIX10 || TARGET_SOCFPGA_AGILEX
+	depends on TARGET_SOCFPGA_GEN5 || TARGET_SOCFPGA_ARRIA10 || TARGET_SOCFPGA_SOC64
+	select RAM if TARGET_SOCFPGA_GEN5 || TARGET_SOCFPGA_SOC64
+	select SPL_RAM if TARGET_SOCFPGA_GEN5 || TARGET_SOCFPGA_SOC64
 	help
 	  Enable DDR SDRAM controller for the SoCFPGA devices.
drivers/fpga/Kconfig +1 -1
index 425b52a926..dc0b3dd31b 100644
@@ -33,7 +33,7 @@ config FPGA_CYCLON2
 
 config FPGA_INTEL_SDM_MAILBOX
 	bool "Enable Intel FPGA Full Reconfiguration SDM Mailbox driver"
-	depends on TARGET_SOCFPGA_STRATIX10 || TARGET_SOCFPGA_AGILEX
+	depends on TARGET_SOCFPGA_SOC64
 	select FPGA_ALTERA
 	help
 	  Say Y here to enable the Intel FPGA Full Reconfig SDM Mailbox driver
drivers/sysreset/Kconfig +1 -1
index 0e5c7c9971..52f874317b 100644
@@ -88,7 +88,7 @@ config SYSRESET_SOCFPGA
 
 config SYSRESET_SOCFPGA_SOC64
 	bool "Enable support for Intel SOCFPGA SoC64 family (Stratix10/Agilex)"
-	depends on ARCH_SOCFPGA && (TARGET_SOCFPGA_STRATIX10 || TARGET_SOCFPGA_AGILEX)
+	depends on ARCH_SOCFPGA && TARGET_SOCFPGA_SOC64
 	help
 	  This enables the system reset driver support for Intel SOCFPGA
 	  SoC64 SoCs.
Signature · 1 line
2.13.0
#2 lore raw

PATCH RESEND v2 1/22 arm: socfpga: Move Stratix10 and Agilex to use TARGET_SOCFPGA_SOC64

Quoted 71 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:44 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 01/22] arm: socfpga: Move Stratix10 and Agilex to use TARGET_SOCFPGA_SOC64

Create common macro TARGET_SOCFPGA_SOC64 for Stratix10 and Agilex.

---
 arch/arm/Kconfig                                    | 6 +++---
 arch/arm/mach-socfpga/Kconfig                       | 5 +++++
 arch/arm/mach-socfpga/include/mach/reset_manager.h  | 3 +--
arch/arm/mach-socfpga/include/mach/system_manager.h | 3 +--
 drivers/ddr/altera/Kconfig                          | 6 +++---
 drivers/fpga/Kconfig                                | 2 +-
 drivers/sysreset/Kconfig                            | 2 +-
 7 files changed, 15 insertions(+), 12 deletions(-)
arch/arm/Kconfig index renamed from arch/arm/Kconfig +0 -0

b2f7fcbd6e..663ea07341 100644

arch/arm/Kconfig +0 -1
@@ -974,7 +974,7 @@ config ARCH_SOCFPGA
 	bool "Altera SOCFPGA family"
 	select ARCH_EARLY_INIT_R
 	select ARCH_MISC_INIT if !TARGET_SOCFPGA_ARRIA10
-	select ARM64 if TARGET_SOCFPGA_STRATIX10 ||

TARGET_SOCFPGA_AGILEX

arch/arm/Kconfig +1 -0
+	select ARM64 if TARGET_SOCFPGA_SOC64
 	select CPU_V7A if TARGET_SOCFPGA_GEN5 ||

TARGET_SOCFPGA_ARRIA10

arch/arm/Kconfig +0 -1
 	select DM
 	select DM_SERIAL
@@ -986,7 +986,7 @@ config ARCH_SOCFPGA
 	select SPL_LIBGENERIC_SUPPORT
 	select SPL_NAND_SUPPORT if SPL_NAND_DENALI
 	select SPL_OF_CONTROL
-	select SPL_SEPARATE_BSS if TARGET_SOCFPGA_STRATIX10 ||

TARGET_SOCFPGA_AGILEX

arch/arm/Kconfig +1 -0
+	select SPL_SEPARATE_BSS if TARGET_SOCFPGA_SOC64
 	select SPL_SERIAL_SUPPORT
 	select SPL_SYSRESET
 	select SPL_WATCHDOG_SUPPORT
@@ -995,7 +995,7 @@ config ARCH_SOCFPGA
 	select SYS_THUMB_BUILD if TARGET_SOCFPGA_GEN5 ||

TARGET_SOCFPGA_ARRIA10

arch/arm/Kconfig +0 -0
 	select SYSRESET
 	select SYSRESET_SOCFPGA if TARGET_SOCFPGA_GEN5 ||

TARGET_SOCFPGA_ARRIA10

arch/arm/Kconfig +0 -1
-	select SYSRESET_SOCFPGA_SOC64 if TARGET_SOCFPGA_STRATIX10

|| TARGET_SOCFPGA_AGILEX

arch/arm/Kconfig +1 -0
+	select SYSRESET_SOCFPGA_SOC64 if TARGET_SOCFPGA_SOC64
 	imply CMD_DM
 	imply CMD_MTDPARTS
 	imply CRC32_VERIFY
arch/arm/mach- renamed from arch/arm/mach-socfpga/Kconfig +0 -0

socfpga/Kconfig index 7fdb52dd83..4d061a9d0d 100644

arch/arm/mach-socfpga/Kconfig config SYS_TEXT_BASE · line 34

Quoted 4 lines
arch/arm/mach-socfpga/Kconfig +1 -0
@@ -31,6 +31,7 @@ config SYS_TEXT_BASE
 
 config TARGET_SOCFPGA_AGILEX
 	bool
+	select TARGET_SOCFPGA_SOC64

Sort by alphabetical order.

arch/arm/mach-socfpga/Kconfig config TARGET_SOCFPGA_GEN5 · line 84

Quoted 13 lines
arch/arm/mach-socfpga/Kconfig +4 -0
 	select ARMV8_MULTIENTRY
 	select ARMV8_SET_SMPEN
 	select CLK
@@ -75,8 +76,12 @@ config TARGET_SOCFPGA_GEN5
 	imply SPL_SYS_MALLOC_SIMPLE
 	imply SPL_USE_TINY_PRINTF
 
+config TARGET_SOCFPGA_SOC64
+	bool
+
 config TARGET_SOCFPGA_STRATIX10
 	bool
+	select TARGET_SOCFPGA_SOC64

Sort by alphabetical order.

arch/arm/mach-socfpga/Kconfig config TARGET_SOCFPGA_GEN5 · line 87

Quoted 3 lines
arch/arm/mach-socfpga/Kconfig +0 -0
 	select ARMV8_MULTIENTRY
 	select ARMV8_SET_SMPEN
 	select FPGA_INTEL_SDM_MAILBOX

Regards
Ley Foon

#3 lore raw

PATCH RESEND v2 2/22 arm: socfpga: dm: Add base address for Intel Diamond Mesa

In reply to Siew Chin Lim

Reuse base_addr_s10.h for Diamond Mesa, the address is the same as Agilex.

---
 arch/arm/mach-socfpga/include/mach/base_addr_s10.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-socfpga/include/mach/base_addr_s10.h +1 -1
index d3eca65e97..eef88a7fc3 100644
@@ -10,7 +10,7 @@
 #define SOCFPGA_SDR_SCHEDULER_ADDRESS		0xf8000400
 #define SOCFPGA_HMC_MMR_IO48_ADDRESS		0xf8010000
 #define SOCFPGA_SDR_ADDRESS			0xf8011000
-#ifdef CONFIG_TARGET_SOCFPGA_AGILEX
+#if defined(CONFIG_TARGET_SOCFPGA_AGILEX) || defined(CONFIG_TARGET_SOCFPGA_DM)
 #define SOCFPGA_FW_MPU_DDR_SCR_ADDRESS		0xf8020200
 #else
 #define SOCFPGA_FW_MPU_DDR_SCR_ADDRESS		0xf8020100
Signature · 1 line
2.13.0
#4 lore raw

PATCH RESEND v2 2/22 arm: socfpga: dm: Add base address for Intel Diamond Mesa

Quoted 16 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:44 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 02/22] arm: socfpga: dm: Add base address for Intel Diamond Mesa

Quoted 5 lines

Reuse base_addr_s10.h for Diamond Mesa, the address is the same as Agilex.

---
 arch/arm/mach-socfpga/include/mach/base_addr_s10.h | 2 +-

Can consider change filename to _soc64.h

Regards
Ley Foon

#5 lore raw

PATCH RESEND v2 3/22 arm: socfpga: dm: Add firewall support for Agilex and Diamond Mesa

In reply to Siew Chin Lim

Disable the MPFE firewall for SMMU and HMC adapter for Agilex and Diamond Mesa.

---
 arch/arm/mach-socfpga/firewall.c                   | 10 ++++++++++
 arch/arm/mach-socfpga/include/mach/base_addr_s10.h |  1 +
 arch/arm/mach-socfpga/include/mach/firewall.h      |  6 ++++++
 3 files changed, 17 insertions(+)
arch/arm/mach-socfpga/firewall.c +10 -0
index 69229dc651..b87cc8aa69 100644
@@ -104,4 +104,14 @@ void firewall_setup(void)
 	       socfpga_get_sysmgr_addr() + SYSMGR_SOC64_DMA);
 	writel(SYSMGR_DMAPERIPH_ALL_NS,
 	       socfpga_get_sysmgr_addr() + SYSMGR_SOC64_DMA_PERIPH);
+
+#if defined(CONFIG_TARGET_SOCFPGA_AGILEX) || defined(CONFIG_TARGET_SOCFPGA_DM)
+	/* Disable the MPFE Firewall for SMMU */
+	writel(FIREWALL_MPFE_SCR_DISABLE_ALL, SOCFPGA_FW_MPFE_SCR_ADDRESS +
+					      FW_MPFE_SCR_HMC);
+	/* Disable MPFE Firewall for HMC adapter (ECC) */
+	writel(FIREWALL_MPFE_SCR_DISABLE_MPU, SOCFPGA_FW_MPFE_SCR_ADDRESS +
+					      FW_MPFE_SCR_HMC_ADAPTOR);
+#endif
+
 }
arch/arm/mach-socfpga/include/mach/base_addr_s10.h +1 -0
index eef88a7fc3..26bd52c907 100644
@@ -10,6 +10,7 @@
 #define SOCFPGA_SDR_SCHEDULER_ADDRESS		0xf8000400
 #define SOCFPGA_HMC_MMR_IO48_ADDRESS		0xf8010000
 #define SOCFPGA_SDR_ADDRESS			0xf8011000
+#define SOCFPGA_FW_MPFE_SCR_ADDRESS		0xf8020000
 #if defined(CONFIG_TARGET_SOCFPGA_AGILEX) || defined(CONFIG_TARGET_SOCFPGA_DM)
 #define SOCFPGA_FW_MPU_DDR_SCR_ADDRESS		0xf8020200
 #else
arch/arm/mach-socfpga/include/mach/firewall.h +6 -0
index adab65bc96..a2face0570 100644
@@ -75,6 +75,8 @@ struct socfpga_firwall_l4_sys {
 };
 
 #define FIREWALL_L4_DISABLE_ALL		(BIT(0) | BIT(24) | BIT(16))
+#define FIREWALL_MPFE_SCR_DISABLE_ALL	(BIT(0) | BIT(8) | BIT(16))
+#define FIREWALL_MPFE_SCR_DISABLE_MPU	BIT(0)
 #define FIREWALL_BRIDGE_DISABLE_ALL	(~0)
 
 /* Cache coherency unit (CCU) registers */
@@ -120,6 +122,10 @@ struct socfpga_firwall_l4_sys {
 #define FW_MPU_DDR_SCR_NONMPUREGION0ADDR_LIMIT		0x98
 #define FW_MPU_DDR_SCR_NONMPUREGION0ADDR_LIMITEXT	0x9c
 
+/* Firewall MPFE SCR Registers */
+#define FW_MPFE_SCR_HMC					0x00
+#define FW_MPFE_SCR_HMC_ADAPTOR				0x04
+
 #define MPUREGION0_ENABLE				BIT(0)
 #define NONMPUREGION0_ENABLE				BIT(8)
 
Signature · 1 line
2.13.0
#6 lore raw

PATCH RESEND v2 3/22 arm: socfpga: dm: Add firewall support for Agilex and Diamond Mesa

Quoted 45 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:44 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 03/22] arm: socfpga: dm: Add firewall support for Agilex and Diamond Mesa

Disable the MPFE firewall for SMMU and HMC adapter for Agilex and Diamond Mesa.

---
 arch/arm/mach-socfpga/firewall.c                   | 10 ++++++++++
 arch/arm/mach-socfpga/include/mach/base_addr_s10.h |  1 +
 arch/arm/mach-socfpga/include/mach/firewall.h      |  6 ++++++
 3 files changed, 17 insertions(+)
arch/arm/mach- renamed from arch/arm/mach-socfpga/firewall.c +0 -0

socfpga/firewall.c
index 69229dc651..b87cc8aa69 100644

arch/arm/mach-socfpga/firewall.c +4 -0
@@ -104,4 +104,14 @@ void firewall_setup(void)
 	       socfpga_get_sysmgr_addr() + SYSMGR_SOC64_DMA);
 	writel(SYSMGR_DMAPERIPH_ALL_NS,
 	       socfpga_get_sysmgr_addr() + SYSMGR_SOC64_DMA_PERIPH);
+
+#if defined(CONFIG_TARGET_SOCFPGA_AGILEX) ||
 defined(CONFIG_TARGET_SOCFPGA_DM)
+	/* Disable the MPFE Firewall for SMMU */
+	writel(FIREWALL_MPFE_SCR_DISABLE_ALL,

SOCFPGA_FW_MPFE_SCR_ADDRESS +

arch/arm/mach-socfpga/firewall.c +3 -0
+					      FW_MPFE_SCR_HMC);
+	/* Disable MPFE Firewall for HMC adapter (ECC) */
+	writel(FIREWALL_MPFE_SCR_DISABLE_MPU,

SOCFPGA_FW_MPFE_SCR_ADDRESS +

arch/arm/mach-socfpga/firewall.c void firewall_setup(void) · line 115

Quoted 2 lines
arch/arm/mach-socfpga/firewall.c +2 -0
+					      FW_MPFE_SCR_HMC_ADAPTOR);
+#endif

Stratix 10 also has these registers. Why Stratix 10 doesn't need this?

Regards
Ley Foon

#7 lore raw

PATCH RESEND v2 4/22 arm: socfpga: Rename Stratix10 and Agilex handoff common macros

In reply to Siew Chin Lim

Rename handoff_s10.h to handoff_soc64.h. Changed macros prefix from S10_HANDOFF to SOC64_HANDOFF.

---
 arch/arm/mach-socfpga/clock_manager_s10.c          |  2 +-
 arch/arm/mach-socfpga/include/mach/handoff_s10.h   | 39 ----------------------
 arch/arm/mach-socfpga/include/mach/handoff_soc64.h | 39 ++++++++++++++++++++++
 arch/arm/mach-socfpga/wrap_pinmux_config_s10.c     | 18 +++++-----
 arch/arm/mach-socfpga/wrap_pll_config_s10.c        | 16 ++++-----
 include/configs/socfpga_soc64_common.h             |  4 +--
 6 files changed, 59 insertions(+), 59 deletions(-)
 delete mode 100644 arch/arm/mach-socfpga/include/mach/handoff_s10.h
 create mode 100644 arch/arm/mach-socfpga/include/mach/handoff_soc64.h
arch/arm/mach-socfpga/clock_manager_s10.c +1 -1
index 05e42127b5..431794e082 100644
@@ -7,7 +7,7 @@
 #include <common.h>
 #include <asm/io.h>
 #include <asm/arch/clock_manager.h>
-#include <asm/arch/handoff_s10.h>
+#include <asm/arch/handoff_soc64.h>
 #include <asm/arch/system_manager.h>
 
 DECLARE_GLOBAL_DATA_PTR;
arch/arm/mach-socfpga/include/mach/handoff_s10.h deleted +0 -39
deleted file mode 100644
index 3e9b606ce2..0000000000
@@ -1,39 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0
- *
- * Copyright (C) 2016-2018 Intel Corporation <www.intel.com>
- *
- */
-
-#ifndef _HANDOFF_S10_H_
-#define _HANDOFF_S10_H_
-
-/*
- * Offset for HW handoff from Quartus tools
- */
-#define S10_HANDOFF_BASE		0xFFE3F000
-#define S10_HANDOFF_MUX		(S10_HANDOFF_BASE + 0x10)
-#define S10_HANDOFF_IOCTL		(S10_HANDOFF_BASE + 0x1A0)
-#define S10_HANDOFF_FPGA		(S10_HANDOFF_BASE + 0x330)
-#define S10_HANODFF_DELAY		(S10_HANDOFF_BASE + 0x3F0)
-#define S10_HANDOFF_CLOCK		(S10_HANDOFF_BASE + 0x580)
-#define S10_HANDOFF_MISC		(S10_HANDOFF_BASE + 0x610)
-#define S10_HANDOFF_MAGIC_MUX	0x504D5558
-#define S10_HANDOFF_MAGIC_IOCTL	0x494F4354
-#define S10_HANDOFF_MAGIC_FPGA	0x46504741
-#define S10_HANDOFF_MAGIC_DELAY	0x444C4159
-#define S10_HANDOFF_MAGIC_CLOCK	0x434C4B53
-#define S10_HANDOFF_MAGIC_MISC	0x4D495343
-#define S10_HANDOFF_OFFSET_LENGTH	0x4
-#define S10_HANDOFF_OFFSET_DATA	0x10
-
-#ifdef CONFIG_TARGET_SOCFPGA_STRATIX10
-#define HANDOFF_CLOCK_OSC	(S10_HANDOFF_BASE + 0x608)
-#define HANDOFF_CLOCK_FPGA	(S10_HANDOFF_BASE + 0x60C)
-#else
-#define HANDOFF_CLOCK_OSC	(S10_HANDOFF_BASE + 0x5fc)
-#define HANDOFF_CLOCK_FPGA	(S10_HANDOFF_BASE + 0x600)
-#endif
-
-#define S10_HANDOFF_SIZE	4096
-
-#endif /* _HANDOFF_S10_H_ */
arch/arm/mach-socfpga/include/mach/handoff_soc64.h new file +39 -0
new file mode 100644
index 0000000000..6c84abe324
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2016-2018 Intel Corporation <www.intel.com>
+ *
+ */
+
+#ifndef _HANDOFF_SOC64_H_
+#define _HANDOFF_SOC64_H_
+
+/*
+ * Offset for HW handoff from Quartus tools
+ */
+#define SOC64_HANDOFF_BASE		0xFFE3F000
+#define SOC64_HANDOFF_MUX		(SOC64_HANDOFF_BASE + 0x10)
+#define SOC64_HANDOFF_IOCTL		(SOC64_HANDOFF_BASE + 0x1A0)
+#define SOC64_HANDOFF_FPGA		(SOC64_HANDOFF_BASE + 0x330)
+#define SOC64_HANDOFF_DELAY		(SOC64_HANDOFF_BASE + 0x3F0)
+#define SOC64_HANDOFF_CLOCK		(SOC64_HANDOFF_BASE + 0x580)
+#define SOC64_HANDOFF_MISC		(SOC64_HANDOFF_BASE + 0x610)
+#define SOC64_HANDOFF_MAGIC_MUX		0x504D5558
+#define SOC64_HANDOFF_MAGIC_IOCTL	0x494F4354
+#define SOC64_HANDOFF_MAGIC_FPGA	0x46504741
+#define SOC64_HANDOFF_MAGIC_DELAY	0x444C4159
+#define SOC64_HANDOFF_MAGIC_CLOCK	0x434C4B53
+#define SOC64_HANDOFF_MAGIC_MISC	0x4D495343
+#define SOC64_HANDOFF_OFFSET_LENGTH	0x4
+#define SOC64_HANDOFF_OFFSET_DATA	0x10
+
+#ifdef CONFIG_TARGET_SOCFPGA_STRATIX10
+#define SOC64_HANDOFF_CLOCK_OSC	(SOC64_HANDOFF_BASE + 0x608)
+#define SOC64_HANDOFF_CLOCK_FPGA	(SOC64_HANDOFF_BASE + 0x60C)
+#else
+#define SOC64_HANDOFF_CLOCK_OSC	(SOC64_HANDOFF_BASE + 0x5fc)
+#define SOC64_HANDOFF_CLOCK_FPGA	(SOC64_HANDOFF_BASE + 0x600)
+#endif
+
+#define SOC64_HANDOFF_SIZE		4096
+
+#endif /* _HANDOFF_SOC64_H_ */
arch/arm/mach-socfpga/wrap_pinmux_config_s10.c +9 -9
index 0b497ec30c..d10fb5e454 100644
@@ -7,23 +7,23 @@
 #include <common.h>
 #include <errno.h>
 #include <asm/io.h>
-#include <asm/arch/handoff_s10.h>
+#include <asm/arch/handoff_soc64.h>
 
 static void sysmgr_pinmux_handoff_read(void *handoff_address,
 				       const u32 **table,
 				       unsigned int *table_len)
 {
 	unsigned int handoff_entry = (swab32(readl(handoff_address +
-					S10_HANDOFF_OFFSET_LENGTH)) -
-					S10_HANDOFF_OFFSET_DATA) /
+					SOC64_HANDOFF_OFFSET_LENGTH)) -
+					SOC64_HANDOFF_OFFSET_DATA) /
 					sizeof(unsigned int);
 	unsigned int handoff_chunk[handoff_entry], temp, i;
 
-	if (swab32(readl(S10_HANDOFF_MUX)) == S10_HANDOFF_MAGIC_MUX) {
+	if (swab32(readl(SOC64_HANDOFF_MUX)) == SOC64_HANDOFF_MAGIC_MUX) {
 		/* using handoff from Quartus tools if exists */
 		for (i = 0; i < handoff_entry; i++) {
 			temp = readl(handoff_address +
-				     S10_HANDOFF_OFFSET_DATA + (i * 4));
+				     SOC64_HANDOFF_OFFSET_DATA + (i * 4));
 			handoff_chunk[i] = swab32(temp);
 		}
 		*table = handoff_chunk;
@@ -33,24 +33,24 @@ static void sysmgr_pinmux_handoff_read(void *handoff_address,
 
 void sysmgr_pinmux_table_sel(const u32 **table, unsigned int *table_len)
 {
-	sysmgr_pinmux_handoff_read((void *)S10_HANDOFF_MUX, table,
+	sysmgr_pinmux_handoff_read((void *)SOC64_HANDOFF_MUX, table,
 				   table_len);
 }
 
 void sysmgr_pinmux_table_ctrl(const u32 **table, unsigned int *table_len)
 {
-	sysmgr_pinmux_handoff_read((void *)S10_HANDOFF_IOCTL, table,
+	sysmgr_pinmux_handoff_read((void *)SOC64_HANDOFF_IOCTL, table,
 				   table_len);
 }
 
 void sysmgr_pinmux_table_fpga(const u32 **table, unsigned int *table_len)
 {
-	sysmgr_pinmux_handoff_read((void *)S10_HANDOFF_FPGA, table,
+	sysmgr_pinmux_handoff_read((void *)SOC64_HANDOFF_FPGA, table,
 				   table_len);
 }
 
 void sysmgr_pinmux_table_delay(const u32 **table, unsigned int *table_len)
 {
-	sysmgr_pinmux_handoff_read((void *)S10_HANODFF_DELAY, table,
+	sysmgr_pinmux_handoff_read((void *)SOC64_HANDOFF_DELAY, table,
 				   table_len);
 }
arch/arm/mach-socfpga/wrap_pll_config_s10.c +8 -8
index 049c5711a8..6a0d6b5ead 100644
@@ -7,24 +7,24 @@
 #include <common.h>
 #include <asm/arch/clock_manager.h>
 #include <asm/io.h>
-#include <asm/arch/handoff_s10.h>
+#include <asm/arch/handoff_soc64.h>
 #include <asm/arch/system_manager.h>
 
 const struct cm_config * const cm_get_default_config(void)
 {
 #ifdef CONFIG_SPL_BUILD
 	struct cm_config *cm_handoff_cfg = (struct cm_config *)
-		(S10_HANDOFF_CLOCK + S10_HANDOFF_OFFSET_DATA);
+		(SOC64_HANDOFF_CLOCK + SOC64_HANDOFF_OFFSET_DATA);
 	u32 *conversion = (u32 *)cm_handoff_cfg;
 	u32 i;
-	u32 handoff_clk = readl(S10_HANDOFF_CLOCK);
+	u32 handoff_clk = readl(SOC64_HANDOFF_CLOCK);
 
-	if (swab32(handoff_clk) == S10_HANDOFF_MAGIC_CLOCK) {
-		writel(swab32(handoff_clk), S10_HANDOFF_CLOCK);
+	if (swab32(handoff_clk) == SOC64_HANDOFF_MAGIC_CLOCK) {
+		writel(swab32(handoff_clk), SOC64_HANDOFF_CLOCK);
 		for (i = 0; i < (sizeof(*cm_handoff_cfg) / sizeof(u32)); i++)
 			conversion[i] = swab32(conversion[i]);
 		return cm_handoff_cfg;
-	} else if (handoff_clk == S10_HANDOFF_MAGIC_CLOCK) {
+	} else if (handoff_clk == SOC64_HANDOFF_MAGIC_CLOCK) {
 		return cm_handoff_cfg;
 	}
 #endif
@@ -35,7 +35,7 @@ const unsigned int cm_get_osc_clk_hz(void)
 {
 #ifdef CONFIG_SPL_BUILD
 
-	u32 clock = readl(HANDOFF_CLOCK_OSC);
+	u32 clock = readl(SOC64_HANDOFF_CLOCK_OSC);
 
 	writel(clock,
 	       socfpga_get_sysmgr_addr() + SYSMGR_SOC64_BOOT_SCRATCH_COLD1);
@@ -52,7 +52,7 @@ const unsigned int cm_get_intosc_clk_hz(void)
 const unsigned int cm_get_fpga_clk_hz(void)
 {
 #ifdef CONFIG_SPL_BUILD
-	u32 clock = readl(HANDOFF_CLOCK_FPGA);
+	u32 clock = readl(SOC64_HANDOFF_CLOCK_FPGA);
 
 	writel(clock,
 	       socfpga_get_sysmgr_addr() + SYSMGR_SOC64_BOOT_SCRATCH_COLD2);
include/configs/socfpga_soc64_common.h +2 -2
index fdcd7d3e9a..194df5940d 100644
@@ -8,7 +8,7 @@
 #define __CONFIG_SOCFPGA_SOC64_COMMON_H__
 
 #include <asm/arch/base_addr_s10.h>
-#include <asm/arch/handoff_s10.h>
+#include <asm/arch/handoff_soc64.h>
 #include <linux/stringify.h>
 
 /*
@@ -43,7 +43,7 @@
 #ifdef CONFIG_SPL_BUILD
 #define CONFIG_SYS_INIT_SP_ADDR		(CONFIG_SYS_INIT_RAM_ADDR  \
 					+ CONFIG_SYS_INIT_RAM_SIZE \
-					- S10_HANDOFF_SIZE)
+					- SOC64_HANDOFF_SIZE)
 #else
 #define CONFIG_SYS_INIT_SP_ADDR		(CONFIG_SYS_TEXT_BASE \
 					+ 0x100000)
Signature · 1 line
2.13.0
#8 lore raw

PATCH RESEND v2 4/22 arm: socfpga: Rename Stratix10 and Agilex handoff common macros

Quoted 32 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:44 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 04/22] arm: socfpga: Rename Stratix10 and Agilex handoff common macros

Rename handoff_s10.h to handoff_soc64.h. Changed macros prefix from S10_HANDOFF to SOC64_HANDOFF.

---
 arch/arm/mach-socfpga/clock_manager_s10.c          |  2 +-
 arch/arm/mach-socfpga/include/mach/handoff_s10.h   | 39 -------------------
---
 arch/arm/mach-socfpga/include/mach/handoff_soc64.h | 39
++++++++++++++++++++++
 arch/arm/mach-socfpga/wrap_pinmux_config_s10.c     | 18 +++++-----
 arch/arm/mach-socfpga/wrap_pll_config_s10.c        | 16 ++++-----
 include/configs/socfpga_soc64_common.h             |  4 +--
 6 files changed, 59 insertions(+), 59 deletions(-)  delete mode 100644
arch/arm/mach-socfpga/include/mach/handoff_s10.h
 create mode 100644 arch/arm/mach-
Quoted 1 line

socfpga/include/mach/handoff_soc64.h

Regards
Ley Foon

#9 lore raw

PATCH RESEND v2 5/22 arm: socfpga: Changed wrap_pll_config_s10.c to wrap_pll_config_soc64.c

In reply to Siew Chin Lim

Rename to common file name to used by all SOC64 devices.

---
 arch/arm/mach-socfpga/Makefile                                        | 4 ++--
 .../mach-socfpga/{wrap_pll_config_s10.c => wrap_pll_config_soc64.c}   | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
 rename arch/arm/mach-socfpga/{wrap_pll_config_s10.c => wrap_pll_config_soc64.c} (96%)
arch/arm/mach-socfpga/Makefile +2 -2
index 0b05283a7a..fc3b809afd 100644
@@ -37,7 +37,7 @@ obj-y	+= reset_manager_s10.o
 obj-y	+= system_manager_s10.o
 obj-y	+= timer_s10.o
 obj-y	+= wrap_pinmux_config_s10.o
-obj-y	+= wrap_pll_config_s10.o
+obj-y	+= wrap_pll_config_soc64.o
 endif
 
 ifdef CONFIG_TARGET_SOCFPGA_AGILEX
@@ -50,7 +50,7 @@ obj-y	+= reset_manager_s10.o
 obj-y	+= system_manager_s10.o
 obj-y	+= timer_s10.o
 obj-y	+= wrap_pinmux_config_s10.o
-obj-y	+= wrap_pll_config_s10.o
+obj-y	+= wrap_pll_config_soc64.o
 endif
 
 ifdef CONFIG_SPL_BUILD
arch/arm/mach-socfpga/wrap_pll_config_soc64.c renamed from arch/arm/mach-socfpga/wrap_pll_config_s10.c +1 -1
similarity index 96%
rename from arch/arm/mach-socfpga/wrap_pll_config_s10.c
rename to arch/arm/mach-socfpga/wrap_pll_config_soc64.c
index 6a0d6b5ead..a3087cd0eb 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (C) 2016-2018 Intel Corporation <www.intel.com>
+ * Copyright (C) 2016-2020 Intel Corporation <www.intel.com>
  *
  */
 
Signature · 1 line
2.13.0
#10 lore raw

PATCH RESEND v2 5/22 arm: socfpga: Changed wrap_pll_config_s10.c to wrap_pll_config_soc64.c

Quoted 18 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:44 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 05/22] arm: socfpga: Changed wrap_pll_config_s10.c to wrap_pll_config_soc64.c

Rename to common file name to used by all SOC64 devices.

Quoted 7 lines
---
 arch/arm/mach-socfpga/Makefile                                        | 4 ++--
 .../mach-socfpga/{wrap_pll_config_s10.c => wrap_pll_config_soc64.c}   | 2
+-
 2 files changed, 3 insertions(+), 3 deletions(-)  rename arch/arm/mach-

socfpga/{wrap_pll_config_s10.c => wrap_pll_config_soc64.c} (96%)

Regards
Ley Foon

#11 lore raw

PATCH RESEND v2 6/22 arm: socfpga: Changed system_manager_s10.c to system_manager_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                                       | 5 +++--
 .../mach-socfpga/{system_manager_s10.c => system_manager_soc64.c}    | 0
 2 files changed, 3 insertions(+), 2 deletions(-)
 rename arch/arm/mach-socfpga/{system_manager_s10.c => system_manager_soc64.c} (100%)
arch/arm/mach-socfpga/Makefile +3 -2
index fc3b809afd..ff82a64d18 100644
@@ -4,6 +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>
 
 obj-y	+= board.o
 obj-y	+= clock_manager.o
@@ -34,7 +35,7 @@ obj-y	+= mailbox_s10.o
 obj-y	+= misc_s10.o
 obj-y	+= mmu-arm64_s10.o
 obj-y	+= reset_manager_s10.o
-obj-y	+= system_manager_s10.o
+obj-y	+= system_manager_soc64.o
 obj-y	+= timer_s10.o
 obj-y	+= wrap_pinmux_config_s10.o
 obj-y	+= wrap_pll_config_soc64.o
@@ -47,7 +48,7 @@ obj-y	+= mailbox_s10.o
 obj-y	+= misc_s10.o
 obj-y	+= mmu-arm64_s10.o
 obj-y	+= reset_manager_s10.o
-obj-y	+= system_manager_s10.o
+obj-y	+= system_manager_soc64.o
 obj-y	+= timer_s10.o
 obj-y	+= wrap_pinmux_config_s10.o
 obj-y	+= wrap_pll_config_soc64.o
arch/arm/mach-socfpga/system_manager_soc64.c renamed from arch/arm/mach-socfpga/system_manager_s10.c +0 -0
similarity index 100%
rename from arch/arm/mach-socfpga/system_manager_s10.c
rename to arch/arm/mach-socfpga/system_manager_soc64.c
Signature · 1 line
2.13.0
#12 lore raw

PATCH RESEND v2 6/22 arm: socfpga: Changed system_manager_s10.c to system_manager_soc64.c

Quoted 19 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:44 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 06/22] arm: socfpga: Changed system_manager_s10.c to system_manager_soc64.c

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

Quoted 7 lines
---
 arch/arm/mach-socfpga/Makefile                                       | 5 +++--
 .../mach-socfpga/{system_manager_s10.c => system_manager_soc64.c}    |
0
 2 files changed, 3 insertions(+), 2 deletions(-)  rename arch/arm/mach-

socfpga/{system_manager_s10.c => system_manager_soc64.c} (100%)

Regards
Ley Foon

#13 lore raw

PATCH RESEND v2 7/22 arm: socfpga: Rearrange sequence of macros in handoff_soc64.h

In reply to Siew Chin Lim

No functionality change. In preparation for Stratix10 and Agilex handoff function restructuring.

---
 arch/arm/mach-socfpga/include/mach/handoff_soc64.h | 46 +++++++++++-----------
 1 file changed, 24 insertions(+), 22 deletions(-)
arch/arm/mach-socfpga/include/mach/handoff_soc64.h +24 -22
index 6c84abe324..dbd19f602c 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0
  *
- * Copyright (C) 2016-2018 Intel Corporation <www.intel.com>
+ * Copyright (C) 2016-2020 Intel Corporation <www.intel.com>
  *
  */
 
@@ -10,30 +10,32 @@
 /*
  * Offset for HW handoff from Quartus tools
  */
-#define SOC64_HANDOFF_BASE		0xFFE3F000
-#define SOC64_HANDOFF_MUX		(SOC64_HANDOFF_BASE + 0x10)
-#define SOC64_HANDOFF_IOCTL		(SOC64_HANDOFF_BASE + 0x1A0)
-#define SOC64_HANDOFF_FPGA		(SOC64_HANDOFF_BASE + 0x330)
-#define SOC64_HANDOFF_DELAY		(SOC64_HANDOFF_BASE + 0x3F0)
-#define SOC64_HANDOFF_CLOCK		(SOC64_HANDOFF_BASE + 0x580)
-#define SOC64_HANDOFF_MISC		(SOC64_HANDOFF_BASE + 0x610)
-#define SOC64_HANDOFF_MAGIC_MUX		0x504D5558
-#define SOC64_HANDOFF_MAGIC_IOCTL	0x494F4354
-#define SOC64_HANDOFF_MAGIC_FPGA	0x46504741
-#define SOC64_HANDOFF_MAGIC_DELAY	0x444C4159
-#define SOC64_HANDOFF_MAGIC_CLOCK	0x434C4B53
-#define SOC64_HANDOFF_MAGIC_MISC	0x4D495343
-#define SOC64_HANDOFF_OFFSET_LENGTH	0x4
-#define SOC64_HANDOFF_OFFSET_DATA	0x10
+/* HPS handoff */
+#define SOC64_HANDOFF_MAGIC_MUX			0x504D5558
+#define SOC64_HANDOFF_MAGIC_IOCTL		0x494F4354
+#define SOC64_HANDOFF_MAGIC_FPGA		0x46504741
+#define SOC64_HANDOFF_MAGIC_DELAY		0x444C4159
+#define SOC64_HANDOFF_MAGIC_CLOCK		0x434C4B53
+#define SOC64_HANDOFF_MAGIC_MISC		0x4D495343
+
+#define SOC64_HANDOFF_OFFSET_LENGTH		0x4
+#define SOC64_HANDOFF_OFFSET_DATA		0x10
+#define SOC64_HANDOFF_SIZE			4096
+
+#define SOC64_HANDOFF_BASE			0xFFE3F000
+#define SOC64_HANDOFF_MISC			(SOC64_HANDOFF_BASE + 0x610)
+#define SOC64_HANDOFF_MUX			(SOC64_HANDOFF_BASE + 0x10)
+#define SOC64_HANDOFF_IOCTL			(SOC64_HANDOFF_BASE + 0x1A0)
+#define SOC64_HANDOFF_FPGA			(SOC64_HANDOFF_BASE + 0x330)
+#define SOC64_HANDOFF_DELAY			(SOC64_HANDOFF_BASE + 0x3F0)
+#define SOC64_HANDOFF_CLOCK			(SOC64_HANDOFF_BASE + 0x580)
 
 #ifdef CONFIG_TARGET_SOCFPGA_STRATIX10
-#define SOC64_HANDOFF_CLOCK_OSC	(SOC64_HANDOFF_BASE + 0x608)
-#define SOC64_HANDOFF_CLOCK_FPGA	(SOC64_HANDOFF_BASE + 0x60C)
+#define SOC64_HANDOFF_CLOCK_OSC			(SOC64_HANDOFF_BASE + 0x608)
+#define SOC64_HANDOFF_CLOCK_FPGA		(SOC64_HANDOFF_BASE + 0x60C)
 #else
-#define SOC64_HANDOFF_CLOCK_OSC	(SOC64_HANDOFF_BASE + 0x5fc)
-#define SOC64_HANDOFF_CLOCK_FPGA	(SOC64_HANDOFF_BASE + 0x600)
+#define SOC64_HANDOFF_CLOCK_OSC			(SOC64_HANDOFF_BASE + 0x5fc)
+#define SOC64_HANDOFF_CLOCK_FPGA		(SOC64_HANDOFF_BASE + 0x600)
 #endif
 
-#define SOC64_HANDOFF_SIZE		4096
-
 #endif /* _HANDOFF_SOC64_H_ */
Signature · 1 line
2.13.0
#14 lore raw

PATCH RESEND v2 7/22 arm: socfpga: Rearrange sequence of macros in handoff_soc64.h

Quoted 16 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:44 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 07/22] arm: socfpga: Rearrange sequence of macros in handoff_soc64.h

Quoted 3 lines

No functionality change. In preparation for Stratix10 and Agilex handoff function restructuring.

This patch adding new macros, please add description for this in commit message.

Regards
Ley Foon

#15 lore raw

PATCH RESEND v2 8/22 arm: socfpga: Restructure Stratix10 and Agilex handoff code

In reply to Siew Chin Lim

Restructure Stratix10 and Agilex handoff code to used by all SOC64 devices, in preparation to support handoff for Diamond Mesa.

Remove wrap_pinmux_config_s10.c. Add wrap_handoff_soc64.c which contains the generic function to parse the handoff data.

Update system_manager_soc64.c to use generic handoff function in wrap_handoff_soc64.c.

---
 arch/arm/mach-socfpga/Makefile                     |  4 +-
 arch/arm/mach-socfpga/include/mach/handoff_soc64.h | 21 +++++++
 .../include/mach/system_manager_soc64.h            |  4 --
 arch/arm/mach-socfpga/system_manager_soc64.c       | 53 ++++++++++------
 arch/arm/mach-socfpga/wrap_handoff_soc64.c         | 73 ++++++++++++++++++++++
 arch/arm/mach-socfpga/wrap_pinmux_config_s10.c     | 56 -----------------
 6 files changed, 131 insertions(+), 80 deletions(-)
 create mode 100644 arch/arm/mach-socfpga/wrap_handoff_soc64.c
 delete mode 100644 arch/arm/mach-socfpga/wrap_pinmux_config_s10.c
arch/arm/mach-socfpga/Makefile +2 -2
index ff82a64d18..96fef50a12 100644
@@ -37,7 +37,7 @@ obj-y	+= mmu-arm64_s10.o
 obj-y	+= reset_manager_s10.o
 obj-y	+= system_manager_soc64.o
 obj-y	+= timer_s10.o
-obj-y	+= wrap_pinmux_config_s10.o
+obj-y	+= wrap_handoff_soc64.o
 obj-y	+= wrap_pll_config_soc64.o
 endif
 
@@ -50,7 +50,7 @@ obj-y	+= mmu-arm64_s10.o
 obj-y	+= reset_manager_s10.o
 obj-y	+= system_manager_soc64.o
 obj-y	+= timer_s10.o
-obj-y	+= wrap_pinmux_config_s10.o
+obj-y	+= wrap_handoff_soc64.o
 obj-y	+= wrap_pll_config_soc64.o
 endif
 
arch/arm/mach-socfpga/include/mach/handoff_soc64.h +21 -0
index dbd19f602c..68e0278384 100644
@@ -11,6 +11,7 @@
  * Offset for HW handoff from Quartus tools
  */
 /* HPS handoff */
+#define SOC64_HANDOFF_MAGIC_BOOT		0x424F4F54
 #define SOC64_HANDOFF_MAGIC_MUX			0x504D5558
 #define SOC64_HANDOFF_MAGIC_IOCTL		0x494F4354
 #define SOC64_HANDOFF_MAGIC_FPGA		0x46504741
@@ -38,4 +39,24 @@
 #define SOC64_HANDOFF_CLOCK_FPGA		(SOC64_HANDOFF_BASE + 0x600)
 #endif
 
+#define SOC64_HANDOFF_MUX_LEN			96
+#define SOC64_HANDOFF_IOCTL_LEN			96
+#ifdef CONFIG_TARGET_SOCFPGA_STRATIX10
+#define SOC64_HANDOFF_FPGA_LEN			42
+#else
+#define SOC64_HANDOFF_FPGA_LEN			40
+#endif
+#define SOC64_HANDOFF_DELAY_LEN			96
+
+#ifndef __ASSEMBLY__
+#include <asm/types.h>
+enum endianness {
+	little_endian,
+	big_endian
+};
+
+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);
+#endif
 #endif /* _HANDOFF_SOC64_H_ */
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +0 -4
index 4949cae97a..1eb8e7a904 100644
@@ -10,10 +10,6 @@
 void sysmgr_pinmux_init(void);
 void populate_sysmgr_fpgaintf_module(void);
 void populate_sysmgr_pinmux(void);
-void sysmgr_pinmux_table_sel(const u32 **table, unsigned int *table_len);
-void sysmgr_pinmux_table_ctrl(const u32 **table, unsigned int *table_len);
-void sysmgr_pinmux_table_fpga(const u32 **table, unsigned int *table_len);
-void sysmgr_pinmux_table_delay(const u32 **table, unsigned int *table_len);
 
 #define SYSMGR_SOC64_WDDBG			0x08
 #define SYSMGR_SOC64_DMA			0x20
arch/arm/mach-socfpga/system_manager_soc64.c +35 -18

86 lines not on this page · raw message

arch/arm/mach-socfpga/wrap_handoff_soc64.c new file +73 -0

73 lines not on this page · raw message

arch/arm/mach-socfpga/wrap_pinmux_config_s10.c deleted +0 -56

56 lines not on this page · raw message

Signature · 1 line
2.13.0
#16 lore raw

PATCH RESEND v2 8/22 arm: socfpga: Restructure Stratix10 and Agilex handoff code

Quoted 27 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:44 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 08/22] arm: socfpga: Restructure Stratix10 and Agilex handoff code

Restructure Stratix10 and Agilex handoff code to used by all SOC64 devices, in preparation to support handoff for Diamond Mesa.

Remove wrap_pinmux_config_s10.c. Add wrap_handoff_soc64.c which contains the generic function to parse the handoff data.

Update system_manager_soc64.c to use generic handoff function in wrap_handoff_soc64.c.

---

[....]

Quoted 7 lines
arch/arm/mach-socfpga/system_manager_soc64.c +0 -0
index cdda881efd..f94bf5ecd6 100644
@@ -1,12 +1,13 @@
 // SPDX-License-Identifier: GPL-2.0

arch/arm/mach-socfpga/system_manager_soc64.c line 10

Quoted 10 lines
arch/arm/mach-socfpga/system_manager_soc64.c +2 -1
 /*
- * Copyright (C) 2016-2018 Intel Corporation <www.intel.com>
+ * Copyright (C) 2016-2020 Intel Corporation <www.intel.com>
  *
  */
 
 #include <common.h>
 #include <asm/io.h>
 #include <asm/arch/system_manager.h>
+#include <asm/arch/handoff_soc64.h>

Sort in alphanumerical order.

[...]

Quoted 9 lines
arch/arm/mach-socfpga/system_manager_soc64.c +0 -0
 }
arch/arm/mach-socfpga/wrap_handoff_soc64.c new file +1 -0
new file mode 100644
index 0000000000..672bdd5230
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0

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

Quoted 10 lines
arch/arm/mach-socfpga/wrap_handoff_soc64.c new file +10 -0
+/*
+ * Copyright (C) 2020 Intel Corporation <www.intel.com>
+ *
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <asm/io.h>
+#include <asm/arch/handoff_soc64.h>
+#include "log.h"

Sort in alphanumerical order.

[...]

Regards
Ley Foon

#17 lore raw

PATCH RESEND v2 9/22 arm: socfpga: Add handoff data support for Diamond Mesa

In reply to Siew Chin Lim

Diamond Mesa support both HPS handoff data and DDR handoff data. HPS handoff data support re-use Straix10 and Agilex code. DDR handoff data is newly introduced in Diamond Mesa.

---
 arch/arm/mach-socfpga/include/mach/handoff_soc64.h | 19 ++++++++++
 arch/arm/mach-socfpga/wrap_handoff_soc64.c         | 40 ++++++++++++++++++++++
 2 files changed, 59 insertions(+)
arch/arm/mach-socfpga/include/mach/handoff_soc64.h +19 -0
index 68e0278384..c38b232065 100644
@@ -23,8 +23,27 @@
 #define SOC64_HANDOFF_OFFSET_DATA		0x10
 #define SOC64_HANDOFF_SIZE			4096
 
+#if defined(CONFIG_TARGET_SOCFPGA_STRATIX10) || \
+	defined(CONFIG_TARGET_SOCFPGA_AGILEX)
 #define SOC64_HANDOFF_BASE			0xFFE3F000
 #define SOC64_HANDOFF_MISC			(SOC64_HANDOFF_BASE + 0x610)
+#elif defined(CONFIG_TARGET_SOCFPGA_DM)
+#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_MEMRESET_BASE		(SOC64_HANDOFF_DDR_BASE + 0xC)
+#define SOC64_HANDOFF_DDR_UMCTL2_SECTION	(SOC64_HANDOFF_DDR_BASE + 0x10)
+#define SOC64_HANDOFF_DDR_UMCTL2_BASE		(SOC64_HANDOFF_DDR_BASE + 0x1C)
+#define SOC64_HANDOFF_DDR_PHY_MAGIC		0x43594850
+#define SOC64_HANDOFF_DDR_PHY_INIT_ENGINE_MAGIC	0x45594850
+#define SOC64_HANDOFF_DDR_PHY_BASE_OFFSET	0x8
+#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)
arch/arm/mach-socfpga/wrap_handoff_soc64.c +40 -0
index 672bdd5230..aea384897e 100644
@@ -67,6 +67,46 @@ int socfpga_handoff_read(void *handoff_address, void *table, u32 table_len,
 			debug("at addr  0x%p\n", (u32 *)handoff_address);
 			return -EPERM;
 		}
+	} else {
+#ifdef CONFIG_TARGET_SOCFPGA_DM
+		temp = readl(handoff_address);
+		if (temp == SOC64_HANDOFF_DDR_UMCTL2_MAGIC) {
+			debug("%s: umctl2 handoff data =\n{\n",
+			      __func__);
+		} else if (temp == SOC64_HANDOFF_DDR_PHY_MAGIC) {
+			debug("%s: PHY handoff data =\n{\n",
+			      __func__);
+		} else if (temp == SOC64_HANDOFF_DDR_PHY_INIT_ENGINE_MAGIC) {
+			debug("%s: PHY engine handoff data =\n{\n",
+			      __func__);
+		}
+
+		debug("handoff table address = 0x%p table length = 0x%x\n",
+		      table_x32, table_len);
+
+		if (temp == SOC64_HANDOFF_DDR_UMCTL2_MAGIC ||
+		    temp == SOC64_HANDOFF_DDR_PHY_MAGIC ||
+		    temp == SOC64_HANDOFF_DDR_PHY_INIT_ENGINE_MAGIC) {
+			/* Using handoff from Quartus tools if exists */
+			for (i = 0; i < table_len; i++) {
+				*table_x32 = readl(handoff_address +
+						SOC64_HANDOFF_OFFSET_DATA + (i * 4));
+
+				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 HANDOFF MAGIC ", __func__);
+			debug("at addr 0x%p\n", (u32 *)handoff_address);
+			return -EPERM;
+		}
+#endif
 	}
 
 	return 0;
Signature · 1 line
2.13.0
#18 lore raw

PATCH RESEND v2 9/22 arm: socfpga: Add handoff data support for Diamond Mesa

Quoted 32 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:44 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 09/22] arm: socfpga: Add handoff data support for Diamond Mesa

Diamond Mesa support both HPS handoff data and DDR handoff data. HPS handoff data support re-use Straix10 and Agilex code. DDR handoff data is newly introduced in Diamond Mesa.

---
 arch/arm/mach-socfpga/include/mach/handoff_soc64.h | 19 ++++++++++
 arch/arm/mach-socfpga/wrap_handoff_soc64.c         | 40
++++++++++++++++++++++
 2 files changed, 59 insertions(+)
arch/arm/mach-socfpga/include/mach/handoff_soc64.h +0 -0
index 68e0278384..c38b232065 100644

[...]

Quoted 26 lines
arch/arm/mach-socfpga/include/mach/handoff_soc64.h +10 -0
+	} else {
+#ifdef CONFIG_TARGET_SOCFPGA_DM
+		temp = readl(handoff_address);
+		if (temp == SOC64_HANDOFF_DDR_UMCTL2_MAGIC) {
+			debug("%s: umctl2 handoff data =\n{\n",
+			      __func__);
+		} else if (temp == SOC64_HANDOFF_DDR_PHY_MAGIC) {
+			debug("%s: PHY handoff data =\n{\n",
+			      __func__);
+		} else if (temp ==

SOC64_HANDOFF_DDR_PHY_INIT_ENGINE_MAGIC) {

arch/arm/mach-socfpga/include/mach/handoff_soc64.h +10 -0
+			debug("%s: PHY engine handoff data =\n{\n",
+			      __func__);
+		}
+
+		debug("handoff table address = 0x%p table length = 0x%x\n",
+		      table_x32, table_len);
+
+		if (temp == SOC64_HANDOFF_DDR_UMCTL2_MAGIC ||
+		    temp == SOC64_HANDOFF_DDR_PHY_MAGIC ||
+		    temp ==

SOC64_HANDOFF_DDR_PHY_INIT_ENGINE_MAGIC) {

arch/arm/mach-socfpga/include/mach/handoff_soc64.h +4 -0
+			/* Using handoff from Quartus tools if exists */
+			for (i = 0; i < table_len; i++) {
+				*table_x32 = readl(handoff_address +
+
Quoted 1 line
	SOC64_HANDOFF_OFFSET_DATA + (i * 4));

Change 4 to sizeof().

Regards
Ley Foon

#19 lore raw

PATCH RESEND v2 10/22 drivers: clk: dm: Add clock driver for Diamond Mesa

In reply to Siew Chin Lim

Add clock manager driver for Diamond Mesa. Provides clock initialization and get_rate functions.

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

504 lines not on this page · raw message

drivers/clk/altera/clk-dm.h new file +213 -0

213 lines not on this page · raw message

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

71 lines not on this page · raw message

Signature · 1 line
2.13.0
#20 lore raw

PATCH RESEND v2 10/22 drivers: clk: dm: Add clock driver for Diamond Mesa

Quoted 82 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:44 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 10/22] drivers: clk: dm: Add clock driver for Diamond Mesa

Add clock manager driver for Diamond Mesa. Provides clock initialization and get_rate functions.

---
 drivers/clk/altera/Makefile          |   3 +-
 drivers/clk/altera/clk-dm.c          | 504
+++++++++++++++++++++++++++++++++++
 drivers/clk/altera/clk-dm.h          | 213 +++++++++++++++
 include/dt-bindings/clock/dm-clock.h |  71 +++++
 4 files changed, 790 insertions(+), 1 deletion(-)  create mode 100644

drivers/clk/altera/clk-dm.c create mode 100644 drivers/clk/altera/clk-dm.h create mode 100644 include/dt-bindings/clock/dm-clock.h

drivers/clk/altera/Makefile index renamed from drivers/clk/altera/Makefile +0 -0

96215ad5c4..08f16fd7cd 100644

drivers/clk/altera/Makefile +2 -1
@@ -1,7 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0+
 #
-# Copyright (C) 2018 Marek Vasut <[email protected]>
+# Copyright (C) 2018-2020 Marek Vasut <[email protected]>
 #
 
 obj-$(CONFIG_TARGET_SOCFPGA_AGILEX) += clk-agilex.o
 obj-$(CONFIG_TARGET_SOCFPGA_ARRIA10) += clk-arria10.o
+obj-$(CONFIG_TARGET_SOCFPGA_DM) += clk-dm.o
drivers/clk/altera/clk-dm.c new file renamed from drivers/clk/altera/clk-dm.c +0 -0

mode 100644 index 0000000000..c8421ed20b

drivers/clk/altera/clk-dm.c new file +33 -0
@@ -0,0 +1,504 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 Intel Corporation <www.intel.com>  */
+
+#include <common.h>
+#include <asm/arch/clock_manager.h>
+#include <asm/io.h>
+#include <clk-uclass.h>
+#include <dm.h>
+#include <dm/lists.h>
+#include <dm/util.h>
+#include <dt-bindings/clock/dm-clock.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct socfpga_clk_platdata {
+	void __iomem *regs;
+};
+
+/*
+ * function to write the bypass register which requires a poll of the
+ * busy bit
+ */
+static void clk_write_bypass_mainpll(struct socfpga_clk_platdata *plat,
+u32 val) {
+	CM_REG_WRITEL(plat, val, CLKMGR_MAINPLL_BYPASS);
+	cm_wait_for_fsm();
+}
+
+static void clk_write_bypass_perpll(struct socfpga_clk_platdata *plat,
+u32 val) {
+	CM_REG_WRITEL(plat, val, CLKMGR_PERPLL_BYPASS);
+	cm_wait_for_fsm();

drivers/clk/altera/clk-dm.c line 43

Quoted 10 lines
drivers/clk/altera/clk-dm.c new file +10 -0
+}
+
+#ifndef CONFIG_TARGET_SOCFPGA_DM
+/* function to write the ctrl register which requires a poll of the
+busy bit */ static void clk_write_ctrl(struct socfpga_clk_platdata
+*plat, u32 val) {
+	CM_REG_WRITEL(plat, val, CLKMGR_CTRL);
+	cm_wait_for_fsm();
+}
+#endif

This .c file only get compiled when CONFIG_TARGET_SOCFPGA_DM is enabled. This code will never get compiled. Same for the similar #ifndef in this file.

[....]

Quoted 48 lines
drivers/clk/altera/clk-dm.c new file +44 -0
+static u64 clk_get_pll_output_hz(struct socfpga_clk_platdata *plat,
+				 u32 pllglob_reg, u32 plldiv_reg)
+{
+	u64 clock = 0;
+	u32 clklsrc, divf, divr, divq, power = 1;
+
+	/* Get input clock frequency */
+	clklsrc = (CM_REG_READL(plat, pllglob_reg) &
+		   CLKMGR_PLLGLOB_VCO_PSRC_MASK) >>
+		   CLKMGR_PLLGLOB_VCO_PSRC_OFFSET;
+
+	switch (clklsrc) {
+	case CLKMGR_VCO_PSRC_EOSC1:
+		clock = cm_get_osc_clk_hz();
+		break;
+	case CLKMGR_VCO_PSRC_INTOSC:
+		clock = cm_get_intosc_clk_hz();
+		break;
+	case CLKMGR_VCO_PSRC_F2S:
+		clock = cm_get_fpga_clk_hz();
+		break;
+	}
+
+	/* Calculate pll out clock frequency */
+	divf = (CM_REG_READL(plat, plldiv_reg) &
+		CLKMGR_PLLDIV_FDIV_MASK) >>
+		CLKMGR_PLLDIV_FDIV_OFFSET;
+
+	divr = (CM_REG_READL(plat, plldiv_reg) &
+		CLKMGR_PLLDIV_REFCLKDIV_MASK) >>
+		CLKMGR_PLLDIV_REFCLKDIV_OFFSET;
+
+	divq = (CM_REG_READL(plat, plldiv_reg) &
+		CLKMGR_PLLDIV_OUTDIV_QDIV_MASK) >>
+		CLKMGR_PLLDIV_OUTDIV_QDIV_OFFSET;
+
+	while (divq) {
+		power *= 2;
+		divq--;
+	}
+
+	return ((clock * 2 * (divf + 1)) / ((divr + 1) * power)); }
+
+static u64 clk_get_clksrc_hz(struct socfpga_clk_platdata *plat, u32

clksrc_reg,

drivers/clk/altera/clk-dm.c new file +3 -0
+			     u32 main_div, u32 per_div)
+{
+	u64 clock = 0;

drivers/clk/altera/clk-dm.c line 210

Quoted 10 lines
drivers/clk/altera/clk-dm.c new file +10 -0
+	u32 clklsrc = clk_get_5_1_clk_src(plat, clksrc_reg);
+
+	switch (clklsrc) {
+	case CLKMGR_CLKSRC_MAIN:
+		clock = clk_get_pll_output_hz(plat,
+					      CLKMGR_MAINPLL_PLLGLOB,
+					      CLKMGR_MAINPLL_PLLDIV);
+		clock /= 1 + main_div;
+		break;
+

Remove extra empty line. Same for the rest.

[...]

Quoted 4 lines
drivers/clk/altera/clk-dm.c new file +2 -0
+
+#endif /* _CLK_DM_ */
include/dt- renamed from include/dt-bindings/clock/dm-clock.h +0 -0

bindings/clock/dm-clock.h

Check we use same file from Linux, and also macro names.

Quoted 76 lines

new file mode 100644
index 0000000000..d624ac723c

include/dt-bindings/clock/dm-clock.h new file +70 -1
@@ -0,0 +1,71 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020, Intel Corporation  */
+
+#ifndef __DM_CLOCK_H
+#define __DM_CLOCK_H
+
+/* fixed rate clocks */
+#define DM_OSC1					0
+#define DM_CB_INTOSC_HS_DIV2_CLK		1
+#define DM_CB_INTOSC_LS_CLK			2
+#define DM_L4_SYS_FREE_CLK			3
+#define DM_F2S_FREE_CLK				4
+
+/* PLL clocks */
+#define DM_MAIN_PLL_CLK				5
+#define DM_MAIN_PLL_C0_CLK			6
+#define DM_MAIN_PLL_C1_CLK			7
+#define DM_MAIN_PLL_C2_CLK			8
+#define DM_MAIN_PLL_C3_CLK			9
+#define DM_PERIPH_PLL_CLK			10
+#define DM_PERIPH_PLL_C0_CLK			11
+#define DM_PERIPH_PLL_C1_CLK			12
+#define DM_PERIPH_PLL_C2_CLK			13
+#define DM_PERIPH_PLL_C3_CLK			14
+#define DM_MPU_FREE_CLK				15
+#define DM_MPU_CCU_CLK				16
+#define DM_BOOT_CLK				17
+
+/* fixed factor clocks */
+#define DM_L3_MAIN_FREE_CLK			18
+#define DM_NOC_FREE_CLK				19
+#define DM_S2F_USR0_CLK				20
+#define DM_NOC_CLK				21
+#define DM_EMAC_A_FREE_CLK			22
+#define DM_EMAC_B_FREE_CLK			23
+#define DM_EMAC_PTP_FREE_CLK			24
+#define DM_GPIO_DB_FREE_CLK			25
+#define DM_SDMMC_FREE_CLK			26
+#define DM_S2F_USER0_FREE_CLK			27
+#define DM_S2F_USER1_FREE_CLK			28
+#define DM_PSI_REF_FREE_CLK			29
+
+/* Gate clocks */
+#define DM_MPU_CLK				30
+#define DM_MPU_PERIPH_CLK			31
+#define DM_L4_MAIN_CLK				32
+#define DM_L4_MP_CLK				33
+#define DM_L4_SP_CLK				34
+#define DM_CS_AT_CLK				35
+#define DM_CS_TRACE_CLK				36
+#define DM_CS_PDBG_CLK				37
+#define DM_CS_TIMER_CLK				38
+#define DM_S2F_USER0_CLK			39
+#define DM_EMAC0_CLK				40
+#define DM_EMAC1_CLK				41
+#define DM_EMAC2_CLK				42
+#define DM_EMAC_PTP_CLK				43
+#define DM_GPIO_DB_CLK				44
+#define DM_NAND_CLK				45
+#define DM_PSI_REF_CLK				46
+#define DM_S2F_USER1_CLK			47
+#define DM_SDMMC_CLK				48
+#define DM_SPI_M_CLK				49
+#define DM_USB_CLK				50
+#define DM_NAND_X_CLK				51
+#define DM_NAND_ECC_CLK				52
+#define DM_NUM_CLKS				53
+
+#endif	/* __DM_CLOCK_H */
--
Quoted 1 line

2.13.0

Regards
Ley Foon

#21 lore raw

PATCH RESEND v2 11/22 arm: socfpga: dm: Get clock manager base address for Diamond Mesa

In reply to Siew Chin Lim

Add Diamond Mesa 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 ac2b891fad..b63eec779a 100644
@@ -253,6 +253,9 @@ void socfpga_get_managers_addr(void)
 #ifdef CONFIG_TARGET_SOCFPGA_AGILEX
 	ret = socfpga_get_base_addr("intel,agilex-clkmgr",
 				    &socfpga_clkmgr_base);
+#elif defined(CONFIG_TARGET_SOCFPGA_DM)
+	ret = socfpga_get_base_addr("intel,dm-clkmgr",
+				    &socfpga_clkmgr_base);
 #else
 	ret = socfpga_get_base_addr("altr,clk-mgr", &socfpga_clkmgr_base);
 #endif
Signature · 1 line
2.13.0
#22 lore raw

PATCH RESEND v2 12/22 drivers: clk: dm: Add memory clock driver for Diamond Mesa

In reply to Siew Chin Lim

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

---
 drivers/clk/altera/Makefile     |   2 +-
 drivers/clk/altera/clk-mem-dm.c | 135 ++++++++++++++++++++++++++++++++++++++++
 drivers/clk/altera/clk-mem-dm.h |  80 ++++++++++++++++++++++++
 3 files changed, 216 insertions(+), 1 deletion(-)
 create mode 100644 drivers/clk/altera/clk-mem-dm.c
 create mode 100644 drivers/clk/altera/clk-mem-dm.h
drivers/clk/altera/Makefile +1 -1
index 08f16fd7cd..ad4ad5fb3d 100644
@@ -5,4 +5,4 @@
 
 obj-$(CONFIG_TARGET_SOCFPGA_AGILEX) += clk-agilex.o
 obj-$(CONFIG_TARGET_SOCFPGA_ARRIA10) += clk-arria10.o
-obj-$(CONFIG_TARGET_SOCFPGA_DM) += clk-dm.o
+obj-$(CONFIG_TARGET_SOCFPGA_DM) += clk-dm.o clk-mem-dm.o
drivers/clk/altera/clk-mem-dm.c new file +135 -0

135 lines not on this page · raw message

drivers/clk/altera/clk-mem-dm.h new file +80 -0

80 lines not on this page · raw message

Signature · 1 line
2.13.0
#23 lore raw

PATCH RESEND v2 12/22 drivers: clk: dm: Add memory clock driver for Diamond Mesa

Quoted 71 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:44 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 12/22] drivers: clk: dm: Add memory clock driver for Diamond Mesa

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

---
 drivers/clk/altera/Makefile     |   2 +-
 drivers/clk/altera/clk-mem-dm.c | 135
++++++++++++++++++++++++++++++++++++++++
 drivers/clk/altera/clk-mem-dm.h |  80 ++++++++++++++++++++++++
 3 files changed, 216 insertions(+), 1 deletion(-)  create mode 100644

drivers/clk/altera/clk-mem-dm.c create mode 100644 drivers/clk/altera/clk- mem-dm.h

drivers/clk/altera/Makefile index renamed from drivers/clk/altera/Makefile +0 -0

08f16fd7cd..ad4ad5fb3d 100644

drivers/clk/altera/Makefile +1 -1
@@ -5,4 +5,4 @@
 
 obj-$(CONFIG_TARGET_SOCFPGA_AGILEX) += clk-agilex.o
 obj-$(CONFIG_TARGET_SOCFPGA_ARRIA10) += clk-arria10.o
-obj-$(CONFIG_TARGET_SOCFPGA_DM) += clk-dm.o
+obj-$(CONFIG_TARGET_SOCFPGA_DM) += clk-dm.o clk-mem-dm.o
drivers/clk/altera/clk-mem- renamed from drivers/clk/altera/clk-mem-dm.c +0 -0

dm.c new file mode 100644 index 0000000000..827b8d3e95

drivers/clk/altera/clk-mem-dm.c new file +25 -0
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 Intel Corporation <www.intel.com>  */
+
+#include <common.h>
+#include <asm/arch/clock_manager.h>
+#include <asm/io.h>
+#include "clk-mem-dm.h"
+#include <clk-uclass.h>
+#include <dt-bindings/clock/dm-clock.h> #include <dm.h> #include
+<dm/lists.h> #include <dm/util.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct socfpga_mem_clk_platdata {
+	void __iomem *regs;
+};
+
+void clk_mem_wait_for_lock(struct socfpga_mem_clk_platdata *plat, u32
+mask) {
+	u32 inter_val;
+	u32 retry = 0;
+
+	do {
+		inter_val = CM_REG_READL(plat, MEMCLKMGR_STAT) &

mask;

drivers/clk/altera/clk-mem-dm.c new file +1 -0
+

drivers/clk/altera/clk-mem-dm.c line 39

Quoted 10 lines
drivers/clk/altera/clk-mem-dm.c new file +10 -0
+		/* Wait for stable lock */
+		if (inter_val == mask)
+			retry++;
+		else
+			retry = 0;
+
+		if (retry >= 10)
+			return;
+	} while (1);
+}

This can use wait_for_bit_le32()?

Quoted 55 lines
drivers/clk/altera/clk-mem-dm.c new file +6 -0
+
+/*
+ * function to write the bypass register which requires a poll of the
+ * busy bit
+ */
+void clk_mem_write_bypass_mempll(struct socfpga_mem_clk_platdata

*plat,

drivers/clk/altera/clk-mem-dm.c new file +5 -0
+u32 val) {
+	CM_REG_WRITEL(plat, val, MEMCLKMGR_MEMPLL_BYPASS); }
+
+/*
+ * Setup clocks while making no assumptions about previous state of the

clocks.
+ */

drivers/clk/altera/clk-mem-dm.c new file +9 -0
+static void clk_mem_basic_init(struct udevice *dev,
+			       const struct cm_config * const cfg) {
+	struct socfpga_mem_clk_platdata *plat = dev_get_platdata(dev);
+
+	if (!cfg)
+		return;
+
+	/* Put PLLs in bypass */
+	clk_mem_write_bypass_mempll(plat,

MEMCLKMGR_BYPASS_MEMPLL_ALL);

drivers/clk/altera/clk-mem-dm.c new file +7 -0
+
+	/* Put PLLs in Reset */
+	CM_REG_SETBITS(plat, MEMCLKMGR_MEMPLL_PLLCTRL,
+		       MEMCLKMGR_PLLCTRL_BYPASS_MASK);
+
+	/* setup mem PLL */
+	CM_REG_WRITEL(plat, cfg->mem_memdiv,

MEMCLKMGR_MEMPLL_MEMDIV);

drivers/clk/altera/clk-mem-dm.c new file +1 -0
+	CM_REG_WRITEL(plat, cfg->mem_pllglob,

MEMCLKMGR_MEMPLL_PLLGLOB);

drivers/clk/altera/clk-mem-dm.c new file +1 -0
+	CM_REG_WRITEL(plat, cfg->mem_plldiv,

MEMCLKMGR_MEMPLL_PLLDIV);

drivers/clk/altera/clk-mem-dm.c new file +1 -0
+	CM_REG_WRITEL(plat, cfg->mem_plloutdiv,

MEMCLKMGR_MEMPLL_PLLOUTDIV);

drivers/clk/altera/clk-mem-dm.c new file +8 -0
+
+	/* Take PLL out of reset and power up */
+	CM_REG_CLRBITS(plat, MEMCLKMGR_MEMPLL_PLLCTRL,
+		       MEMCLKMGR_PLLCTRL_BYPASS_MASK); }
+
+static int socfpga_mem_clk_enable(struct clk *clk) {
+	const struct cm_config *cm_default_cfg = cm_get_default_config();
+	struct socfpga_mem_clk_platdata *plat = dev_get_platdata(clk-
Quoted 1 line

dev);

drivers/clk/altera/clk-mem-dm.c new file +4 -0
+
+	clk_mem_basic_init(clk->dev, cm_default_cfg);
+
+	clk_mem_wait_for_lock(plat,

MEMCLKMGR_STAT_ALLPLL_LOCKED_MASK);

drivers/clk/altera/clk-mem-dm.c new file +2 -0
+
+	CM_REG_WRITEL(plat, CM_REG_READL(plat,

MEMCLKMGR_MEMPLL_PLLGLOB) |

drivers/clk/altera/clk-mem-dm.c line 97

Quoted 9 lines
drivers/clk/altera/clk-mem-dm.c new file +9 -0
+		      MEMCLKMGR_PLLGLOB_CLR_LOSTLOCK_BYPASS_MASK,
+		      MEMCLKMGR_MEMPLL_PLLGLOB);
+
+	/* Take all PLLs out of bypass */
+	clk_mem_write_bypass_mempll(plat, 0);
+
+	/* Clear the loss of lock bits (write 1 to clear) */
+	CM_REG_CLRBITS(plat, MEMCLKMGR_INTRCLR,
+		       MEMCLKMGR_INTER_MEMPLLLOST_MASK);

This clear the bit, why comment said " write 1 to clear"?

Quoted 43 lines
drivers/clk/altera/clk-mem-dm.c new file +36 -0
+
+	/* Take all ping pong counters out of reset */
+	CM_REG_CLRBITS(plat, MEMCLKMGR_MEMPLL_EXTCNTRST,
+		       MEMCLKMGR_EXTCNTRST_ALLCNTRST);
+
+	return 0;
+}
+
+static int socfpga_mem_clk_ofdata_to_platdata(struct udevice *dev) {
+	struct socfpga_mem_clk_platdata *plat = dev_get_platdata(dev);
+	fdt_addr_t addr;
+
+	addr = devfdt_get_addr(dev);
+	if (addr == FDT_ADDR_T_NONE)
+		return -EINVAL;
+	plat->regs = (void __iomem *)addr;
+
+	return 0;
+}
+
+static struct clk_ops socfpga_mem_clk_ops = {
+	.enable		= socfpga_mem_clk_enable
+};
+
+static const struct udevice_id socfpga_mem_clk_match[] = {
+	{ .compatible = "intel,dm-mem-clkmgr" },
+	{}
+};
+
+U_BOOT_DRIVER(socfpga_dm_mem_clk) = {
+	.name		= "mem-clk-dm",
+	.id		= UCLASS_CLK,
+	.of_match	= socfpga_mem_clk_match,
+	.ops		= &socfpga_mem_clk_ops,
+	.ofdata_to_platdata = socfpga_mem_clk_ofdata_to_platdata,
+	.platdata_auto_alloc_size = sizeof(struct

socfpga_mem_clk_platdata),

drivers/clk/altera/clk-mem-dm.c new file +1 -0
+};
drivers/clk/altera/clk-mem- renamed from drivers/clk/altera/clk-mem-dm.h +0 -0

dm.h new file mode 100644 index 0000000000..bb65351e79

drivers/clk/altera/clk-mem-dm.h line 10

Quoted 10 lines
drivers/clk/altera/clk-mem-dm.h new file +10 -0
@@ -0,0 +1,80 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 Intel Corporation <www.intel.com>  */
+
+#ifndef	_CLK_MEM_DM_
+#define	_CLK_MEM_DM_
+
+/* Clock Manager registers */
+#define MEMCLKMGR_STAT					4
+#define MEMCLKMGR_INTRGEN				8

Change to 0x04 and 0x08. Consistent with the rest.

Quoted 28 lines
drivers/clk/altera/clk-mem-dm.h new file +28 -0
+#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
+
+#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
Quoted 1 line
	0x00000001

Use BIT(n)

Quoted 2 lines

+#define MEMCLKMGR_INTER_MEMPLLLOST_MASK

	0x00000004

Use BIT(n)

Regards
Ley Foon

#24 lore raw

PATCH RESEND v2 13/22 arm: socfpga: Move Stratix10 and Agilex clock manager common code

In reply to Siew Chin Lim

Move duplicated function cm_get_qspi_controller_clk_hz to clock_manager.c.

---
 arch/arm/mach-socfpga/clock_manager.c                  | 10 ++++++++++
 arch/arm/mach-socfpga/clock_manager_agilex.c           |  6 ------
 arch/arm/mach-socfpga/clock_manager_s10.c              |  6 ------
 arch/arm/mach-socfpga/include/mach/clock_manager.h     |  4 ++++
 arch/arm/mach-socfpga/include/mach/clock_manager_s10.h |  1 -
 5 files changed, 14 insertions(+), 13 deletions(-)
arch/arm/mach-socfpga/clock_manager.c +10 -0
index a4a97b6a0f..2d0cc19f7a 100644
@@ -9,6 +9,7 @@
 #include <wait_bit.h>
 #include <asm/io.h>
 #include <asm/arch/clock_manager.h>
+#include <asm/arch/system_manager.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -62,6 +63,15 @@ int set_cpu_clk_info(void)
 	return 0;
 }
 
+#if defined(CONFIG_TARGET_SOCFPGA_SOC64)
+unsigned int cm_get_qspi_controller_clk_hz(void)
+{
+	return readl(socfpga_get_sysmgr_addr() +
+		     SYSMGR_SOC64_BOOT_SCRATCH_COLD0);
+}
+
+#endif
+
 #ifndef CONFIG_SPL_BUILD
 static int do_showclocks(struct cmd_tbl *cmdtp, int flag, int argc,
 			 char *const argv[])
arch/arm/mach-socfpga/clock_manager_agilex.c +0 -6
index 6188a8c3d2..86e00d7611 100644
@@ -64,12 +64,6 @@ unsigned int cm_get_l4_sys_free_clk_hz(void)
 	return cm_get_rate_dm(AGILEX_L4_SYS_FREE_CLK);
 }
 
-u32 cm_get_qspi_controller_clk_hz(void)
-{
-	return readl(socfpga_get_sysmgr_addr() +
-		     SYSMGR_SOC64_BOOT_SCRATCH_COLD0);
-}
-
 void cm_print_clock_quick_summary(void)
 {
 	printf("MPU       %10d kHz\n",
arch/arm/mach-socfpga/clock_manager_s10.c +0 -6
index 431794e082..ef62c56ad9 100644
@@ -383,12 +383,6 @@ unsigned int cm_get_l4_sp_clk_hz(void)
 	return clock;
 }
 
-unsigned int cm_get_qspi_controller_clk_hz(void)
-{
-	return readl(socfpga_get_sysmgr_addr() +
-		     SYSMGR_SOC64_BOOT_SCRATCH_COLD0);
-}
-
 unsigned int cm_get_spi_controller_clk_hz(void)
 {
 	u32 clock = cm_get_l3_main_clk_hz();
arch/arm/mach-socfpga/include/mach/clock_manager.h +4 -0
index 1f734bcd65..0f0cb230fa 100644
@@ -12,6 +12,10 @@ 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);
+
+#if defined(CONFIG_TARGET_SOCFPGA_SOC64)
+unsigned int cm_get_qspi_controller_clk_hz(void);
+#endif
 #endif
 
 #if defined(CONFIG_TARGET_SOCFPGA_GEN5)
arch/arm/mach-socfpga/include/mach/clock_manager_s10.h +0 -1
index cb7923baef..98c3bf1b03 100644
@@ -15,7 +15,6 @@ 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);
-unsigned int cm_get_qspi_controller_clk_hz(void);
 unsigned int cm_get_spi_controller_clk_hz(void);
 
 struct cm_config {
Signature · 1 line
2.13.0
#25 lore raw

PATCH RESEND v2 13/22 arm: socfpga: Move Stratix10 and Agilex clock manager common code

Quoted 101 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:45 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 13/22] arm: socfpga: Move Stratix10 and Agilex clock manager common code

Move duplicated function cm_get_qspi_controller_clk_hz to clock_manager.c.

---
 arch/arm/mach-socfpga/clock_manager.c                  | 10 ++++++++++
 arch/arm/mach-socfpga/clock_manager_agilex.c           |  6 ------
 arch/arm/mach-socfpga/clock_manager_s10.c              |  6 ------
 arch/arm/mach-socfpga/include/mach/clock_manager.h     |  4 ++++
 arch/arm/mach-socfpga/include/mach/clock_manager_s10.h |  1 -
 5 files changed, 14 insertions(+), 13 deletions(-)
arch/arm/mach- renamed from arch/arm/mach-socfpga/clock_manager.c +0 -0

socfpga/clock_manager.c
index a4a97b6a0f..2d0cc19f7a 100644

arch/arm/mach-socfpga/clock_manager.c +9 -0
@@ -9,6 +9,7 @@
 #include <wait_bit.h>
 #include <asm/io.h>
 #include <asm/arch/clock_manager.h>
+#include <asm/arch/system_manager.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -62,6 +63,15 @@ int set_cpu_clk_info(void)
 	return 0;
 }
 
+#if defined(CONFIG_TARGET_SOCFPGA_SOC64)
+unsigned int cm_get_qspi_controller_clk_hz(void)
+{
+	return readl(socfpga_get_sysmgr_addr() +
+		     SYSMGR_SOC64_BOOT_SCRATCH_COLD0); }
+
+#endif
+
 #ifndef CONFIG_SPL_BUILD
 static int do_showclocks(struct cmd_tbl *cmdtp, int flag, int argc,
 			 char *const argv[])
arch/arm/mach-socfpga/clock_manager_agilex.c +0 -6
index 6188a8c3d2..86e00d7611 100644
@@ -64,12 +64,6 @@ unsigned int cm_get_l4_sys_free_clk_hz(void)
 	return cm_get_rate_dm(AGILEX_L4_SYS_FREE_CLK);
 }
 
-u32 cm_get_qspi_controller_clk_hz(void)
-{
-	return readl(socfpga_get_sysmgr_addr() +
-		     SYSMGR_SOC64_BOOT_SCRATCH_COLD0);
-}
-
 void cm_print_clock_quick_summary(void)
 {
 	printf("MPU       %10d kHz\n",
arch/arm/mach-socfpga/clock_manager_s10.c +0 -6
index 431794e082..ef62c56ad9 100644
@@ -383,12 +383,6 @@ unsigned int cm_get_l4_sp_clk_hz(void)
 	return clock;
 }
 
-unsigned int cm_get_qspi_controller_clk_hz(void)
-{
-	return readl(socfpga_get_sysmgr_addr() +
-		     SYSMGR_SOC64_BOOT_SCRATCH_COLD0);
-}
-
 unsigned int cm_get_spi_controller_clk_hz(void)
 {
 	u32 clock = cm_get_l3_main_clk_hz();
arch/arm/mach-socfpga/include/mach/clock_manager.h +0 -0
index 1f734bcd65..0f0cb230fa 100644
@@ -12,6 +12,10 @@ 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);

arch/arm/mach-socfpga/include/mach/clock_manager.h phys_addr_t socfpga_get_clkmgr_addr(void); · line 19

Quoted 5 lines
arch/arm/mach-socfpga/include/mach/clock_manager.h +4 -0
+
+#if defined(CONFIG_TARGET_SOCFPGA_SOC64)
+unsigned int cm_get_qspi_controller_clk_hz(void);
+#endif
 #endif

Cyclone 5 and Arria 10 also have this function.
This is also define in include/configs/*.h. Check where should add it.

Regards
Ley Foon

#26 lore raw

PATCH RESEND v2 14/22 arm: socfpga: Changed to store QSPI reference clock in kHz

In reply to Siew Chin Lim

Changed to store QSPI reference clock in kHz instead of Hz in boot scratch cold0 register for Stratix10 and Agilex.

This patch is in preparation for Diamond Mesa SDRAM driver support. Reserved 4 bits for Diamond Mesa SDRAM driver, and there will be 28 bits to store QSPI reference clock. Due to limited bits, QSPI reference clock frequency is converted to kHz from Hz.

---
 arch/arm/mach-socfpga/clock_manager.c              |  5 ++--
 .../include/mach/system_manager_soc64.h            | 12 +++++++++-
 arch/arm/mach-socfpga/mailbox_s10.c                | 28 +++++++++++++++++++---
 3 files changed, 39 insertions(+), 6 deletions(-)
arch/arm/mach-socfpga/clock_manager.c +3 -2
index 2d0cc19f7a..8299d0956d 100644
@@ -66,8 +66,9 @@ int set_cpu_clk_info(void)
 #if defined(CONFIG_TARGET_SOCFPGA_SOC64)
 unsigned int cm_get_qspi_controller_clk_hz(void)
 {
-	return readl(socfpga_get_sysmgr_addr() +
-		     SYSMGR_SOC64_BOOT_SCRATCH_COLD0);
+	return (readl(socfpga_get_sysmgr_addr() +
+		     SYSMGR_SOC64_BOOT_SCRATCH_COLD0) &
+		     SYSMGR_SCRATCH_REG_0_QSPI_REFCLK_MASK) * 1000;
 }
 
 #endif
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +11 -1
index 1eb8e7a904..1e2289e5f8 100644
@@ -42,7 +42,10 @@ void populate_sysmgr_pinmux(void);
 #define SYSMGR_SOC64_GPO			0xe4
 #define SYSMGR_SOC64_GPI			0xe8
 #define SYSMGR_SOC64_MPU			0xf0
-/* store qspi ref clock */
+/*
+ * Bits[31:28] reserved for DM DDR retention, bits[27:0] reserved for SOC 64-bit
+ * storing qspi ref clock(kHz)
+ */
 #define SYSMGR_SOC64_BOOT_SCRATCH_COLD0		0x200
 /* store osc1 clock freq */
 #define SYSMGR_SOC64_BOOT_SCRATCH_COLD1		0x204
@@ -85,6 +88,13 @@ void populate_sysmgr_pinmux(void);
 #define SYSMGR_SOC64_HPS_OSC_CLK		0x1358
 #define SYSMGR_SOC64_IODELAY0			0x1400
 
+/*
+ * Bits for SYSMGR_SOC64_BOOT_SCRATCH_COLD0
+ * Bits[31:28] reserved for DM DDR retention, bits[27:0] reserved for SOC 64-bit
+ * storing qspi ref clock(kHz)
+ */
+#define SYSMGR_SCRATCH_REG_0_QSPI_REFCLK_MASK		GENMASK(27, 0)
+
 #define SYSMGR_SDMMC				SYSMGR_SOC64_SDMMC
 
 #define SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGPINMUX	BIT(0)
arch/arm/mach-socfpga/mailbox_s10.c +25 -3
index 429444f069..2e43131c5d 100644
@@ -359,7 +359,7 @@ int mbox_qspi_open(void)
 {
 	int ret;
 	u32 resp_buf[1];
-	u32 resp_buf_len;
+	u32 resp_buf_len, temp;
 
 	ret = mbox_send_cmd(MBOX_ID_UBOOT, MBOX_QSPI_OPEN, MBOX_CMD_DIRECT,
 			    0, NULL, 0, 0, NULL);
@@ -384,8 +384,30 @@ int mbox_qspi_open(void)
 		goto error;
 
 	/* We are getting QSPI ref clock and set into sysmgr boot register */
-	printf("QSPI: Reference clock at %d Hz\n", resp_buf[0]);
-	writel(resp_buf[0],
+	/*
+	 * Only clock freq in kHz degree is accepted due to limited bits[27:0]
+	 * is reserved for storing the QSPI clock freq into boot scratch cold0
+	 * register
+	 */
+	if (resp_buf[0] < 1000) {
+		ret = -EINVAL;
+		goto error;
+	} else {
+		resp_buf[0] /= 1000;
+	}
+
+	printf("QSPI: Reference clock@%d kHz\n", resp_buf[0]);
+
+	/*
+	 * DDR retention bit, SHA comparison bit and reset type bits sharing the
+	 * same scratch register in DM, ensure the content inside register is
+	 * not overwritten by QSPI ref clock(kHz)
+	 */
+	temp = readl(socfpga_get_sysmgr_addr() +
+		    SYSMGR_SOC64_BOOT_SCRATCH_COLD0) &
+		    ~(SYSMGR_SCRATCH_REG_0_QSPI_REFCLK_MASK);
+
+	writel((resp_buf[0] & SYSMGR_SCRATCH_REG_0_QSPI_REFCLK_MASK) | temp,
 	       socfpga_get_sysmgr_addr() + SYSMGR_SOC64_BOOT_SCRATCH_COLD0);
 
 	return 0;
Signature · 1 line
2.13.0
#27 lore raw

PATCH RESEND v2 14/22 arm: socfpga: Changed to store QSPI reference clock in kHz

Quoted 57 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:45 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 14/22] arm: socfpga: Changed to store QSPI reference clock in kHz

Changed to store QSPI reference clock in kHz instead of Hz in boot scratch cold0 register for Stratix10 and Agilex.

This patch is in preparation for Diamond Mesa SDRAM driver support. Reserved 4 bits for Diamond Mesa SDRAM driver, and there will be 28 bits to store QSPI reference clock.
Due to limited bits, QSPI reference clock frequency is converted to kHz from Hz.

---
 arch/arm/mach-socfpga/clock_manager.c              |  5 ++--
 .../include/mach/system_manager_soc64.h            | 12 +++++++++-
 arch/arm/mach-socfpga/mailbox_s10.c                | 28
+++++++++++++++++++---
 3 files changed, 39 insertions(+), 6 deletions(-)
arch/arm/mach- renamed from arch/arm/mach-socfpga/clock_manager.c +0 -0

socfpga/clock_manager.c
index 2d0cc19f7a..8299d0956d 100644

arch/arm/mach-socfpga/clock_manager.c +3 -2
@@ -66,8 +66,9 @@ int set_cpu_clk_info(void)  #if
 defined(CONFIG_TARGET_SOCFPGA_SOC64)
 unsigned int cm_get_qspi_controller_clk_hz(void)
 {
-	return readl(socfpga_get_sysmgr_addr() +
-		     SYSMGR_SOC64_BOOT_SCRATCH_COLD0);
+	return (readl(socfpga_get_sysmgr_addr() +
+		     SYSMGR_SOC64_BOOT_SCRATCH_COLD0) &
+		     SYSMGR_SCRATCH_REG_0_QSPI_REFCLK_MASK) * 1000;
 }
 
 #endif
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +0 -0
index 1eb8e7a904..1e2289e5f8 100644

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h void populate_sysmgr_pinmux(void); · line 48

Quoted 8 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -1
@@ -42,7 +42,10 @@ void populate_sysmgr_pinmux(void);
 #define SYSMGR_SOC64_GPO			0xe4
 #define SYSMGR_SOC64_GPI			0xe8
 #define SYSMGR_SOC64_MPU			0xf0
-/* store qspi ref clock */
+/*
+ * Bits[31:28] reserved for DM DDR retention, bits[27:0] reserved for
+SOC 64-bit
+ * storing qspi ref clock(kHz)

Space after "(".

Quoted 58 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +9 -0
+ */
 #define SYSMGR_SOC64_BOOT_SCRATCH_COLD0		0x200
 /* store osc1 clock freq */
 #define SYSMGR_SOC64_BOOT_SCRATCH_COLD1		0x204
@@ -85,6 +88,13 @@ void populate_sysmgr_pinmux(void);
 #define SYSMGR_SOC64_HPS_OSC_CLK		0x1358
 #define SYSMGR_SOC64_IODELAY0			0x1400
 
+/*
+ * Bits for SYSMGR_SOC64_BOOT_SCRATCH_COLD0
+ * Bits[31:28] reserved for DM DDR retention, bits[27:0] reserved for
+SOC 64-bit
+ * storing qspi ref clock(kHz)
+ */
+#define SYSMGR_SCRATCH_REG_0_QSPI_REFCLK_MASK
 	GENMASK(27, 0)
+
 #define SYSMGR_SDMMC

SYSMGR_SOC64_SDMMC

#define SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGPINMUX BIT(0)

arch/arm/mach- renamed from arch/arm/mach-socfpga/mailbox_s10.c +0 -0

socfpga/mailbox_s10.c
index 429444f069..2e43131c5d 100644

arch/arm/mach-socfpga/mailbox_s10.c +17 -3
@@ -359,7 +359,7 @@ int mbox_qspi_open(void)  {
 	int ret;
 	u32 resp_buf[1];
-	u32 resp_buf_len;
+	u32 resp_buf_len, temp;
 
 	ret = mbox_send_cmd(MBOX_ID_UBOOT, MBOX_QSPI_OPEN,
 MBOX_CMD_DIRECT,
 			    0, NULL, 0, 0, NULL);
@@ -384,8 +384,30 @@ int mbox_qspi_open(void)
 		goto error;
 
 	/* We are getting QSPI ref clock and set into sysmgr boot register */
-	printf("QSPI: Reference clock at %d Hz\n", resp_buf[0]);
-	writel(resp_buf[0],
+	/*
+	 * Only clock freq in kHz degree is accepted due to limited bits[27:0]
+	 * is reserved for storing the QSPI clock freq into boot scratch cold0
+	 * register
+	 */
+	if (resp_buf[0] < 1000) {
+		ret = -EINVAL;
+		goto error;
+	} else {
+		resp_buf[0] /= 1000;
+	}
+
+	printf("QSPI: Reference clock at %d kHz\n", resp_buf[0]);
+
+	/*
+	 * DDR retention bit, SHA comparison bit and reset type bits sharing

the

arch/arm/mach-socfpga/mailbox_s10.c int mbox_qspi_open(void)

Quoted 8 lines
arch/arm/mach-socfpga/mailbox_s10.c +8 -0
+	 * same scratch register in DM, ensure the content inside register is
+	 * not overwritten by QSPI ref clock(kHz)
+	 */
+	temp = readl(socfpga_get_sysmgr_addr() +
+		    SYSMGR_SOC64_BOOT_SCRATCH_COLD0) &
+		    ~(SYSMGR_SCRATCH_REG_0_QSPI_REFCLK_MASK);
+
+	writel((resp_buf[0] &

Can help helper function to read and write boot scratch register.

Regards
Ley Foon

#28 lore raw

PATCH RESEND v2 15/22 arm: socfpga: dm: Add clock manager for Diamond Mesa

In reply to Siew Chin Lim

Add clock manager for Diamond Mesa.

---
 arch/arm/mach-socfpga/clock_manager_dm.c           | 79 ++++++++++++++++++++++
 arch/arm/mach-socfpga/include/mach/clock_manager.h |  2 +
 .../mach-socfpga/include/mach/clock_manager_dm.h   | 14 ++++
 3 files changed, 95 insertions(+)
 create mode 100644 arch/arm/mach-socfpga/clock_manager_dm.c
 create mode 100644 arch/arm/mach-socfpga/include/mach/clock_manager_dm.h
arch/arm/mach-socfpga/clock_manager_dm.c new file +79 -0
new file mode 100644
index 0000000000..cdf096cd8b
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 Intel Corporation <www.intel.com>
+ *
+ */
+
+#include <clk.h>
+#include <common.h>
+#include <dm.h>
+#include <malloc.h>
+#include <asm/arch/clock_manager.h>
+#include <asm/arch/system_manager.h>
+#include <asm/io.h>
+#include <dt-bindings/clock/dm-clock.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static ulong cm_get_rate_dm(u32 id)
+{
+	struct udevice *dev;
+	struct clk clk;
+	ulong rate;
+	int ret;
+
+	ret = uclass_get_device_by_driver(UCLASS_CLK,
+					  DM_GET_DRIVER(socfpga_dm_clk),
+					  &dev);
+	if (ret)
+		return 0;
+
+	clk.id = id;
+	ret = clk_request(dev, &clk);
+	if (ret < 0)
+		return 0;
+
+	rate = clk_get_rate(&clk);
+
+	clk_free(&clk);
+
+	if ((rate == (unsigned long)-ENXIO) ||
+	    (rate == (unsigned long)-EIO)) {
+		debug("%s id %u: clk_get_rate err: %ld\n",
+		      __func__, id, rate);
+		return 0;
+	}
+
+	return rate;
+}
+
+static u32 cm_get_rate_dm_khz(u32 id)
+{
+	return cm_get_rate_dm(id) / 1000;
+}
+
+unsigned long cm_get_mpu_clk_hz(void)
+{
+	return cm_get_rate_dm(DM_MPU_CLK);
+}
+
+unsigned int cm_get_l4_sys_free_clk_hz(void)
+{
+	return cm_get_rate_dm(DM_L4_SYS_FREE_CLK);
+}
+
+void cm_print_clock_quick_summary(void)
+{
+	printf("MPU       %10d kHz\n",
+	       cm_get_rate_dm_khz(DM_MPU_CLK));
+	printf("L4 Main	    %8d kHz\n",
+	       cm_get_rate_dm_khz(DM_L4_MAIN_CLK));
+	printf("L4 sys free %8d kHz\n",
+	       cm_get_rate_dm_khz(DM_L4_SYS_FREE_CLK));
+	printf("L4 MP       %8d kHz\n",
+	       cm_get_rate_dm_khz(DM_L4_MP_CLK));
+	printf("L4 SP       %8d kHz\n",
+	       cm_get_rate_dm_khz(DM_L4_SP_CLK));
+	printf("SDMMC       %8d kHz\n",
+	       cm_get_rate_dm_khz(DM_SDMMC_CLK));
+}
arch/arm/mach-socfpga/include/mach/clock_manager.h +2 -0
index 0f0cb230fa..a164f47bda 100644
@@ -26,6 +26,8 @@ unsigned int cm_get_qspi_controller_clk_hz(void);
 #include <asm/arch/clock_manager_s10.h>
 #elif defined(CONFIG_TARGET_SOCFPGA_AGILEX)
 #include <asm/arch/clock_manager_agilex.h>
+#elif defined(CONFIG_TARGET_SOCFPGA_DM)
+#include <asm/arch/clock_manager_dm.h>
 #endif
 
 #endif /* _CLOCK_MANAGER_H_ */
arch/arm/mach-socfpga/include/mach/clock_manager_dm.h new file +14 -0
new file mode 100644
index 0000000000..a355fda692
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 Intel Corporation <www.intel.com>
+ */
+
+#ifndef _CLOCK_MANAGER_DM_
+#define _CLOCK_MANAGER_DM_
+
+unsigned long cm_get_mpu_clk_hz(void);
+
+#include <asm/arch/clock_manager_soc64.h>
+#include "../../../../../drivers/clk/altera/clk-dm.h"
+
+#endif /* _CLOCK_MANAGER_DM_ */
Signature · 1 line
2.13.0
#29 lore raw

PATCH RESEND v2 15/22 arm: socfpga: dm: Add clock manager for Diamond Mesa

Quoted 40 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:45 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 15/22] arm: socfpga: dm: Add clock manager for Diamond Mesa

Add clock manager for Diamond Mesa.

---
 arch/arm/mach-socfpga/clock_manager_dm.c           | 79
++++++++++++++++++++++
 arch/arm/mach-socfpga/include/mach/clock_manager.h |  2 +
 .../mach-socfpga/include/mach/clock_manager_dm.h   | 14 ++++
 3 files changed, 95 insertions(+)
 create mode 100644 arch/arm/mach-socfpga/clock_manager_dm.c
 create mode 100644 arch/arm/mach-

socfpga/include/mach/clock_manager_dm.h

arch/arm/mach-socfpga/clock_manager_dm.c new file +4 -0
new file mode 100644
index 0000000000..cdf096cd8b
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 Intel Corporation <www.intel.com>
+ *

arch/arm/mach-socfpga/clock_manager_dm.c line 14

Quoted 10 lines
arch/arm/mach-socfpga/clock_manager_dm.c new file +10 -0
+ */
+
+#include <clk.h>
+#include <common.h>
+#include <dm.h>
+#include <malloc.h>
+#include <asm/arch/clock_manager.h>
+#include <asm/arch/system_manager.h>
+#include <asm/io.h>
+#include <dt-bindings/clock/dm-clock.h>

Try to sort alphanumerical order.

[...]

Quoted 21 lines
arch/arm/mach-socfpga/include/mach/clock_manager.h +2 -0
index 0f0cb230fa..a164f47bda 100644
@@ -26,6 +26,8 @@ unsigned int cm_get_qspi_controller_clk_hz(void);
 #include <asm/arch/clock_manager_s10.h>  #elif
 defined(CONFIG_TARGET_SOCFPGA_AGILEX)
 #include <asm/arch/clock_manager_agilex.h>
+#elif defined(CONFIG_TARGET_SOCFPGA_DM) #include
+<asm/arch/clock_manager_dm.h>
 #endif
 
 #endif /* _CLOCK_MANAGER_H_ */
arch/arm/mach-socfpga/include/mach/clock_manager_dm.h new file +0 -0
new file mode 100644
index 0000000000..a355fda692

arch/arm/mach-socfpga/include/mach/clock_manager_dm.h line 8

Quoted 8 lines
arch/arm/mach-socfpga/include/mach/clock_manager_dm.h new file +8 -0
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 Intel Corporation <www.intel.com>  */
+
+#ifndef _CLOCK_MANAGER_DM_
+#define _CLOCK_MANAGER_DM_
+
+unsigned long cm_get_mpu_clk_hz(void);

This can move to clock_manager.h, since all devices have this.

Regards
Ley Foon

#30 lore raw

PATCH RESEND v2 16/22 ddr: altera: dm: Add SDRAM driver for Diamond Mesa

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 Quartus.

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.

---
 arch/arm/mach-socfpga/include/mach/firewall.h      |    1 +
 .../include/mach/system_manager_soc64.h            |    4 +
 drivers/ddr/altera/Makefile                        |    1 +
 drivers/ddr/altera/sdram_dm.c                      | 1294 ++++++++++++++++++++
 drivers/ddr/altera/sdram_soc64.c                   |    6 +
 5 files changed, 1306 insertions(+)
 create mode 100644 drivers/ddr/altera/sdram_dm.c
arch/arm/mach-socfpga/include/mach/firewall.h +1 -0
index a2face0570..06c941937b 100644
@@ -121,6 +121,7 @@ struct socfpga_firwall_l4_sys {
 #define FW_MPU_DDR_SCR_MPUREGION0ADDR_LIMITEXT		0x1c
 #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
 
 /* Firewall MPFE SCR Registers */
 #define FW_MPFE_SCR_HMC					0x00
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
index 1e2289e5f8..4fc1a158b7 100644
@@ -94,6 +94,10 @@ void populate_sysmgr_pinmux(void);
  * storing qspi ref clock(kHz)
  */
 #define SYSMGR_SCRATCH_REG_0_QSPI_REFCLK_MASK		GENMASK(27, 0)
+#define SYSMGR_SCRATCH_REG_0_DDR_RETENTION_MASK		BIT(31)
+#define SYSMGR_SCRATCH_REG_0_DDR_SHA_MASK		BIT(30)
+#define SYSMGR_SCRATCH_REG_0_DDR_RESET_TYPE_MASK	(BIT(29) | BIT(28))
+#define SYSMGR_SCRATCH_REG_0_DDR_RESET_TYPE_SHIFT	28
 
 #define SYSMGR_SDMMC				SYSMGR_SOC64_SDMMC
 
drivers/ddr/altera/Makefile +1 -0
index 39dfee5d5a..0f3b786c43 100644
@@ -11,4 +11,5 @@ 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_DM) += sdram_soc64.o sdram_dm.o
 endif
drivers/ddr/altera/sdram_dm.c new file +1294 -0

1,294 lines not on this page · raw message

drivers/ddr/altera/sdram_soc64.c +6 -0
index 8cb75fe02a..32a16ccdc7 100644
@@ -235,6 +235,11 @@ static int altera_sdram_ofdata_to_platdata(struct udevice *dev)
 	struct altera_sdram_platdata *plat = dev->platdata;
 	fdt_addr_t addr;
 
+	/* These regs info are part of DDR handoff in bitstream */
+#ifdef CONFIG_TARGET_SOCFPGA_DM
+	return 0;
+#endif
+
 	addr = dev_read_addr_index(dev, 0);
 	if (addr == FDT_ADDR_T_NONE)
 		return -EINVAL;
@@ -295,6 +300,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-dm" },
 	{ /* sentinel */ }
 };
 
Signature · 1 line
2.13.0
#31 lore raw

PATCH RESEND v2 16/22 ddr: altera: dm: Add SDRAM driver for Diamond Mesa

Quoted 43 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:45 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 16/22] ddr: altera: dm: Add SDRAM driver for Diamond Mesa

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 Quartus.

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.

---
 arch/arm/mach-socfpga/include/mach/firewall.h      |    1 +
 .../include/mach/system_manager_soc64.h            |    4 +
 drivers/ddr/altera/Makefile                        |    1 +
 drivers/ddr/altera/sdram_dm.c                      | 1294 ++++++++++++++++++++
 drivers/ddr/altera/sdram_soc64.c                   |    6 +
 5 files changed, 1306 insertions(+)
 create mode 100644 drivers/ddr/altera/sdram_dm.c

[...]

Quoted 9 lines

/* Firewall MPFE SCR Registers */
#define FW_MPFE_SCR_HMC 0x00

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +0 -0
index 1e2289e5f8..4fc1a158b7 100644

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h void populate_sysmgr_pinmux(void); · line 102

Quoted 9 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +3 -0
@@ -94,6 +94,10 @@ void populate_sysmgr_pinmux(void);
  * storing qspi ref clock(kHz)
  */
 #define SYSMGR_SCRATCH_REG_0_QSPI_REFCLK_MASK
 	GENMASK(27, 0)
+#define SYSMGR_SCRATCH_REG_0_DDR_RETENTION_MASK
 	BIT(31)
+#define SYSMGR_SCRATCH_REG_0_DDR_SHA_MASK		BIT(30)
+#define SYSMGR_SCRATCH_REG_0_DDR_RESET_TYPE_MASK	(BIT(29) |
 BIT(28))

Change the order, from bit-28 to 31.

Quoted 5 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +1 -0
+#define SYSMGR_SCRATCH_REG_0_DDR_RESET_TYPE_SHIFT	28

#define SYSMGR_SDMMC
SYSMGR_SOC64_SDMMC

[...]

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 5 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +5 -0
+#define TIMEOUT_200MS     200
+#define TIMEOUT_5000MS    5000
+
+/* DDR4 umctl2 */
+#define DDR4_STAT_OFFSET		0x4

Change to 0x04.

Quoted 11 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +10 -0
+#define DDR4_STAT_SELFREF_TYPE		(BIT(5) | BIT(4))
+#define DDR4_STAT_SELFREF_TYPE_SHIFT	4
+#define DDR4_STAT_OPERATING_MODE	(BIT(2) | BIT(1) | BIT(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		(BIT(5) | BIT(4))
+#define DDR4_MRCTRL0_MR_RANK_SHIFT	4
+#define DDR4_MRCTRL0_MR_ADDR		(BIT(15) | BIT(14) | BIT(13) |

BIT(12))

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 5 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +5 -0
+#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

Follow other drivers use small letter for hex value. Check all in this file.

Quoted 106 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +20 -0
+
+#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		(BIT(6) | BIT(5) |

BIT(4))

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +85 -0
+#define DDR4_RFSHCTL3_REFRESH_MODE_SHIFT	4
+
+#define DDR4_ECCCFG0_OFFSET		0x70
+#define DDR4_ECC_MODE			(BIT(2) | BIT(1) | BIT(0))
+#define DDR4_DIS_SCRUB			BIT(4)
+
+#define DDR4_CRCPARCTL1_OFFSET			0x04
+#define DDR4_CRCPARCTL1_CRC_PARITY_RETRY_ENABLE	BIT(8)
+#define DDR4_CRCPARCTL1_ALERT_WAIT_FOR_SW	BIT(9)
+
+#define DDR4_CRCPARCTL0_OFFSET			0xC0
+#define DDR4_CRCPARCTL0_DFI_ALERT_ERR_INIT_CLR	BIT(1)
+
+#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_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 DDR_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_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_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

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 10 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +10 -0
+#define DDR_PHY_UCCLKHCLKENABLES_OFFSET		0x180100
+
+#define DDR_PHY_APBONLY0_OFFSET			0x1A0000
+#define DDR_PHY_MICROCONTMUXSEL			BIT(0)
+
+#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

These use prefix "DDR" instead of "DDR4". Is it intended?

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 7 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +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

Change to prefix OPM_.

Quoted 12 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +12 -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

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 10 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +10 -0
+#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)

Try change all the display of macro value aligned to each other's.

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 2 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +2 -0
+
+#ifdef CONFIG_TARGET_SOCFPGA_DM

This file only get compiled when CONFIG_TARGET_SOCFPGA_DM is enabled. No need add this.

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 3 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +3 -0
+#define PSI_LL_SLAVE_APS_PER_OFST	0x00000000
+#define alt_write_hword(addr, val)	(writew(val, addr))
+#define SDM_HPS_PERI_ADDR_TRANSLATION(_HPS_OFFSET_) \

Don't use capital letter for _HPS_OFFSET_, and remove __.

Quoted 9 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+	(PSI_LL_SLAVE_APS_PER_OFST + (_HPS_OFFSET_))
+#define DDR_PHY_BASE	0xF8800000
+#define SNPS_PHY_TRANSLATION(_PHY_OFFSET_) \
+	(PSI_LL_SLAVE_APS_PER_OFST + ((DDR_PHY_BASE + ((_PHY_OFFSET_)

<< 1))))

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +2 -0
+#define dwc_ddrphy_apb_wr(dest, data) \
+	alt_write_hword(SNPS_PHY_TRANSLATION(dest), data) #define

b_max 1
+#define timing_group_max 4 #endif

Use capital letter for macros.

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 7 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +7 -0
+
+/* Reset type */
+enum reset_type {
+	por_reset,
+	warm_reset,
+	cold_reset,
+	rsu_reset

Use capital letter for enum.

Quoted 26 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +25 -0
+};
+
+/* DDR handoff structure */
+struct ddr_handoff {
+	phys_addr_t mem_reset_base;
+	phys_addr_t umctl2_handoff_base;
+	phys_addr_t umctl2_base;
+	size_t umctl2_total_length;
+	size_t umctl2_handoff_length;
+	phys_addr_t phy_handoff_base;
+	phys_addr_t phy_base;
+	size_t phy_total_length;
+	size_t phy_handoff_length;
+	phys_addr_t phy_engine_handoff_base;
+	size_t phy_engine_total_length;
+	size_t phy_engine_handoff_length;
+};
+
+static bool is_ddr_retention_enabled(u32 boot_scratch_cold0_reg) {
+	return boot_scratch_cold0_reg &
+	       SYSMGR_SCRATCH_REG_0_DDR_RETENTION_MASK;
+}
+
+static bool is_ddr_bitstream_sha_matching(u32 boot_scratch_cold0_reg) {
+	return boot_scratch_cold0_reg &

SYSMGR_SCRATCH_REG_0_DDR_SHA_MASK;

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 9 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +9 -0
+}
+
+static enum reset_type get_reset_type(u32 boot_scratch_cold0_reg) {
+	return (boot_scratch_cold0_reg &
+		SYSMGR_SCRATCH_REG_0_DDR_RESET_TYPE_MASK) >>
+		SYSMGR_SCRATCH_REG_0_DDR_RESET_TYPE_SHIFT;
+}
+
+static bool is_ddr_init_skipped(void)

Can invert the logic? Return true if need do the DDR init? Easier to read the code.

Quoted 21 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +21 -0
+{
+	u32 reg = readl(socfpga_get_sysmgr_addr() +
+			SYSMGR_SOC64_BOOT_SCRATCH_COLD0);
+
+	if (get_reset_type(reg) == por_reset) {
+		debug("%s: POR reset is triggered\n", __func__);
+		debug("%s: DDR init is required\n", __func__);
+		return false;
+	}
+
+	if (get_reset_type(reg) == warm_reset) {
+		debug("%s: Warm reset is triggered\n", __func__);
+		debug("%s: DDR init is skipped\n", __func__);
+		return true;
+	}
+
+	if ((get_reset_type(reg) == cold_reset) ||
+	    (get_reset_type(reg) == rsu_reset)) {
+		debug("%s: Cold/RSU reset is triggered\n", __func__);
+
+		if (is_ddr_retention_enabled(reg)) {

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 10 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +10 -0
+			debug("%s: DDR retention bit is set\n", __func__);
+
+			if (is_ddr_bitstream_sha_matching(reg)) {
+				debug("%s: Matching in DDR bistream\n",
+				      __func__);
+				debug("%s: DDR init is skipped\n", __func__);
+				return true;
+			}
+
+			debug("%s: Mismatch in DDR bistream\n", __func__);

SHA mismatch.

Quoted 106 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +15 -0
+		}
+	}
+
+	debug("%s: DDR init is required\n", __func__);
+	return false;
+}
+
+static int clr_ca_parity_error_status(struct ddr_handoff
+*ddr_handoff_info) {
+	int ret;
+
+	debug("%s: Clear C/A parity error status in MR5[4]\n", __func__);
+
+	/* Set mode register MRS */
+	clrbits_le32(ddr_handoff_info->umctl2_base +

DDR4_MRCTRL0_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+		     DDR4_MRCTRL0_MPR_EN);
+
+	/* Set mode register to write operation */
+	setbits_le32(ddr_handoff_info->umctl2_base +

DDR4_MRCTRL0_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+		     DDR4_MRCTRL0_MR_TYPE);
+
+	/* Set the address of mode rgister to 0x101(MR5) */
+	setbits_le32(ddr_handoff_info->umctl2_base +

DDR4_MRCTRL0_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +5 -0
+		     (MR5 << DDR4_MRCTRL0_MR_ADDR_SHIFT) &
+		     DDR4_MRCTRL0_MR_ADDR);
+
+	/* Set MR rank to rank 1 */
+	setbits_le32(ddr_handoff_info->umctl2_base +

DDR4_MRCTRL0_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +5 -0
+		     (RANK1 << DDR4_MRCTRL0_MR_RANK_SHIFT) &
+		     DDR4_MRCTRL0_MR_RANK);
+
+	/* Clear C/A parity error status in MR5[4] */
+	clrbits_le32(ddr_handoff_info->umctl2_base +

DDR4_MRCTRL1_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+		     MR5_BIT4);
+
+	/* Trigger mode register read or write operation */
+	setbits_le32(ddr_handoff_info->umctl2_base +

DDR4_MRCTRL0_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+		     DDR4_MRCTRL0_MR_WR);
+
+	/* Wait for retry done */
+	ret = wait_for_bit_le32((const void *)(ddr_handoff_info-
Quoted 1 line

umctl2_base +

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +1 -0
+				DDR4_MRSTAT_OFFSET),

DDR4_MRSTAT_MR_WR_BUSY,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +17 -0
+				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 ddr4_retry_software_sequence(struct ddr_handoff
+*ddr_handoff_info) {
+	u32 value;
+	int ret;
+
+	/* Check software can perform MRS/MPR/PDA? */
+	value = readl(ddr_handoff_info->umctl2_base +

DDR4_CRCPARSTAT_OFFSET) &

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+		      DDR4_CRCPARSTAT_DFI_ALERT_ERR_NO_SW;
+
+	if (value) {
+		debug("%s: Software can't perform MRS/MPR/PDA\n",

__func__);

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +22 -0
+
+		/* Clear interrupt bit for DFI alert error */
+		setbits_le32(ddr_handoff_info->umctl2_base +
+			     DDR4_CRCPARCTL0_OFFSET,
+			     DDR4_CRCPARCTL0_DFI_ALERT_ERR_INIT_CLR);
+
+		/* Wait for retry done */
+		ret = wait_for_bit_le32((const void *)
+					(ddr_handoff_info->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;
+		}
+
+		if (clr_ca_parity_error_status(ddr_handoff_info))
+			return ret;
+	} else {
+		debug("%s: Software can perform MRS/MPR/PDA\n",

__func__);

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +10 -0
+
+		ret = wait_for_bit_le32((const void *)
+					(ddr_handoff_info->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;

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 10 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +10 -0
+		}
+
+		if (clr_ca_parity_error_status(ddr_handoff_info))
+			return ret;
+
+		/* Clear interrupt bit for DFI alert error */
+		setbits_le32(ddr_handoff_info->umctl2_base +
+			     DDR4_CRCPARCTL0_OFFSET,
+			     DDR4_CRCPARCTL0_DFI_ALERT_ERR_INIT_CLR);
+	}

This if .. else doing almost same thing, can combine.

Quoted 13 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +12 -0
+
+	return 0;
+}
+
+static int ensure_retry_procedure_complete(struct ddr_handoff
+*ddr_handoff_info) {
+	u32 value;
+	u32 start = get_timer(0);
+	int ret;
+
+	/* Check parity/crc/error window is emptied ? */
+	value = readl(ddr_handoff_info->umctl2_base +

DDR4_CRCPARSTAT_OFFSET) &

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 1 line
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +1 -0
+		      DDR4_CRCPARSTAT_CMD_IN_ERR_WINDOW;

While loop below can change to do..while() then can remove this readl here.

Quoted 109 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +26 -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(ddr_handoff_info->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(ddr_handoff_info->umctl2_base +
+				      DDR4_CRCPARSTAT_OFFSET) &
+				      DDR4_CRCPARSTAT_DFI_ALERT_ERR_INT;
+
+			if (value) {
+				ret =
+
	ddr4_retry_software_sequence(ddr_handoff_info);
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +14 -0
+				debug("%s: DFI alert error interrupt ",
+				      __func__);
+				debug("is set\n");
+
+				if (ret)
+					return ret;
+			}
+
+			/*
+			 * Check fatal parity error interrupt is set?
+			 */
+			value = readl(ddr_handoff_info->umctl2_base +
+				      DDR4_CRCPARSTAT_OFFSET) &
+

DDR4_CRCPARSTAT_DFI_ALERT_ERR_FATL_INT;

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +26 -0
+			if (value) {
+				printf("%s: Fatal parity error  ",
+				       __func__);
+				printf("interrupt is set, Hang it!!\n");
+				hang();
+			}
+		}
+
+		value = readl(ddr_handoff_info->umctl2_base +
+			      DDR4_CRCPARSTAT_OFFSET) &
+			      DDR4_CRCPARSTAT_CMD_IN_ERR_WINDOW;
+
+		udelay(1);
+		WATCHDOG_RESET();
+	}
+
+	return 0;
+}
+
+static int enable_quasi_dynamic_reg_grp3(struct ddr_handoff
+*ddr_handoff_info) {
+	u32 i, value, backup;
+	int ret;
+
+	/* Disable input traffic per port */
+	clrbits_le32(ddr_handoff_info->umctl2_base +

DDR4_PCTRL0_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+		     DDR4_PCTRL0_PORT_EN);
+
+	/* Polling AXI port until idle */
+	ret = wait_for_bit_le32((const void *)(ddr_handoff_info-
Quoted 1 line

umctl2_base +

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +1 -0
+				DDR4_PSTAT_OFFSET),

DDR4_PSTAT_WR_PORT_BUSY_0 |

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +10 -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(ddr_handoff_info->umctl2_base +

DDR4_DBG1_OFFSET);

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +15 -0
+
+	/* Disable input traffic to the controller */
+	setbits_le32(ddr_handoff_info->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 *)
+					(ddr_handoff_info->umctl2_base +
+					DDR4_DBGCAM_OFFSET),
+

DDR4_DBGCAM_WR_DATA_PIPELINE_EMPTY |
+
DDR4_DBGCAM_RD_DATA_PIPELINE_EMPTY |
+
DDR4_DBGCAM_DBG_WR_Q_EMPTY |

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +1 -0
+					DDR4_DBGCAM_DBG_RD_Q_EMPTY,

true,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 9 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +9 -0
+					TIMEOUT_200MS, false);
+		if (ret) {
+			debug("%s: loop(%u): Timeout while waiting for",
+			      __func__, i + 1);
+			debug(" CAM/data pipelines are empty\n");
+
+			/* Restore user setting */
+			writel(backup, ddr_handoff_info->umctl2_base +
+			       DDR4_DBG1_OFFSET);

Always need to restore backup. Can use "goto" at the exit function below.

Quoted 11 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +7 -0
+
+			return ret;
+		}
+	}
+
+	/* Check DDR4 retry is enabled ? */
+	value = readl(ddr_handoff_info->umctl2_base +

DDR4_CRCPARCTL1_OFFSET) &

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +3 -0
+		      DDR4_CRCPARCTL1_CRC_PARITY_RETRY_ENABLE;
+
+	if (value) {

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 10 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +10 -0
+		debug("%s: DDR4 retry is enabled\n", __func__);
+
+		ret = ensure_retry_procedure_complete(ddr_handoff_info);
+		if (ret) {
+			debug("%s: Timeout while waiting for", __func__);
+			debug(" retry procedure complete\n");
+
+			/* Restore user setting */
+			writel(backup, ddr_handoff_info->umctl2_base +
+			       DDR4_DBG1_OFFSET);

Same here.

Quoted 62 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +7 -0
+
+			return ret;
+		}
+	}
+
+	/* Restore user setting */
+	writel(backup, ddr_handoff_info->umctl2_base +

DDR4_DBG1_OFFSET);

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +2 -0
+
+	debug("%s: Quasi-dynamic group 3 registers are enabled\n",

__func__);

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +9 -0
+
+	return 0;
+}
+
+static int scrubbing_ddr_config(struct ddr_handoff *ddr_handoff_info) {
+	u32 backup[7];
+	int ret;
+
+	/* Reset to default value, prevent scrubber stop due to lower power

*/

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+	writel(0, ddr_handoff_info->umctl2_base + DDR4_PWRCTL_OFFSET);
+
+	/* Disable input traffic per port */
+	clrbits_le32(ddr_handoff_info->umctl2_base +

DDR4_PCTRL0_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+		     DDR4_PCTRL0_PORT_EN);
+
+	/* Backup user settings */
+	backup[0] = readl(ddr_handoff_info->umctl2_base +

DDR4_SBRCTL_OFFSET);

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +15 -0
+	backup[1] = readl(ddr_handoff_info->umctl2_base +
+			  DDR4_SBRWDATA0_OFFSET);
+	backup[2] = readl(ddr_handoff_info->umctl2_base +
+			  DDR4_SBRWDATA1_OFFSET);
+	backup[3] = readl(ddr_handoff_info->umctl2_base +
+			  DDR4_SBRSTART0_OFFSET);
+	backup[4] = readl(ddr_handoff_info->umctl2_base +
+			  DDR4_SBRSTART1_OFFSET);
+	backup[5] = readl(ddr_handoff_info->umctl2_base +
+			  DDR4_SBRRANGE0_OFFSET);
+	backup[6] = readl(ddr_handoff_info->umctl2_base +
+			  DDR4_SBRRANGE1_OFFSET);
+
+	/* Scrub_burst = 1, scrub_mode = 1(performs writes) */
+	writel(DDR_SBRCTL_SCRUB_BURST_1 |

DDR4_SBRCTL_SCRUB_WRITE,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +8 -0
+	       ddr_handoff_info->umctl2_base + DDR4_SBRCTL_OFFSET);
+
+	/* Zeroing whole DDR */
+	writel(0, ddr_handoff_info->umctl2_base +
+	       DDR4_SBRWDATA0_OFFSET);
+	writel(0, ddr_handoff_info->umctl2_base +
+	       DDR4_SBRWDATA1_OFFSET);
+	writel(0, ddr_handoff_info->umctl2_base +

DDR4_SBRSTART0_OFFSET);

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +1 -0
+	writel(0, ddr_handoff_info->umctl2_base +

DDR4_SBRSTART1_OFFSET);

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +1 -0
+	writel(0, ddr_handoff_info->umctl2_base +

DDR4_SBRRANGE0_OFFSET);

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +1 -0
+	writel(0, ddr_handoff_info->umctl2_base +

DDR4_SBRRANGE1_OFFSET);

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 2 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +2 -0
+
+#ifdef CONFIG_TARGET_SOCFPGA_DM

No need ifdef.

Quoted 43 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +6 -0
+	writel(0x0FFFFFFF, ddr_handoff_info->umctl2_base +
+	       DDR4_SBRRANGE0_OFFSET);
+#endif
+
+	/* Enables scrubber */
+	setbits_le32(ddr_handoff_info->umctl2_base +

DDR4_SBRCTL_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+		     DDR4_SBRCTL_SCRUB_EN);
+
+	/* Polling all scrub writes commands have been sent */
+	ret = wait_for_bit_le32((const void *)(ddr_handoff_info-
Quoted 1 line

umctl2_base +

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +1 -0
+				DDR4_SBRSTAT_OFFSET),

DDR4_SBRSTAT_SCRUB_DONE,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +9 -0
+				true, TIMEOUT_5000MS, false);
+	if (ret) {
+		debug("%s: Timeout while waiting for", __func__);
+		debug(" sending all scrub commands\n");
+		return ret;
+	}
+
+	/* Polling all scrub writes data have been sent */
+	ret = wait_for_bit_le32((const void *)(ddr_handoff_info-
Quoted 1 line

umctl2_base +

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +1 -0
+				DDR4_SBRSTAT_OFFSET),

DDR4_SBRSTAT_SCRUB_BUSY,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +9 -0
+				false, TIMEOUT_5000MS, false);
+	if (ret) {
+		debug("%s: Timeout while waiting for", __func__);
+		debug(" sending all scrub data\n");
+		return ret;
+	}
+
+	/* Disables scrubber */
+	clrbits_le32(ddr_handoff_info->umctl2_base +

DDR4_SBRCTL_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+		     DDR4_SBRCTL_SCRUB_EN);
+
+	/* Restore user settings */
+	writel(backup[0], ddr_handoff_info->umctl2_base +

DDR4_SBRCTL_OFFSET);

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +2 -0
+	writel(backup[1], ddr_handoff_info->umctl2_base +
+	       DDR4_SBRWDATA0_OFFSET);

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 10 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +10 -0
+	writel(backup[2], ddr_handoff_info->umctl2_base +
+	       DDR4_SBRWDATA1_OFFSET);
+	writel(backup[3], ddr_handoff_info->umctl2_base +
+	       DDR4_SBRSTART0_OFFSET);
+	writel(backup[4], ddr_handoff_info->umctl2_base +
+	       DDR4_SBRSTART1_OFFSET);
+	writel(backup[5], ddr_handoff_info->umctl2_base +
+	       DDR4_SBRRANGE0_OFFSET);
+	writel(backup[6], ddr_handoff_info->umctl2_base +
+	       DDR4_SBRRANGE1_OFFSET);

Can have helper function to read and write these.

Quoted 69 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +19 -0
+
+	return 0;
+}
+
+static int init_umctl2(struct ddr_handoff *ddr_handoff_info, u32
+*user_backup) {
+	u32 handoff_table[ddr_handoff_info->umctl2_handoff_length];
+	u32 i, value, expected_value;
+	u32 start = get_timer(0);
+	int ret;
+
+	printf("Initializing DDR controller ...\n");
+
+	/* Prevent controller from issuing read/write to SDRAM */
+	setbits_le32(ddr_handoff_info->umctl2_base + DDR4_DBG1_OFFSET,
+		     DDR4_DBG1_DISDQ);
+
+	/* Put SDRAM into self-refresh */
+	setbits_le32(ddr_handoff_info->umctl2_base +

DDR4_PWRCTL_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+		     DDR4_PWRCTL_SELFREF_EN);
+
+	/* Enable quasi-dynamic programing of the controller registers */
+	clrbits_le32(ddr_handoff_info->umctl2_base +

DDR4_SWCTL_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+		     DDR4_SWCTL_SW_DONE);
+
+	/* Ensure the controller is in initialization mode */
+	ret = wait_for_bit_le32((const void *)(ddr_handoff_info-
Quoted 1 line

umctl2_base +

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +1 -0
+				DDR4_STAT_OFFSET),

DDR4_STAT_OPERATING_MODE,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +12 -0
+				false, TIMEOUT_200MS, false);
+	if (ret) {
+		debug("%s: Timeout while waiting for", __func__);
+		debug(" init operating mode\n");
+		return ret;
+	}
+
+	debug("%s: Handoff table address = 0x%p table length = 0x%08x\n",
+	      __func__, (u32 *)handoff_table,
+	      (u32)ddr_handoff_info->umctl2_handoff_length);
+
+	socfpga_handoff_read((void *)ddr_handoff_info-
Quoted 1 line

umctl2_handoff_base,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +23 -0
+			     handoff_table,
+			     ddr_handoff_info->umctl2_handoff_length,
+			     little_endian);
+
+	for (i = 0; i < ddr_handoff_info->umctl2_handoff_length; i = i + 2) {
+		debug("%s: Absolute addr: 0x%08llx APB offset: 0x%08x",
+		      __func__, handoff_table[i] +
+		      ddr_handoff_info->umctl2_base, handoff_table[i]);
+		debug(" wr = 0x%08x ", handoff_table[i + 1]);
+
+		writel(handoff_table[i + 1], (uintptr_t)(handoff_table[i] +
+		       ddr_handoff_info->umctl2_base));
+
+		debug("rd = 0x%08x\n", readl((uintptr_t)(handoff_table[i] +
+		      ddr_handoff_info->umctl2_base)));
+	}
+
+	/* Backup user settings, restore after DDR up running */
+	*user_backup = readl(ddr_handoff_info->umctl2_base +
+			     DDR4_PWRCTL_OFFSET);
+
+	/* Polling granularity of refresh mode change to fixed 2x (DDR4) */
+	value = readl(ddr_handoff_info->umctl2_base +

DDR4_RFSHCTL3_OFFSET) &

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 1 line
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +1 -0
+		      DDR4_RFSHCTL3_REFRESH_MODE;

Use do...while() loop below, then can remove this.

Quoted 125 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +2 -0
+
+	expected_value = FIXED_2X <<

DDR4_RFSHCTL3_REFRESH_MODE_SHIFT;

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +19 -0
+
+	while (value != expected_value) {
+		if (get_timer(start) > TIMEOUT_200MS) {
+			debug("%s: loop(%u): Timeout while waiting for",
+			      __func__, i + 1);
+			debug(" fine granularity refresh mode change to ");
+			debug("fixed 2x\n");
+			debug("%s: expected_value = 0x%x value= 0x%x\n",
+			      __func__, expected_value, value);
+			return -ETIMEDOUT;
+		}
+
+		value = readl(ddr_handoff_info->umctl2_base +
+			      DDR4_RFSHCTL3_OFFSET) &
+			      DDR4_RFSHCTL3_REFRESH_MODE;
+	}
+
+	/* Disable self resfresh */
+	clrbits_le32(ddr_handoff_info->umctl2_base +

DDR4_PWRCTL_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+		     DDR4_PWRCTL_SELFREF_EN);
+
+	/* Complete quasi-dynamic register programming */
+	setbits_le32(ddr_handoff_info->umctl2_base +

DDR4_SWCTL_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +9 -0
+		     DDR4_SWCTL_SW_DONE);
+
+	/* Enable controller from issuing read/write to SDRAM */
+	clrbits_le32(ddr_handoff_info->umctl2_base + DDR4_DBG1_OFFSET,
+		     DDR4_DBG1_DISDQ);
+
+	/* 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 |

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +17 -0
+		     MEM_RST_MGR_STATUS_CONTROLLER_RST |
+		     MEM_RST_MGR_STATUS_RESET_COMPLETE);
+
+	printf("DDR controller configuration is completed\n");
+
+	return 0;
+}
+
+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");
+
+	/* Check DDR4 retry is enabled ? */
+	value = readl(ddr_handoff_info->umctl2_base +

DDR4_CRCPARCTL1_OFFSET) &

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +5 -0
+		      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__);

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +9 -0
+	} else {
+		/* Disable auto refresh */
+		setbits_le32(ddr_handoff_info->umctl2_base +
+			     DDR4_RFSHCTL3_OFFSET,
+			     DDR4_RFSHCTL3_DIS_AUTO_REFRESH);
+	}
+
+	/* Disable selfref_en & powerdown_en, nvr disable dfi dram clk */
+	clrbits_le32(ddr_handoff_info->umctl2_base +

DDR4_PWRCTL_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +2 -0
+		     DDR4_PWRCTL_EN_DFI_DRAM_CLK_DISABLE |
+		     DDR4_PWRCTL_POWERDOWN_EN |

DDR4_PWRCTL_SELFREF_EN);

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +3 -0
+
+	/* Enable quasi-dynamic programing of the controller registers */
+	clrbits_le32(ddr_handoff_info->umctl2_base +

DDR4_SWCTL_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +8 -0
+		     DDR4_SWCTL_SW_DONE);
+
+	ret = enable_quasi_dynamic_reg_grp3(ddr_handoff_info);
+	if (ret)
+		return ret;
+
+	/* Masking dfi init complete */
+	clrbits_le32(ddr_handoff_info->umctl2_base +

DDR4_DFIMISC_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+		     DDR4_DFIMISC_DFI_INIT_COMPLETE_EN);
+
+	/* Complete quasi-dynamic register programming */
+	setbits_le32(ddr_handoff_info->umctl2_base +

DDR4_SWCTL_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+		     DDR4_SWCTL_SW_DONE);
+
+	/* Polling programming done */
+	ret = wait_for_bit_le32((const void *)(ddr_handoff_info-
Quoted 1 line

umctl2_base +

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +1 -0
+				DDR4_SWSTAT_OFFSET),

DDR4_SWSTAT_SW_DONE_ACK,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +13 -0
+				true, TIMEOUT_200MS, false);
+	if (ret) {
+		debug("%s: Timeout while waiting for", __func__);
+		debug(" programming done\n");
+		return ret;
+	}
+
+	debug("%s: Handoff table address = 0x%p table length = 0x%08x\n",
+	      __func__, (u32 *)handoff_table,
+	      (u32)ddr_handoff_info->umctl2_handoff_length);
+
+	/* Execute PHY configuration handoff */
+	socfpga_handoff_read((void *)ddr_handoff_info-
Quoted 1 line

phy_handoff_base,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +11 -0
+			     handoff_table,
+			     (u32)ddr_handoff_info->phy_handoff_length,
+			     little_endian);
+
+	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 ",

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 10 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +10 -0
+		      __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)));
+	}
+
+#ifdef CONFIG_TARGET_SOCFPGA_DM

Same here, no need ifdef.

Quoted 19 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +19 -0
+	u8 numdbyte = 0x0009;
+	u8 byte, lane;
+	u32 b_addr, c_addr;
+
+	/* Program TxOdtDrvStren bx_p0 */
+	for (byte = 0; byte < numdbyte; byte++) {
+		c_addr = byte << 13;
+
+		for (lane = 0; lane <= b_max ; lane++) {
+			b_addr = lane << 9;
+			writew(0x00, (uintptr_t)
+			       (ddr_handoff_info->phy_base +
+			       DDR_PHY_TXODTDRVSTREN_B0_P0 + c_addr +
+			       b_addr));
+		}
+	}
+
+	/* Program TxOdtDrvStren bx_p1 */
+	for (byte = 0; byte < numdbyte; byte++) {

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 10 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +10 -0
+		c_addr = byte << 13;
+
+		for (lane = 0; lane <= b_max ; lane++) {
+			b_addr = lane << 9;
+			writew(0x00, (uintptr_t)
+			       (ddr_handoff_info->phy_base +
+			       DDR_PHY_TXODTDRVSTREN_B0_P1 + c_addr +
+			       b_addr));
+		}
+	}

These 2 for loops can be combined or move to a function.

Quoted 68 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +52 -0
+
+	/*
+	 * [phyinit_C_initPhyConfig] Pstate=0, Memclk=1600MHz,
+	 * Programming ARdPtrInitVal to 0x2
+	 * DWC_DDRPHYA_MASTER0_ARdPtrInitVal_p0
+	 */
+	dwc_ddrphy_apb_wr(0x2002e, 0x3);
+
+	/* [phyinit_C_initPhyConfig] Pstate=1,
+	 * Memclk=1067MHz, Programming ARdPtrInitVal to 0x2
+	 * DWC_DDRPHYA_MASTER0_ARdPtrInitVal_p1
+	 */
+	dwc_ddrphy_apb_wr(0x12002e, 0x3);
+
+	/* DWC_DDRPHYA_MASTER0_DfiFreqXlat0 */
+	dwc_ddrphy_apb_wr(0x200f0, 0x6666);
+
+	/* DWC_DDRPHYA_DBYTE0_DFIMRL_p0 */
+	dwc_ddrphy_apb_wr(0x10020, 0x4);
+	/* DWC_DDRPHYA_DBYTE1_DFIMRL_p0 */
+	dwc_ddrphy_apb_wr(0x11020, 0x4);
+	/* DWC_DDRPHYA_DBYTE2_DFIMRL_p0 */
+	dwc_ddrphy_apb_wr(0x12020, 0x4);
+	/* DWC_DDRPHYA_DBYTE3_DFIMRL_p0 */
+	dwc_ddrphy_apb_wr(0x13020, 0x4); //
+	/*  DWC_DDRPHYA_DBYTE4_DFIMRL_p0 */
+	dwc_ddrphy_apb_wr(0x14020, 0x4);
+	/* DWC_DDRPHYA_DBYTE5_DFIMRL_p0 */
+	dwc_ddrphy_apb_wr(0x15020, 0x4);
+	/* DWC_DDRPHYA_DBYTE6_DFIMRL_p0 */
+	dwc_ddrphy_apb_wr(0x16020, 0x4);
+	/* DWC_DDRPHYA_DBYTE7_DFIMRL_p0 */
+	dwc_ddrphy_apb_wr(0x17020, 0x4);
+	/* DWC_DDRPHYA_DBYTE8_DFIMRL_p0 */
+	dwc_ddrphy_apb_wr(0x18020, 0x4);
+	/* DWC_DDRPHYA_MASTER0_HwtMRL_p0 */
+	dwc_ddrphy_apb_wr(0x20020, 0x4);
+#endif
+
+	printf("DDR PHY configuration is completed\n");
+
+	return 0;
+}
+
+static void phy_init_engine(struct ddr_handoff *ddr_handoff_info) {
+	u32 i, value;
+	u32 handoff_table[ddr_handoff_info->phy_engine_handoff_length];
+
+	printf("Load PHY Init Engine ...\n");
+
+	/* Execute PIE production code handoff */
+	socfpga_handoff_read((void *)ddr_handoff_info-
Quoted 1 line

phy_engine_handoff_base,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +2 -0
+			     handoff_table,
+			     (u32)ddr_handoff_info-
Quoted 1 line

phy_engine_handoff_length,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +12 -0
+			     little_endian);
+
+	for (i = 0; i < ddr_handoff_info->phy_engine_handoff_length;
+	    i = i + 2) {
+		debug("Handoff addr: 0x%8llx ", handoff_table[i] +
+		      ddr_handoff_info->phy_base);
+
+		/*
+		 * Convert PHY odd offset to even offset that supported by
+		 * ARM processor.
+		 */
+		value = handoff_table[i] << 1;

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 10 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +10 -0
+		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)));

Same code as in init_phy(), can have a helper function for this.

Quoted 132 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +9 -0
+	}
+
+#ifdef CONFIG_TARGET_SOCFPGA_DM
+	u8 numdbyte = 0x0009;
+	u8 byte, timing_group;
+	u32 b_addr, c_addr;
+
+	/* Enable access to the PHY configuration registers */
+	clrbits_le16(ddr_handoff_info->phy_base +

DDR_PHY_APBONLY0_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +18 -0
+		     DDR_PHY_MICROCONTMUXSEL);
+
+	/* Program RXPBDLYTG0 bx_p0 */
+	for (byte = 0; byte < numdbyte; byte++) {
+		c_addr = byte << 9;
+
+		for (timing_group = 0; timing_group <= timing_group_max;
+			timing_group++) {
+			b_addr = timing_group << 1;
+			writew(0x00, (uintptr_t)
+			       (ddr_handoff_info->phy_base +
+			       DDR_PHY_RXPBDLYTG0_R0 + c_addr +
+			       b_addr));
+		}
+	}
+
+	/* Isolate the APB access from internal CSRs */
+	setbits_le16(ddr_handoff_info->phy_base +

DDR_PHY_APBONLY0_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +8 -0
+		     DDR_PHY_MICROCONTMUXSEL);
+#endif
+
+	printf("End of loading PHY Init Engine\n"); }
+
+int populate_ddr_handoff(struct ddr_handoff *ddr_handoff_info) {
+	/* DDR handoff */
+	ddr_handoff_info->mem_reset_base =

SOC64_HANDOFF_DDR_MEMRESET_BASE;

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +7 -0
+	debug("%s: DDR memory reset base = 0x%x\n", __func__,
+	      (u32)ddr_handoff_info->mem_reset_base);
+	debug("%s: DDR memory reset address = 0x%x\n", __func__,
+	      readl(ddr_handoff_info->mem_reset_base));
+
+	/* DDR controller handoff */
+	ddr_handoff_info->umctl2_handoff_base =

SOC64_HANDOFF_DDR_UMCTL2_SECTION;

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+	debug("%s: umctl2 handoff base = 0x%x\n", __func__,
+	      (u32)ddr_handoff_info->umctl2_handoff_base);
+
+	ddr_handoff_info->umctl2_base =

readl(SOC64_HANDOFF_DDR_UMCTL2_BASE);

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +11 -0
+	debug("%s: umctl2 base = 0x%x\n", __func__,
+	      (u32)ddr_handoff_info->umctl2_base);
+
+	ddr_handoff_info->umctl2_total_length =
+			readl(ddr_handoff_info->umctl2_handoff_base +
+			      SOC64_HANDOFF_OFFSET_LENGTH);
+	debug("%s: Umctl2 total length in byte = 0x%x\n", __func__,
+	      (u32)ddr_handoff_info->umctl2_total_length);
+
+	ddr_handoff_info->umctl2_handoff_length =
+		socfpga_get_handoff_size((void *)ddr_handoff_info-
Quoted 1 line

umctl2_handoff_base,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +2 -0
+					 little_endian);
+	debug("%s: Umctl2 handoff length in word(32-bit) = 0x%x\n",

__func__,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +26 -0
+	      (u32)ddr_handoff_info->umctl2_handoff_length);
+
+	if (ddr_handoff_info->umctl2_handoff_length < 0)
+		return ddr_handoff_info->umctl2_handoff_length;
+
+	/* DDR PHY handoff */
+	ddr_handoff_info->phy_handoff_base =
+		ddr_handoff_info->umctl2_handoff_base +
+			ddr_handoff_info->umctl2_total_length;
+	debug("%s: PHY handoff base = 0x%x\n", __func__,
+	      (u32)ddr_handoff_info->phy_handoff_base);
+
+	ddr_handoff_info->phy_base =
+		readl(ddr_handoff_info->phy_handoff_base +
+		      SOC64_HANDOFF_DDR_PHY_BASE_OFFSET);
+	debug("%s: PHY base = 0x%x\n", __func__,
+	      (u32)ddr_handoff_info->phy_base);
+
+	ddr_handoff_info->phy_total_length =
+		readl(ddr_handoff_info->phy_handoff_base +
+			      SOC64_HANDOFF_OFFSET_LENGTH);
+	debug("%s: PHY total length in byte = 0x%x\n", __func__,
+	      (u32)ddr_handoff_info->phy_total_length);
+
+	ddr_handoff_info->phy_handoff_length =
+		socfpga_get_handoff_size((void *)ddr_handoff_info-
Quoted 1 line

phy_handoff_base,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +23 -0
+					 little_endian);
+	debug("%s: PHY handoff length in word(32-bit) = 0x%x\n", __func__,
+	      (u32)ddr_handoff_info->phy_handoff_length);
+
+	if (ddr_handoff_info->phy_handoff_length < 0)
+		return ddr_handoff_info->phy_handoff_length;
+
+	/* DDR PHY Engine handoff */
+	ddr_handoff_info->phy_engine_handoff_base =
+				ddr_handoff_info->phy_handoff_base +
+				ddr_handoff_info->phy_total_length;
+	debug("%s: PHY base = 0x%x\n", __func__,
+	      (u32)ddr_handoff_info->phy_engine_handoff_base);
+
+	ddr_handoff_info->phy_engine_total_length =
+			readl(ddr_handoff_info->phy_engine_handoff_base
+
+			      SOC64_HANDOFF_OFFSET_LENGTH);
+	debug("%s: PHY engine total length in byte = 0x%x\n", __func__,
+	      (u32)ddr_handoff_info->phy_engine_total_length);
+
+	ddr_handoff_info->phy_engine_handoff_length =
+	socfpga_get_handoff_size((void *)ddr_handoff_info-
Quoted 1 line

phy_engine_handoff_base,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +15 -0
+				 little_endian);
+	debug("%s: PHY engine handoff length in word(32-bit) = 0x%x\n",
+	      __func__, (u32)ddr_handoff_info->phy_engine_handoff_length);
+
+	if (ddr_handoff_info->phy_engine_handoff_length < 0)
+		return ddr_handoff_info->phy_engine_handoff_length;
+
+	return 0;
+}
+
+int enable_ddr_clock(struct udevice *dev) {
+	struct clk *ddr_clk;
+	int ret;
+
+	/* Enable clock before init DDR */

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 10 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +10 -0
+	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__);

Fix the error message, it is not getting from dts.

Quoted 66 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +22 -0
+		return ret;
+	}
+
+	printf("%s: DDR clock is enabled\n", __func__);
+
+	return 0;
+}
+
+int sdram_mmr_init_full(struct udevice *dev) {
+	u32 value, user_backup;
+	u32 start = get_timer(0);
+	int ret;
+	struct bd_info bd;
+	struct ddr_handoff ddr_handoff_info;
+	struct altera_sdram_priv *priv = dev_get_priv(dev);
+
+	if (!is_ddr_init_skipped()) {
+		printf("%s: SDRAM init in progress ...\n", __func__);
+
+		ret = populate_ddr_handoff(&ddr_handoff_info);
+		if (ret) {
+			debug("%s: Failed to populate DDR handoff\n",

__func__);

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +5 -0
+			return ret;
+		}
+
+		/*
+		 * Polling reset complete, must be high to ensure DDR

subsystem

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +8 -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,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +27 -0
+					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;
+
+		/* Initialize DDR controller */
+		ret = init_umctl2(&ddr_handoff_info, &user_backup);
+		if (ret) {
+			debug("%s: Failed to inilialize DDR controller\n",
+			      __func__);
+			return ret;
+		}
+
+		/* Initialize DDR PHY */
+		ret = init_phy(&ddr_handoff_info);
+		if (ret) {
+			debug("%s: Failed to inilialize DDR PHY\n", __func__);
+			return ret;
+		}
+
+		/* Reset ARC processor when no using for security purpose

*/

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 5 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +5 -0
+		setbits_le16(ddr_handoff_info.phy_base +
+			     DDR_PHY_MICRORESET_OFFSET,
+			     DDR_PHY_MICRORESET_RESET);
+
+		/* DDR freq set to support DDR4-3200 */

This comment is correct?

Quoted 96 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+		phy_init_engine(&ddr_handoff_info);
+
+		/* Trigger memory controller to init SDRAM */
+		/* Enable quasi-dynamic programing of controller registers

*/

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +1 -0
+		clrbits_le32(ddr_handoff_info.umctl2_base +

DDR4_SWCTL_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +8 -0
+			     DDR4_SWCTL_SW_DONE);
+
+		ret = enable_quasi_dynamic_reg_grp3(&ddr_handoff_info);
+		if (ret)
+			return ret;
+
+		/* Start DFI init sequence */
+		setbits_le32(ddr_handoff_info.umctl2_base +

DDR4_DFIMISC_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+			     DDR4_DFIMISC_DFI_INIT_START);
+
+		/* Complete quasi-dynamic register programming */
+		setbits_le32(ddr_handoff_info.umctl2_base +

DDR4_SWCTL_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +29 -0
+			     DDR4_SWCTL_SW_DONE);
+
+		/* Polling programming done */
+		ret = wait_for_bit_le32((const void *)
+					(ddr_handoff_info.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;
+		}
+
+		/* Polling DFI init complete */
+		ret = wait_for_bit_le32((const void *)
+					(ddr_handoff_info.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("DFI init completed.\n");
+
+		/* Enable quasi-dynamic programing of controller registers

*/

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +1 -0
+		clrbits_le32(ddr_handoff_info.umctl2_base +

DDR4_SWCTL_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +8 -0
+			     DDR4_SWCTL_SW_DONE);
+
+		ret = enable_quasi_dynamic_reg_grp3(&ddr_handoff_info);
+		if (ret)
+			return ret;
+
+		/* Stop DFI init sequence */
+		clrbits_le32(ddr_handoff_info.umctl2_base +

DDR4_DFIMISC_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+			     DDR4_DFIMISC_DFI_INIT_START);
+
+		/* Unmasking dfi init complete */
+		setbits_le32(ddr_handoff_info.umctl2_base +

DDR4_DFIMISC_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+			     DDR4_DFIMISC_DFI_INIT_COMPLETE_EN);
+
+		/* Software exit from self-refresh */
+		clrbits_le32(ddr_handoff_info.umctl2_base +

DDR4_PWRCTL_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +4 -0
+			     DDR4_PWRCTL_SELFREF_SW);
+
+		/* Complete quasi-dynamic register programming */
+		setbits_le32(ddr_handoff_info.umctl2_base +

DDR4_SWCTL_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +18 -0
+			     DDR4_SWCTL_SW_DONE);
+
+		/* Polling programming done */
+		ret = wait_for_bit_le32((const void *)
+					(ddr_handoff_info.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("DDR programming done\n");
+
+		/* Polling until SDRAM entered normal operating mode */
+		value = readl(ddr_handoff_info.umctl2_base +

DDR4_STAT_OFFSET) &

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 1 line
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +1 -0
+			      DDR4_STAT_OPERATING_MODE;

Change to do...while() and can remove this readl.

Quoted 45 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +5 -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");

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +26 -0
+				return -ETIMEDOUT;
+			}
+
+			value = readl(ddr_handoff_info.umctl2_base +
+				      DDR4_STAT_OFFSET) &
+				      DDR4_STAT_OPERATING_MODE;
+
+			udelay(1);
+			WATCHDOG_RESET();
+		}
+
+		debug("DDR entered normal operating mode\n");
+
+		/* Enabling auto refresh */
+		clrbits_le32(ddr_handoff_info.umctl2_base +
+			     DDR4_RFSHCTL3_OFFSET,
+			     DDR4_RFSHCTL3_DIS_AUTO_REFRESH);
+
+		/* Checking ECC is enabled? */
+		value = readl(ddr_handoff_info.umctl2_base +
+			      DDR4_ECCCFG0_OFFSET) & DDR4_ECC_MODE;
+		if (value) {
+			printf("%s: ECC is enabled\n", __func__);
+			ret = scrubbing_ddr_config(&ddr_handoff_info);
+			if (ret) {
+				debug("%s: Failed to enable ECC\n",

__func__);

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +10 -0
+				return ret;
+			}
+		}
+
+		/* Restore user settings */
+		writel(user_backup, ddr_handoff_info.umctl2_base +
+		       DDR4_PWRCTL_OFFSET);
+
+		/* Enable input traffic per port */
+		setbits_le32(ddr_handoff_info.umctl2_base +

DDR4_PCTRL0_OFFSET,

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +1 -0
+			     DDR4_PCTRL0_PORT_EN);

arch/arm/mach-socfpga/include/mach/system_manager_soc64.h

Quoted 10 lines
arch/arm/mach-socfpga/include/mach/system_manager_soc64.h +10 -0
+
+		printf("%s: DDR init success\n", __func__);
+	}
+
+	/* 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;

Use errorno.

Regards
Ley Foon

#32 lore raw

PATCH RESEND v2 17/22 arm: socfpga: Move Stratix10 and Agilex SPL common code

In reply to Siew Chin Lim

Move Stratix10 and Agilex SPL common code to spl_soc64.c

---
 arch/arm/mach-socfpga/Makefile     |  2 ++
 arch/arm/mach-socfpga/spl_agilex.c | 16 ----------------
 arch/arm/mach-socfpga/spl_s10.c    | 17 -----------------
 arch/arm/mach-socfpga/spl_soc64.c  | 26 ++++++++++++++++++++++++++
 4 files changed, 28 insertions(+), 33 deletions(-)
 create mode 100644 arch/arm/mach-socfpga/spl_soc64.c
arch/arm/mach-socfpga/Makefile +2 -0
index 96fef50a12..57dc1e730d 100644
@@ -68,10 +68,12 @@ 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
 else
 obj-$(CONFIG_SPL_ATF) += smc_api.o
arch/arm/mach-socfpga/spl_agilex.c +0 -16
index 78b5d7c8d9..e65bf6360c 100644
@@ -24,22 +24,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-u32 spl_boot_device(void)
-{
-	return BOOT_DEVICE_MMC1;
-}
-
-#ifdef CONFIG_SPL_MMC_SUPPORT
-u32 spl_mmc_boot_mode(const u32 boot_device)
-{
-#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
-	return MMCSD_MODE_FS;
-#else
-	return MMCSD_MODE_RAW;
-#endif
-}
-#endif
-
 void board_init_f(ulong dummy)
 {
 	int ret;
arch/arm/mach-socfpga/spl_s10.c +0 -17
index daed05653a..1512b1ace3 100644
@@ -25,23 +25,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-u32 spl_boot_device(void)
-{
-	/* TODO: Get from SDM or handoff */
-	return BOOT_DEVICE_MMC1;
-}
-
-#ifdef CONFIG_SPL_MMC_SUPPORT
-u32 spl_mmc_boot_mode(const u32 boot_device)
-{
-#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
-	return MMCSD_MODE_FS;
-#else
-	return MMCSD_MODE_RAW;
-#endif
-}
-#endif
-
 void board_init_f(ulong dummy)
 {
 	const struct cm_config *cm_default_cfg = cm_get_default_config();
arch/arm/mach-socfpga/spl_soc64.c new file +26 -0
new file mode 100644
index 0000000000..53e5f6998c
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ *  Copyright (C) 2020 Intel Corporation. All rights reserved
+ *
+ */
+
+#include <common.h>
+#include <spl.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+u32 spl_boot_device(void)
+{
+	return BOOT_DEVICE_MMC1;
+}
+
+#ifdef CONFIG_SPL_MMC_SUPPORT
+u32 spl_boot_mode(const u32 boot_device)
+{
+#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
+	return MMCSD_MODE_FS;
+#else
+	return MMCSD_MODE_RAW;
+#endif
+}
+#endif
Signature · 1 line
2.13.0
#33 lore raw

PATCH RESEND v2 17/22 arm: socfpga: Move Stratix10 and Agilex SPL common code

Quoted 18 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:45 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 17/22] arm: socfpga: Move Stratix10 and Agilex SPL common code

Move Stratix10 and Agilex SPL common code to spl_soc64.c

Quoted 9 lines
---
 arch/arm/mach-socfpga/Makefile     |  2 ++
 arch/arm/mach-socfpga/spl_agilex.c | 16 ----------------
 arch/arm/mach-socfpga/spl_s10.c    | 17 -----------------
 arch/arm/mach-socfpga/spl_soc64.c  | 26 ++++++++++++++++++++++++++
 4 files changed, 28 insertions(+), 33 deletions(-)  create mode 100644

arch/arm/mach-socfpga/spl_soc64.c

#34 lore raw

PATCH RESEND v2 18/22 arm: socfpga: dm: Add SPL for Diamond Mesa

In reply to Siew Chin Lim
---
 arch/arm/mach-socfpga/spl_dm.c | 93 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 93 insertions(+)
 create mode 100644 arch/arm/mach-socfpga/spl_dm.c
arch/arm/mach-socfpga/spl_dm.c new file +93 -0
new file mode 100644
index 0000000000..ef664f4426
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 Intel Corporation <www.intel.com>
+ *
+ */
+
+#include <asm/io.h>
+#include <asm/u-boot.h>
+#include <asm/utils.h>
+#include <common.h>
+#include <hang.h>
+#include <image.h>
+#include <init.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 <dm/uclass.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+void board_init_f(ulong dummy)
+{
+	int ret;
+	struct udevice *dev;
+
+	ret = spl_early_init();
+	if (ret)
+		hang();
+
+	socfpga_get_managers_addr();
+
+	/* Ensure watchdog is paused when debugging is happening */
+	writel(SYSMGR_WDDBG_PAUSE_ALL_CPU,
+	       socfpga_get_sysmgr_addr() + SYSMGR_SOC64_WDDBG);
+
+#ifdef CONFIG_HW_WATCHDOG
+	/* Enable watchdog before initializing the HW */
+	socfpga_per_reset(SOCFPGA_RESET(L4WD0), 1);
+	socfpga_per_reset(SOCFPGA_RESET(L4WD0), 0);
+	hw_watchdog_init();
+#endif
+
+	/* ensure all processors are not released prior Linux boot */
+	writeq(0, CPU_RELEASE_ADDR);
+
+	timer_init();
+
+	sysmgr_pinmux_init();
+
+	preloader_console_init();
+
+	ret = uclass_get_device(UCLASS_CLK, 0, &dev);
+	if (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();
+	}
+
+	print_reset_info();
+	cm_print_clock_quick_summary();
+
+	firewall_setup();
+
+	ret = uclass_get_device(UCLASS_CACHE, 0, &dev);
+	if (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) {
+		printf("DRAM init failed: %d\n", ret);
+		hang();
+	}
+#endif
+
+	mbox_init();
+
+#ifdef CONFIG_CADENCE_QSPI
+	mbox_qspi_open();
+#endif
+}
Signature · 1 line
2.13.0
#35 lore raw

PATCH RESEND v2 18/22 arm: socfpga: dm: Add SPL for Diamond Mesa

Quoted 39 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:45 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 18/22] arm: socfpga: dm: Add SPL for Diamond Mesa

---
 arch/arm/mach-socfpga/spl_dm.c | 93
++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 93 insertions(+)
 create mode 100644 arch/arm/mach-socfpga/spl_dm.c
arch/arm/mach- renamed from arch/arm/mach-socfpga/spl_dm.c +0 -0

socfpga/spl_dm.c new file mode 100644 index 0000000000..ef664f4426

arch/arm/mach-socfpga/spl_dm.c new file +12 -0
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 Intel Corporation <www.intel.com>
+ *
+ */
+
+#include <asm/io.h>
+#include <asm/u-boot.h>
+#include <asm/utils.h>
+#include <common.h>
+#include <hang.h>
+#include <image.h>

arch/arm/mach-socfpga/spl_dm.c line 22

Quoted 10 lines
arch/arm/mach-socfpga/spl_dm.c new file +10 -0
+#include <init.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 <dm/uclass.h>

Sort alphanumerical order.

Regards
Ley Foon

#36 lore raw

PATCH RESEND v2 19/22 board: intel: dm: Add socdk board support for Diamond Mesa

In reply to Siew Chin Lim

Add Diamond Mesa SoC devkit board.

---
 board/intel/dm-socdk/MAINTAINERS | 7 +++++++
 board/intel/dm-socdk/Makefile    | 7 +++++++
 board/intel/dm-socdk/socfpga.c   | 7 +++++++
 3 files changed, 21 insertions(+)
 create mode 100644 board/intel/dm-socdk/MAINTAINERS
 create mode 100644 board/intel/dm-socdk/Makefile
 create mode 100644 board/intel/dm-socdk/socfpga.c
board/intel/dm-socdk/MAINTAINERS new file +7 -0
new file mode 100644
index 0000000000..f41bbcf2d5
@@ -0,0 +1,7 @@
+SOCFPGA BOARD
+M:	Chee Tien Fong <[email protected]>
+M:	Lim Siew Chin <[email protected]>
+S:	Maintained
+F:	board/intel/dm-socdk/
+F:	include/configs/socfpga_dm_socdk.h
+F:	configs/socfpga_dm_atf_defconfig
board/intel/dm-socdk/Makefile new file +7 -0
new file mode 100644
index 0000000000..09f07b8b2f
@@ -0,0 +1,7 @@
+#
+# Copyright (C) 2020 Intel Corporation <www.intel.com>
+#
+# SPDX-License-Identifier:	GPL-2.0
+#
+
+obj-y	:= socfpga.o
board/intel/dm-socdk/socfpga.c new file +7 -0
new file mode 100644
index 0000000000..ce87e2307d
@@ -0,0 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 Intel Corporation <www.intel.com>
+ *
+ */
+
+#include <common.h>
Signature · 1 line
2.13.0
#37 lore raw

PATCH RESEND v2 19/22 board: intel: dm: Add socdk board support for Diamond Mesa

Quoted 19 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:45 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 19/22] board: intel: dm: Add socdk board support for Diamond Mesa

Add Diamond Mesa SoC devkit board.

Quoted 9 lines
---
 board/intel/dm-socdk/MAINTAINERS | 7 +++++++
 board/intel/dm-socdk/Makefile    | 7 +++++++
 board/intel/dm-socdk/socfpga.c   | 7 +++++++
 3 files changed, 21 insertions(+)
 create mode 100644 board/intel/dm-socdk/MAINTAINERS  create mode

100644 board/intel/dm-socdk/Makefile create mode 100644 board/intel/dm-socdk/socfpga.c

#38 lore raw

PATCH RESEND v2 20/22 arm: dts: dm: Add base dtsi and devkit dts for Diamond Mesa

In reply to Siew Chin Lim

Add device tree for Diamond Mesa.

---
 arch/arm/dts/Makefile                     |   1 +
 arch/arm/dts/socfpga_dm-u-boot.dtsi       | 102 +++++
 arch/arm/dts/socfpga_dm.dtsi              | 640 ++++++++++++++++++++++++++++++
 arch/arm/dts/socfpga_dm_socdk-u-boot.dtsi |  50 +++
 arch/arm/dts/socfpga_dm_socdk.dts         | 144 +++++++
 5 files changed, 937 insertions(+)
 create mode 100644 arch/arm/dts/socfpga_dm-u-boot.dtsi
 create mode 100644 arch/arm/dts/socfpga_dm.dtsi
 create mode 100644 arch/arm/dts/socfpga_dm_socdk-u-boot.dtsi
 create mode 100644 arch/arm/dts/socfpga_dm_socdk.dts
arch/arm/dts/Makefile +1 -0
index 5308713df7..0d9384f77b 100644
@@ -376,6 +376,7 @@ dtb-$(CONFIG_ARCH_SOCFPGA) +=				\
 	socfpga_cyclone5_socrates.dtb			\
 	socfpga_cyclone5_sr1500.dtb			\
 	socfpga_cyclone5_vining_fpga.dtb		\
+	socfpga_dm_socdk.dtb				\
 	socfpga_stratix10_socdk.dtb
 
 dtb-$(CONFIG_TARGET_DRA7XX_EVM) += dra72-evm.dtb dra7-evm.dtb	\
arch/arm/dts/socfpga_dm-u-boot.dtsi new file +102 -0

102 lines not on this page · raw message

arch/arm/dts/socfpga_dm.dtsi new file +640 -0

640 lines not on this page · raw message

arch/arm/dts/socfpga_dm_socdk-u-boot.dtsi new file +50 -0

50 lines not on this page · raw message

arch/arm/dts/socfpga_dm_socdk.dts new file +144 -0

144 lines not on this page · raw message

Signature · 1 line
2.13.0
#39 lore raw

PATCH RESEND v2 20/22 arm: dts: dm: Add base dtsi and devkit dts for Diamond Mesa

arch/arm/dts/socfpga_dm.dtsi

Quoted 34 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:45 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 20/22] arm: dts: dm: Add base dtsi and devkit dts for Diamond Mesa

Add device tree for Diamond Mesa.

---
 arch/arm/dts/Makefile                     |   1 +
 arch/arm/dts/socfpga_dm-u-boot.dtsi       | 102 +++++
 arch/arm/dts/socfpga_dm.dtsi              | 640
++++++++++++++++++++++++++++++
 arch/arm/dts/socfpga_dm_socdk-u-boot.dtsi |  50 +++
 arch/arm/dts/socfpga_dm_socdk.dts         | 144 +++++++
 5 files changed, 937 insertions(+)
 create mode 100644 arch/arm/dts/socfpga_dm-u-boot.dtsi
 create mode 100644 arch/arm/dts/socfpga_dm.dtsi  create mode 100644
arch/arm/dts/socfpga_dm_socdk-u-boot.dtsi
 create mode 100644 arch/arm/dts/socfpga_dm_socdk.dts
arch/arm/dts/socfpga_dm.dtsi +0 -0

Make sure sync latest from Linux.

[...]

arch/arm/dts/socfpga_dm.dtsi

Quoted 2 lines
arch/arm/dts/socfpga_dm.dtsi +2 -0
+		};
+		gmac0: ethernet at ff800000 {

Add new line before gmac0.

[...]

Quoted 42 lines
arch/arm/dts/socfpga_dm_socdk-u-boot.dtsi new file +35 -0
new file mode 100644
index 0000000000..9dbcaf2eb0
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * U-Boot additions
+ *
+ * Copyright (C) 2020 Intel Corporation <www.intel.com>  */
+
+#include "socfpga_dm-u-boot.dtsi"
+
+/{
+	aliases {
+		spi0 = &qspi;
+		i2c0 = &i2c1;
+	};
+
+	memory {
+		/* 8GB */
+		reg = <0 0x00000000 0 0x80000000>,
+		      <2 0x80000000 1 0x80000000>;
+	};
+};
+
+&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;
+};

arch/arm/dts/socfpga_dm_socdk-u-boot.dtsi line 45

Quoted 10 lines
arch/arm/dts/socfpga_dm_socdk-u-boot.dtsi new file +10 -0
+
+&mmc {
+	drvsel = <3>;
+	smplsel = <0>;
+	u-boot,dm-pre-reloc;
+};
+
+&qspi {
+	status = "okay";
+};

socfpga_dm_socdk.dts already set this.

Regards
Ley Foon

#40 lore raw

PATCH RESEND v2 21/22 configs: dm: Add Diamond Mesa CONFIGs

In reply to Siew Chin Lim

Add CONFIGs for Diamond Mesa.

---
 include/configs/socfpga_dm_socdk.h | 46 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 include/configs/socfpga_dm_socdk.h
include/configs/socfpga_dm_socdk.h new file +46 -0
new file mode 100644
index 0000000000..f0082b8d1d
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2020 Intel Corporation <www.intel.com>
+ *
+ */
+
+#ifndef __CONFIG_SOCFGPA_DM_H__
+#define __CONFIG_SOCFGPA_DM_H__
+
+#include <configs/socfpga_soc64_common.h>
+
+#undef CONFIG_BOOTARGS
+#define CONFIG_BOOTARGS "earlycon panic=-1 earlyprintk=ttyS0,4800"
+
+#undef CONFIG_EXTRA_ENV_SETTINGS
+#define CONFIG_EXTRA_ENV_SETTINGS \
+	"loadaddr=" __stringify(CONFIG_SYS_LOAD_ADDR) "\0" \
+	"bootfile=Image\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" \
+	"mmcvabboot=setenv bootargs " CONFIG_BOOTARGS \
+		" root=${mmcroot} rw rootwait;" \
+		"bootm ${loadaddr}\0" \
+	"mmcvabload=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;" \
+		"fdt set /soc/clkmgr/clocks/qspi_clk clock-frequency " \
+		" ${qspi_clock}; 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_DM_H__ */
Signature · 1 line
2.13.0
#41 lore raw

PATCH RESEND v2 21/22 configs: dm: Add Diamond Mesa CONFIGs

Quoted 53 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:45 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 21/22] configs: dm: Add Diamond Mesa CONFIGs

Add CONFIGs for Diamond Mesa.

---
 include/configs/socfpga_dm_socdk.h | 46
++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 include/configs/socfpga_dm_socdk.h
include/configs/socfpga_dm_socdk.h new file +22 -0
new file mode 100644
index 0000000000..f0082b8d1d
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2020 Intel Corporation <www.intel.com>
+ *
+ */
+
+#ifndef __CONFIG_SOCFGPA_DM_H__
+#define __CONFIG_SOCFGPA_DM_H__
+
+#include <configs/socfpga_soc64_common.h>
+
+#undef CONFIG_BOOTARGS
+#define CONFIG_BOOTARGS "earlycon panic=-1 earlyprintk=ttyS0,4800"
+
+#undef CONFIG_EXTRA_ENV_SETTINGS
+#define CONFIG_EXTRA_ENV_SETTINGS \
+	"loadaddr=" __stringify(CONFIG_SYS_LOAD_ADDR) "\0" \
+	"bootfile=Image\0" \
+	"fdt_addr=1100000\0" \
+	"fdtimage=" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0" \
+	"mmcroot=/dev/mmcblk0p2\0" \
+	"mmcboot=setenv bootargs " CONFIG_BOOTARGS \

include/configs/socfpga_dm_socdk.h line 32

Quoted 10 lines
include/configs/socfpga_dm_socdk.h new file +10 -0
+		" 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" \
+	"mmcvabboot=setenv bootargs " CONFIG_BOOTARGS \
+		" root=${mmcroot} rw rootwait;" \
+		"bootm ${loadaddr}\0" \
+	"mmcvabload=mmc rescan;" \
+		"load mmc 0:1 ${loadaddr} ${bootfile}\0" \

VAB related shouldn't in this patchset?

Regards
Ley Foon

#42 lore raw

PATCH RESEND v2 22/22 arm: socfpga: dm: Enable Intel Diamond Mesa build

In reply to Siew Chin Lim

Add defconfig for Diamond Mesa to support both
legacy boot flow and ATF boot flow.

Legacy boot:
SPL -> U-Boot proper -> OS (Linux)

ATF boot flow:
SPL -> ATF(BL31) -> U-Boot proper -> OS (Linux)

---
 arch/arm/mach-socfpga/Kconfig    | 19 ++++++++++
 arch/arm/mach-socfpga/Makefile   | 18 ++++++++++
 configs/socfpga_dm_atf_defconfig | 76 ++++++++++++++++++++++++++++++++++++++++
 configs/socfpga_dm_defconfig     | 69 ++++++++++++++++++++++++++++++++++++
 4 files changed, 182 insertions(+)
 create mode 100644 configs/socfpga_dm_atf_defconfig
 create mode 100644 configs/socfpga_dm_defconfig
arch/arm/mach-socfpga/Kconfig +19 -0
index 4d061a9d0d..5dee193b31 100644
@@ -66,6 +66,22 @@ config TARGET_SOCFPGA_CYCLONE5
 	bool
 	select TARGET_SOCFPGA_GEN5
 
+config TARGET_SOCFPGA_DM
+	bool
+	select TARGET_SOCFPGA_SOC64
+	select ARMV8_MULTIENTRY
+	select ARMV8_SET_SMPEN
+	select CLK
+	select FPGA_INTEL_SDM_MAILBOX
+	select NCORE_CACHE
+	select SPL_ALTERA_SDRAM
+	select SPL_CLK if SPL
+	select BINMAN
+
+config TARGET_SOCFPGA_DM_SOCDK
+	bool "Intel SOCFPGA SoCDK (Diamond Mesa)"
+	select TARGET_SOCFPGA_DM
+
 config TARGET_SOCFPGA_GEN5
 	bool
 	select SPL_ALTERA_SDRAM
@@ -165,6 +181,7 @@ config SYS_BOARD
 	default "arria10-socdk" if TARGET_SOCFPGA_ARRIA10_SOCDK
 	default "cyclone5-socdk" if TARGET_SOCFPGA_CYCLONE5_SOCDK
 	default "dbm-soc1" if TARGET_SOCFPGA_DEVBOARDS_DBM_SOC1
+	default "dm-socdk" if TARGET_SOCFPGA_DM_SOCDK
 	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
@@ -179,6 +196,7 @@ config SYS_BOARD
 
 config SYS_VENDOR
 	default "intel" if TARGET_SOCFPGA_AGILEX_SOCDK
+	default "intel" if TARGET_SOCFPGA_DM_SOCDK
 	default "altera" if TARGET_SOCFPGA_ARRIA5_SOCDK
 	default "altera" if TARGET_SOCFPGA_ARRIA10_SOCDK
 	default "altera" if TARGET_SOCFPGA_CYCLONE5_SOCDK
@@ -203,6 +221,7 @@ config SYS_CONFIG_NAME
 	default "socfpga_arria10_socdk" if TARGET_SOCFPGA_ARRIA10_SOCDK
 	default "socfpga_cyclone5_socdk" if TARGET_SOCFPGA_CYCLONE5_SOCDK
 	default "socfpga_dbm_soc1" if TARGET_SOCFPGA_DEVBOARDS_DBM_SOC1
+	default "socfpga_dm_socdk" if TARGET_SOCFPGA_DM_SOCDK
 	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
arch/arm/mach-socfpga/Makefile +18 -0
index 57dc1e730d..b88bb515d0 100644
@@ -54,6 +54,19 @@ obj-y	+= wrap_handoff_soc64.o
 obj-y	+= wrap_pll_config_soc64.o
 endif
 
+ifdef CONFIG_TARGET_SOCFPGA_DM
+obj-y	+= clock_manager_dm.o
+obj-y	+= lowlevel_init_soc64.o
+obj-y	+= mailbox_s10.o
+obj-y	+= misc_s10.o
+obj-y	+= mmu-arm64_s10.o
+obj-y	+= reset_manager_s10.o
+obj-y	+= system_manager_soc64.o
+obj-y	+= timer_s10.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
@@ -75,6 +88,11 @@ obj-y	+= firewall.o
 obj-y	+= spl_agilex.o
 obj-y	+= spl_soc64.o
 endif
+ifdef CONFIG_TARGET_SOCFPGA_DM
+obj-y	+= firewall.o
+obj-y	+= spl_dm.o
+obj-y	+= spl_soc64.o
+endif
 else
 obj-$(CONFIG_SPL_ATF) += smc_api.o
 endif
configs/socfpga_dm_atf_defconfig new file +76 -0

76 lines not on this page · raw message

configs/socfpga_dm_defconfig new file +69 -0

69 lines not on this page · raw message

Signature · 1 line
2.13.0
#43 lore raw

PATCH RESEND v2 22/22 arm: socfpga: dm: Enable Intel Diamond Mesa build

Quoted 46 lines

-----Original Message-----
From: Lim, Elly Siew Chin <[email protected]>
Sent: Tuesday, November 10, 2020 2:45 PM
To: u-boot at lists.denx.de
Cc: 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]>; Lim, Elly Siew Chin <[email protected]>
Subject: [RESEND v2 22/22] arm: socfpga: dm: Enable Intel Diamond Mesa build

Add defconfig for Diamond Mesa to support both legacy boot flow and ATF boot flow.

Legacy boot:
SPL -> U-Boot proper -> OS (Linux)

ATF boot flow:
SPL -> ATF(BL31) -> U-Boot proper -> OS (Linux)

---
 arch/arm/mach-socfpga/Kconfig    | 19 ++++++++++
 arch/arm/mach-socfpga/Makefile   | 18 ++++++++++
 configs/socfpga_dm_atf_defconfig | 76
++++++++++++++++++++++++++++++++++++++++
 configs/socfpga_dm_defconfig     | 69
++++++++++++++++++++++++++++++++++++
 4 files changed, 182 insertions(+)
 create mode 100644 configs/socfpga_dm_atf_defconfig  create mode

100644 configs/socfpga_dm_defconfig

arch/arm/mach- renamed from arch/arm/mach-socfpga/Kconfig +0 -0

socfpga/Kconfig index 4d061a9d0d..5dee193b31 100644

arch/arm/mach-socfpga/Kconfig +1 -0
@@ -66,6 +66,22 @@ config TARGET_SOCFPGA_CYCLONE5
 	bool
 	select TARGET_SOCFPGA_GEN5
 
+config TARGET_SOCFPGA_DM

arch/arm/mach-socfpga/Kconfig config TARGET_SOCFPGA_CYCLONE5 · line 79

Quoted 10 lines
arch/arm/mach-socfpga/Kconfig +10 -0
+	bool
+	select TARGET_SOCFPGA_SOC64
+	select ARMV8_MULTIENTRY
+	select ARMV8_SET_SMPEN
+	select CLK
+	select FPGA_INTEL_SDM_MAILBOX
+	select NCORE_CACHE
+	select SPL_ALTERA_SDRAM
+	select SPL_CLK if SPL
+	select BINMAN

Sort in alphanumerical order.

Regards
Ley Foon