Merge "rockchip: px30: support px30" into integration
authorSoby Mathew <soby.mathew@arm.com>
Wed, 24 Jul 2019 12:02:13 +0000 (12:02 +0000)
committerTrustedFirmware Code Review <review@review.trustedfirmware.org>
Wed, 24 Jul 2019 12:02:13 +0000 (12:02 +0000)
182 files changed:
.checkpatch.conf
.editorconfig
Makefile
bl31/aarch64/crash_reporting.S
bl32/optee/optee.mk
common/backtrace/backtrace.c
common/tf_log.c
docs/change-log.rst
docs/components/firmware-update.rst
docs/components/sdei.rst
docs/components/secure-partition-manager-design.rst
docs/conf.py
docs/getting_started/porting-guide.rst
docs/getting_started/user-guide.rst
docs/index.rst
docs/maintainers.rst
docs/perf/psci-performance-juno.rst
docs/plat/fvp_ve.rst
docs/plat/intel-agilex.rst [new file with mode: 0644]
docs/process/coding-guidelines.rst
docs/process/platform-compatibility-policy.rst
docs/requirements.txt
docs/resources/diagrams/Makefile
docs/resources/diagrams/plantuml/io_arm_class_diagram.puml [new file with mode: 0644]
docs/resources/diagrams/plantuml/io_dev_init_and_check.puml [new file with mode: 0644]
docs/resources/diagrams/plantuml/io_dev_registration.puml [new file with mode: 0644]
docs/resources/diagrams/plantuml/io_framework_usage_overview.puml [new file with mode: 0644]
docs/resources/diagrams/plantuml/plantuml_to_svg.sh [deleted file]
docs/resources/diagrams/plantuml/sdei_explicit_dispatch.svg [deleted file]
docs/resources/diagrams/plantuml/sdei_general.svg [deleted file]
drivers/console/aarch32/skeleton_console.S
drivers/console/aarch64/skeleton_console.S
drivers/marvell/mci.c
drivers/marvell/mochi/cp110_setup.c
drivers/meson/gxl/crypto/sha_dma.c
drivers/renesas/rcar/auth/auth_mod.c
drivers/renesas/rcar/cpld/ulcb_cpld.c
drivers/renesas/rcar/pfc/D3/pfc_init_d3.c
drivers/renesas/rcar/pfc/E3/pfc_init_e3.c
drivers/renesas/rcar/pfc/H3/pfc_init_h3_v1.c
drivers/renesas/rcar/pfc/H3/pfc_init_h3_v2.c
drivers/renesas/rcar/pfc/M3/pfc_init_m3.c
drivers/renesas/rcar/pfc/M3N/pfc_init_m3n.c
drivers/renesas/rcar/pfc/V3M/pfc_init_v3m.c
drivers/renesas/rcar/pfc/pfc_regs.h
drivers/renesas/rcar/pwrc/pwrc.c
drivers/renesas/rcar/pwrc/pwrc.h
drivers/renesas/rcar/rpc/rpc_driver.c
drivers/staging/renesas/rcar/ddr/ddr_a/boot_init_dram_regdef.h [new file with mode: 0644]
drivers/staging/renesas/rcar/ddr/ddr_a/boot_init_dram_regdef_d3.h [deleted file]
drivers/staging/renesas/rcar/ddr/ddr_a/boot_init_dram_regdef_e3.h [deleted file]
drivers/staging/renesas/rcar/ddr/ddr_a/boot_init_dram_regdef_v3m.h [deleted file]
drivers/staging/renesas/rcar/ddr/ddr_a/ddr_init_d3.c
drivers/staging/renesas/rcar/ddr/ddr_a/ddr_init_e3.c
drivers/staging/renesas/rcar/ddr/ddr_a/ddr_init_e3.h [deleted file]
drivers/staging/renesas/rcar/ddr/ddr_a/ddr_init_v3m.c
drivers/staging/renesas/rcar/ddr/ddr_b/boot_init_dram.c
drivers/staging/renesas/rcar/ddr/ddr_b/boot_init_dram_config.c
drivers/staging/renesas/rcar/ddr/ddr_b/boot_init_dram_regdef.h
drivers/staging/renesas/rcar/ddr/ddr_b/ddr_regdef.h
drivers/staging/renesas/rcar/ddr/ddr_b/init_dram_tbl_h3.h
drivers/synopsys/emmc/dw_mmc.c
fdts/a5ds.dts [new file with mode: 0644]
include/arch/aarch32/console_macros.S
include/arch/aarch64/arch.h
include/arch/aarch64/arch_features.h
include/drivers/ufs.h
include/lib/cpus/aarch64/cortex_a77.h [new file with mode: 0644]
include/lib/cpus/aarch64/cortex_deimos.h [deleted file]
include/lib/cpus/aarch64/cortex_hercules.h [new file with mode: 0644]
include/lib/libc/aarch64/stdint_.h
include/plat/arm/common/plat_arm.h
lib/cpus/aarch64/cortex_a77.S [new file with mode: 0644]
lib/cpus/aarch64/cortex_deimos.S [deleted file]
lib/cpus/aarch64/cortex_hercules.S [new file with mode: 0644]
lib/el3_runtime/aarch64/context_mgmt.c
lib/xlat_tables/aarch32/nonlpae_tables.c
plat/arm/board/a5ds/a5ds_bl1_setup.c [new file with mode: 0644]
plat/arm/board/a5ds/a5ds_bl2_setup.c [new file with mode: 0644]
plat/arm/board/a5ds/a5ds_common.c [new file with mode: 0644]
plat/arm/board/a5ds/a5ds_err.c [new file with mode: 0644]
plat/arm/board/a5ds/a5ds_pm.c [new file with mode: 0644]
plat/arm/board/a5ds/a5ds_private.h [new file with mode: 0644]
plat/arm/board/a5ds/a5ds_security.c [new file with mode: 0644]
plat/arm/board/a5ds/a5ds_topology.c [new file with mode: 0644]
plat/arm/board/a5ds/aarch32/a5ds_helpers.S [new file with mode: 0644]
plat/arm/board/a5ds/fdts/a5ds_tb_fw_config.dts [new file with mode: 0644]
plat/arm/board/a5ds/include/platform_def.h [new file with mode: 0644]
plat/arm/board/a5ds/platform.mk [new file with mode: 0644]
plat/arm/board/a5ds/sp_min/a5ds_sp_min_setup.c [new file with mode: 0644]
plat/arm/board/a5ds/sp_min/sp_min-a5ds.mk [new file with mode: 0644]
plat/arm/board/fvp/fvp_bl1_setup.c
plat/arm/board/fvp/fvp_err.c [new file with mode: 0644]
plat/arm/board/fvp/platform.mk
plat/arm/board/fvp_ve/fvp_ve_err.c [new file with mode: 0644]
plat/arm/board/fvp_ve/platform.mk
plat/arm/board/juno/juno_bl1_setup.c
plat/arm/board/juno/juno_err.c
plat/arm/board/juno/platform.mk
plat/arm/board/n1sdp/n1sdp_bl31_setup.c
plat/arm/board/n1sdp/n1sdp_def.h
plat/arm/board/rde1edge/platform.mk
plat/arm/board/rde1edge/rde1edge_err.c [new file with mode: 0644]
plat/arm/board/rdn1edge/platform.mk
plat/arm/board/rdn1edge/rdn1edge_err.c [new file with mode: 0644]
plat/arm/board/sgi575/platform.mk
plat/arm/board/sgi575/sgi575_err.c [new file with mode: 0644]
plat/arm/board/sgm775/platform.mk
plat/arm/board/sgm775/sgm775_err.c [new file with mode: 0644]
plat/arm/common/arm_err.c
plat/hisilicon/hikey/hikey_ddr.c
plat/hisilicon/hikey/include/hi6220_regs_ao.h
plat/hisilicon/hikey/include/hi6220_regs_peri.h
plat/hisilicon/hikey960/drivers/pwrc/hisi_pwrc.c
plat/hisilicon/hikey960/include/hi3660.h
plat/hisilicon/hikey960/include/hi3660_crg.h
plat/hisilicon/hikey960/include/hi3660_hkadc.h
plat/imx/common/sci/imx8_mu.h
plat/imx/imx8m/imx8m_caam.c [new file with mode: 0644]
plat/imx/imx8m/imx8mm/imx8mm_bl31_setup.c
plat/imx/imx8m/imx8mm/include/platform_def.h
plat/imx/imx8m/imx8mm/platform.mk
plat/imx/imx8m/imx8mq/imx8mq_bl31_setup.c
plat/imx/imx8m/imx8mq/include/platform_def.h
plat/imx/imx8m/imx8mq/platform.mk
plat/imx/imx8m/include/imx8m_caam.h [new file with mode: 0644]
plat/intel/soc/agilex/aarch64/plat_helpers.S [new file with mode: 0644]
plat/intel/soc/agilex/aarch64/platform_common.c [new file with mode: 0644]
plat/intel/soc/agilex/bl2_plat_mem_params_desc.c [new file with mode: 0644]
plat/intel/soc/agilex/bl2_plat_setup.c [new file with mode: 0644]
plat/intel/soc/agilex/bl31_plat_setup.c [new file with mode: 0644]
plat/intel/soc/agilex/include/agilex_clock_manager.h [new file with mode: 0644]
plat/intel/soc/agilex/include/agilex_handoff.h [new file with mode: 0644]
plat/intel/soc/agilex/include/agilex_mailbox.h [new file with mode: 0644]
plat/intel/soc/agilex/include/agilex_memory_controller.h [new file with mode: 0644]
plat/intel/soc/agilex/include/agilex_noc.h [new file with mode: 0644]
plat/intel/soc/agilex/include/agilex_pinmux.h [new file with mode: 0644]
plat/intel/soc/agilex/include/agilex_private.h [new file with mode: 0644]
plat/intel/soc/agilex/include/agilex_reset_manager.h [new file with mode: 0644]
plat/intel/soc/agilex/include/agilex_system_manager.h [new file with mode: 0644]
plat/intel/soc/agilex/include/plat_macros.S [new file with mode: 0644]
plat/intel/soc/agilex/include/platform_def.h [new file with mode: 0644]
plat/intel/soc/agilex/include/socfpga_private.h [new file with mode: 0644]
plat/intel/soc/agilex/platform.mk [new file with mode: 0644]
plat/intel/soc/agilex/soc/agilex_clock_manager.c [new file with mode: 0644]
plat/intel/soc/agilex/soc/agilex_handoff.c [new file with mode: 0644]
plat/intel/soc/agilex/soc/agilex_mailbox.c [new file with mode: 0644]
plat/intel/soc/agilex/soc/agilex_memory_controller.c [new file with mode: 0644]
plat/intel/soc/agilex/soc/agilex_pinmux.c [new file with mode: 0644]
plat/intel/soc/agilex/soc/agilex_reset_manager.c [new file with mode: 0644]
plat/intel/soc/agilex/soc/agilex_system_manager.c [new file with mode: 0644]
plat/intel/soc/agilex/socfpga_delay_timer.c [new file with mode: 0644]
plat/intel/soc/agilex/socfpga_image_load.c [new file with mode: 0644]
plat/intel/soc/agilex/socfpga_psci.c [new file with mode: 0644]
plat/intel/soc/agilex/socfpga_sip_svc.c [new file with mode: 0644]
plat/intel/soc/agilex/socfpga_storage.c [new file with mode: 0644]
plat/intel/soc/agilex/socfpga_topology.c [new file with mode: 0644]
plat/intel/soc/common/drivers/qspi/cadence_qspi.h
plat/intel/soc/stratix10/include/s10_mailbox.h
plat/intel/soc/stratix10/include/s10_system_manager.h
plat/intel/soc/stratix10/soc/s10_system_manager.c
plat/layerscape/board/ls1043/ls1043_psci.c
plat/layerscape/board/ls1043/ls_gic.c
plat/layerscape/common/include/soc.h
plat/marvell/a8k/common/include/a8k_plat_def.h
plat/marvell/a8k/common/plat_ble_setup.c
plat/marvell/a8k/common/plat_pm.c
plat/mediatek/mt8183/drivers/mcsi/mcsi.h
plat/mediatek/mt8183/include/mcucfg.h
plat/mediatek/mt8183/include/platform_def.h
plat/renesas/rcar/include/rcar_version.h
plat/renesas/rcar/rcar_common.c
plat/rockchip/rk3328/drivers/pmu/pmu.c
plat/rockchip/rk3368/drivers/ddr/ddr_rk3368.c
plat/rockchip/rk3368/drivers/ddr/ddr_rk3368.h
plat/rockchip/rk3368/drivers/soc/soc.h
plat/rockchip/rk3399/drivers/dram/dfs.c
plat/rockchip/rk3399/drivers/dram/suspend.c
plat/rockchip/rk3399/drivers/pmu/m0_ctl.c
plat/socionext/synquacer/include/plat.ld.S
readme.rst
services/spd/opteed/teesmc_opteed.h

index 2a5396148d29ab8ae73408952406b66cfce0b4d5..baa983dc9d0ef7efb84cdd9383691ae588d863b1 100644 (file)
@@ -43,8 +43,8 @@
 # Commit messages might contain a Gerrit Change-Id.
 --ignore GERRIT_CHANGE_ID
 
-# Do not check the format of commit messages, as Github's merge commits do not
-# observe it.
+# Do not check the format of commit messages, as Gerrit's merge commits do not
+# preserve it.
 --ignore GIT_COMMIT_ID
 
 # FILE_PATH_CHANGES reports this kind of message:
index 0e7a5c3c912dcb8fb61e3741b919c1f8440f85eb..928c307050d5c61e13a34a178f6e70930eda8d5a 100644 (file)
@@ -1,10 +1,10 @@
 #
-# Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
+# Copyright (c) 2017-2019, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
 
-# ARM Trusted Firmware Coding style spec for editors.
+# Trusted Firmware-A Coding style spec for editors.
 
 # References:
 # [EC]          http://editorconfig.org/
index 471cf59825e47b2b2c052f8afc212f6bb7f93e0b..aca57b697680e126d3a14606f203e599c4b83bde 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -256,9 +256,14 @@ WARNINGS   +=              -Wunused -Wno-unused-parameter  \
                                -Wvla
 
 ifeq ($(findstring clang,$(notdir $(CC))),)
+# not using clang
 WARNINGS       +=              -Wunused-but-set-variable       \
                                -Wmaybe-uninitialized           \
-                               -Wpacked-bitfield-compat
+                               -Wpacked-bitfield-compat        \
+                               -Wshift-overflow=2
+else
+# using clang
+WARNINGS       +=              -Wshift-overflow -Wshift-sign-overflow
 endif
 
 ifneq (${E},0)
@@ -510,9 +515,8 @@ endif
 # Process platform overrideable behaviour
 ################################################################################
 
-# Using the ARM Trusted Firmware BL2 implies that a BL33 image also needs to be
-# supplied for the FIP and Certificate generation tools. This flag can be
-# overridden by the platform.
+# Using BL2 implies that a BL33 image also needs to be supplied for the FIP and
+# Certificate generation tools. This flag can be overridden by the platform.
 ifdef BL2_SOURCES
         ifdef EL3_PAYLOAD_BASE
                 # If booting an EL3 payload there is no need for a BL33 image
index b3f59796c376afea69d25e96334e38d75da1a3f1..40506785bf182c6108a01dc8d1e313a9dc6fdf37 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2017, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2014-2019, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -45,10 +45,14 @@ non_el3_sys_regs:
                "spsr_irq", "spsr_fiq", "sctlr_el1", "actlr_el1", "cpacr_el1",\
                "csselr_el1", "sp_el1", "esr_el1", "ttbr0_el1", "ttbr1_el1",\
                "mair_el1", "amair_el1", "tcr_el1", "tpidr_el1", "tpidr_el0",\
-               "tpidrro_el0", "dacr32_el2", "ifsr32_el2", "par_el1",\
-               "mpidr_el1", "afsr0_el1", "afsr1_el1", "contextidr_el1",\
-               "vbar_el1", "cntp_ctl_el0", "cntp_cval_el0", "cntv_ctl_el0",\
-               "cntv_cval_el0", "cntkctl_el1", "sp_el0", "isr_el1", ""
+               "tpidrro_el0",  "par_el1", "mpidr_el1", "afsr0_el1", "afsr1_el1",\
+               "contextidr_el1", "vbar_el1", "cntp_ctl_el0", "cntp_cval_el0",\
+               "cntv_ctl_el0", "cntv_cval_el0", "cntkctl_el1", "sp_el0", "isr_el1", ""
+
+#if CTX_INCLUDE_AARCH32_REGS
+aarch32_regs:
+       .asciz  "dacr32_el2", "ifsr32_el2", ""
+#endif /* CTX_INCLUDE_AARCH32_REGS */
 
 panic_msg:
        .asciz "PANIC in EL3 at x30 = 0x"
@@ -299,24 +303,30 @@ func do_crash_reporting
        mrs     x9, tpidr_el1
        mrs     x10, tpidr_el0
        mrs     x11, tpidrro_el0
-       mrs     x12, dacr32_el2
-       mrs     x13, ifsr32_el2
-       mrs     x14, par_el1
-       mrs     x15, mpidr_el1
+       mrs     x12, par_el1
+       mrs     x13, mpidr_el1
+       mrs     x14, afsr0_el1
+       mrs     x15, afsr1_el1
+       bl      str_in_crash_buf_print
+       mrs     x8, contextidr_el1
+       mrs     x9, vbar_el1
+       mrs     x10, cntp_ctl_el0
+       mrs     x11, cntp_cval_el0
+       mrs     x12, cntv_ctl_el0
+       mrs     x13, cntv_cval_el0
+       mrs     x14, cntkctl_el1
+       mrs     x15, sp_el0
        bl      str_in_crash_buf_print
-       mrs     x8, afsr0_el1
-       mrs     x9, afsr1_el1
-       mrs     x10, contextidr_el1
-       mrs     x11, vbar_el1
-       mrs     x12, cntp_ctl_el0
-       mrs     x13, cntp_cval_el0
-       mrs     x14, cntv_ctl_el0
-       mrs     x15, cntv_cval_el0
+       mrs     x8, isr_el1
        bl      str_in_crash_buf_print
-       mrs     x8, cntkctl_el1
-       mrs     x9, sp_el0
-       mrs     x10, isr_el1
+
+#if CTX_INCLUDE_AARCH32_REGS
+       /* Print the AArch32 registers */
+       adr     x6, aarch32_regs
+       mrs     x8, dacr32_el2
+       mrs     x9, ifsr32_el2
        bl      str_in_crash_buf_print
+#endif /* CTX_INCLUDE_AARCH32_REGS */
 
        /* Get the cpu specific registers to report */
        bl      do_cpu_reg_dump
index 462020f589d788dc4129a701a784a31012c62e98..c8aa7cece3c1dd6a107ee526175a1124ec61c619 100644 (file)
@@ -1,10 +1,10 @@
 #
-# Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
+# Copyright (c) 2016-2019, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
-# This makefile only aims at complying with ARM Trusted Firmware build process so
-# that "optee" is a valid ARM Trusted Firmware AArch32 Secure Playload identifier.
+# This makefile only aims at complying with Trusted Firmware-A build process so
+# that "optee" is a valid TF-A AArch32 Secure Playload identifier.
 
 ifneq ($(ARCH),aarch32)
 $(error This directory targets AArch32 support)
@@ -12,4 +12,4 @@ endif
 
 $(eval $(call add_define,AARCH32_SP_OPTEE))
 
-$(info ARM Trusted Firmware built for OP-TEE payload support)
+$(info Trusted Firmware-A built for OP-TEE payload support)
index ecc65c92e1859e78c9c0a054be2b29cdf331c13c..53f8b0719d24e1eb545b90c61cfc482c86bcf57a 100644 (file)
@@ -37,6 +37,47 @@ struct frame_record {
        uintptr_t return_addr;
 };
 
+/*
+ * Strip the Pointer Authentication Code (PAC) from the address to retrieve the
+ * original one.
+ *
+ * The PAC field is stored on the high bits of the address and defined as:
+ * - PAC field = Xn[54:bottom_PAC_bit], when address tagging is used.
+ * - PAC field = Xn[63:56, 54:bottom_PAC_bit], without address tagging.
+ *
+ * With bottom_PAC_bit = 64 - TCR_ELx.TnSZ
+ */
+#if ENABLE_PAUTH
+static uintptr_t demangle_address(uintptr_t addr)
+{
+       unsigned int el, t0sz, bottom_pac_bit;
+       uint64_t tcr, pac_mask;
+
+       /*
+        * Different virtual address space size can be defined for each EL.
+        * Ensure that we use the proper one by reading the corresponding
+        * TCR_ELx register.
+        */
+       el = get_current_el();
+
+       if (el == 3U) {
+               tcr = read_tcr_el3();
+       } else if (el == 2U) {
+               tcr = read_tcr_el2();
+       } else {
+               tcr = read_tcr_el1();
+       }
+
+       /* T0SZ = TCR_ELx[5:0] */
+       t0sz = tcr & 0x1f;
+       bottom_pac_bit = 64 - t0sz;
+       pac_mask = (1ULL << bottom_pac_bit) - 1;
+
+       /* demangle the address with the computed mask */
+       return (addr & pac_mask);
+}
+#endif /* ENABLE_PAUTH */
+
 static const char *get_el_str(unsigned int el)
 {
        if (el == 3U) {
@@ -57,6 +98,15 @@ static bool is_address_readable(uintptr_t addr)
 {
        unsigned int el = get_current_el();
 
+#if ENABLE_PAUTH
+       /*
+        * When pointer authentication is enabled, the LR value saved on the
+        * stack contains a PAC. It must be stripped to retrieve the return
+        * address.
+        */
+       addr = demangle_address(addr);
+#endif
+
        if (el == 3U) {
                ats1e3r(addr);
        } else if (el == 2U) {
@@ -201,6 +251,15 @@ static void unwind_stack(struct frame_record *fr, uintptr_t current_pc,
                 */
                call_site = fr->return_addr - 4U;
 
+#if ENABLE_PAUTH
+               /*
+                * When pointer authentication is enabled, the LR value saved on
+                * the stack contains a PAC. It must be stripped to retrieve the
+                * return address.
+                */
+               call_site = demangle_address(call_site);
+#endif
+
                /*
                 * If the address is invalid it means that the frame record is
                 * probably corrupted.
index 3e174dda089265d92d49a0cf0ef88c557007e261..08d3cf481ffcae0faeb35a79c587ba76265248a6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2017-2019, Arm Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -15,7 +15,7 @@
 static unsigned int max_log_level = LOG_LEVEL;
 
 /*
- * The common log function which is invoked by ARM Trusted Firmware code.
+ * The common log function which is invoked by TF-A code.
  * This function should not be directly invoked and is meant to be
  * only used by the log macros defined in debug.h. The function
  * expects the first character in the format string to be one of the
index 71f24fd6247e1506ef5369f8da3219df0b7d1fbd..70aafc0634b48d55d09c2cce507ac2034c770066 100644 (file)
@@ -632,8 +632,8 @@ New Features
 
    -  Introduce External Abort handling on AArch64
       External Abort routed to EL3 was reported as an unhandled exception
-      and caused a panic. This change enables Arm Trusted Firmware-A to
-      handle External Aborts routed to EL3.
+      and caused a panic. This change enables Trusted Firmware-A to handle
+      External Aborts routed to EL3.
 
    -  Save value of ACTLR_EL1 implementation-defined register in the CPU
       context structure rather than forcing it to 0.
@@ -1626,7 +1626,7 @@ New features
    -  `Power Domain Topology Design`_
 
 -  Applied the new image terminology to the code base and documentation, as
-   described on the `TF-A wiki on GitHub`_.
+   described in the `image terminology document`_.
 
 -  The build system has been reworked to improve readability and facilitate
    adding future extensions.
@@ -2420,7 +2420,7 @@ releases of TF-A.
 
 --------------
 
-*Copyright (c) 2013-2018, Arm Limited and Contributors. All rights reserved.*
+*Copyright (c) 2013-2019, Arm Limited and Contributors. All rights reserved.*
 
 .. _SDEI Specification: http://infocenter.arm.com/help/topic/com.arm.doc.den0054a/ARM_DEN0054A_Software_Delegated_Exception_Interface.pdf
 .. _PSCI Integration Guide: ./getting_started/psci-lib-integration-guide.rst
@@ -2431,7 +2431,7 @@ releases of TF-A.
 .. _Firmware Design: ./design/firmware-design.rst
 .. _TF-A Reset Design: ./design/reset-design.rst
 .. _Power Domain Topology Design: ./design/psci-pd-tree.rst
-.. _TF-A wiki on GitHub: https://github.com/ARM-software/arm-trusted-firmware/wiki/ARM-Trusted-Firmware-Image-Terminology
+.. _image terminology document: ./getting_started/image-terminology.rst
 .. _Authentication Framework: ./design/auth-framework.rst
 .. _OP-TEE Dispatcher: ./spd/optee-dispatcher.rst
 .. _tf-issue#501: https://github.com/ARM-software/tf-issues/issues/501
index d6bb6ce8a2bdb4052e607e4b271b9299744b3dce..30bdc24b289187c57b5fa4c8c1cdbc1df881734d 100644 (file)
@@ -392,11 +392,11 @@ This is only allowed if the image is not being executed.
 
 --------------
 
-*Copyright (c) 2015-2018, Arm Limited and Contributors. All rights reserved.*
+*Copyright (c) 2015-2019, Arm Limited and Contributors. All rights reserved.*
 
 .. _Trusted Board Boot: ../design/trusted-board-boot.rst
 .. _Porting Guide: ../getting_started/porting-guide.rst
-.. _here: https://github.com/ARM-software/arm-trusted-firmware/wiki/ARM-Trusted-Firmware-Image-Terminology
+.. _here: ../getting_started/image-terminology.rst
 .. _Authentication Framework Design: ../design/auth-framework.rst
 .. _Universally Unique Identifier: https://tools.ietf.org/rfc/rfc4122.txt
 
index 6d0e1563d64928fe951a70dd0e1a3bbfa4fa2e66..2a777b385b0561cfa0e8fcfb8f41532fe972ddb2 100644 (file)
@@ -26,7 +26,7 @@ The following figure depicts a general sequence involving SDEI client executing
 at EL2 and an event dispatch resulting from the triggering of a bound interrupt.
 A commentary is provided below:
 
-.. image:: ../resources/diagrams/plantuml/sdei_general.svg
+.. uml:: ../resources/diagrams/plantuml/sdei_general.puml
 
 As part of initialisation, the SDEI client binds a Non-secure interrupt [1], and
 the SDEI dispatcher returns a platform dynamic event number [2]. The client then
@@ -234,7 +234,7 @@ on success, or ``-1`` on failure.
 The following figure depicts a scenario involving explicit dispatch of SDEI
 event. A commentary is provided below:
 
-.. image:: ../resources/diagrams/plantuml/sdei_explicit_dispatch.svg
+.. uml:: ../resources/diagrams/plantuml/sdei_explicit_dispatch.puml
 
 As part of initialisation, the SDEI client registers a handler for a platform
 event [1], enables the event [3], and unmasks the current PE [5]. Note that,
index ac1172c8fa431a4c4a257739c62b76d4f0905c20..de0792d15ecc1243336d2994fc3a24a961846436 100644 (file)
@@ -250,7 +250,7 @@ implemented by the SPM.
 A SVC causes an exception to be taken to S-EL1. TF-A assumes ownership of S-EL1
 and installs a simple exception vector table in S-EL1 that relays a SVC request
 from a Secure Partition as a SMC request to the SPM in EL3. Upon servicing the
-SMC request, Arm Trusted Firmware returns control directly to S-EL0 through an
+SMC request, Trusted Firmware-A returns control directly to S-EL0 through an
 ERET instruction.
 
 Calling conventions
@@ -806,7 +806,7 @@ Error Codes
 
 --------------
 
-*Copyright (c) 2017-2018, Arm Limited and Contributors. All rights reserved.*
+*Copyright (c) 2017-2019, Arm Limited and Contributors. All rights reserved.*
 
 .. _Armv8-A ARM: https://developer.arm.com/docs/ddi0487/latest/arm-architecture-reference-manual-armv8-for-armv8-a-architecture-profile
 .. _instructions in the EDK2 repository: https://github.com/tianocore/edk2-staging/blob/AArch64StandaloneMm/HowtoBuild.MD
index 64f12431bb3f4f64427717d9b8aeaced470735ad..b267de0e86311a2110c626a6e7cb98d766a1f2bf 100644 (file)
@@ -23,7 +23,7 @@ release = version # We don't need these to be distinct
 # Add any Sphinx extension module names here, as strings. They can be
 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
 # ones.
-extensions = ['sphinx.ext.autosectionlabel']
+extensions = ['sphinx.ext.autosectionlabel', 'sphinxcontrib.plantuml']
 
 # Add any paths that contain templates here, relative to this directory.
 templates_path = ['_templates']
@@ -82,4 +82,8 @@ html_theme_options = {
 # -- Options for autosectionlabel --------------------------------------------
 
 # Only generate automatic section labels for document titles
-autosectionlabel_maxdepth = 1
\ No newline at end of file
+autosectionlabel_maxdepth = 1
+
+# -- Options for plantuml ----------------------------------------------------
+
+plantuml_output_format = 'svg_img'
index 72865a5176f4b0ec8514ca1acf2f96968935d98c..b327f6ee31eee8eb702230cbaf7b29dbed630082 100644 (file)
@@ -2762,14 +2762,12 @@ can be obtained from http://github.com/freebsd/freebsd.
 Storage abstraction layer
 -------------------------
 
-In order to improve platform independence and portability an storage abstraction
-layer is used to load data from non-volatile platform storage.
+In order to improve platform independence and portability a storage abstraction
+layer is used to load data from non-volatile platform storage. Currently
+storage access is only required by BL1 and BL2 phases and performed inside the
+``load_image()`` function in ``bl_common.c``.
 
-Each platform should register devices and their drivers via the Storage layer.
-These drivers then need to be initialized by bootloader phases as
-required in their respective ``blx_platform_setup()`` functions. Currently
-storage access is only required by BL1 and BL2 phases. The ``load_image()``
-function uses the storage layer to access non-volatile platform storage.
+.. uml:: ../resources/diagrams/plantuml/io_framework_usage_overview.puml
 
 It is mandatory to implement at least one storage driver. For the Arm
 development platforms the Firmware Image Package (FIP) driver is provided as
@@ -2779,13 +2777,25 @@ section in the `User Guide`_). The storage layer is described in the header file
 is in ``drivers/io/io_storage.c`` and the driver files are located in
 ``drivers/io/``.
 
+.. uml:: ../resources/diagrams/plantuml/io_arm_class_diagram.puml
+
 Each IO driver must provide ``io_dev_*`` structures, as described in
 ``drivers/io/io_driver.h``. These are returned via a mandatory registration
 function that is called on platform initialization. The semi-hosting driver
 implementation in ``io_semihosting.c`` can be used as an example.
 
-The Storage layer provides mechanisms to initialize storage devices before
-IO operations are called. The basic operations supported by the layer
+Each platform should register devices and their drivers via the storage
+abstraction layer. These drivers then need to be initialized by bootloader
+phases as required in their respective ``blx_platform_setup()`` functions.
+
+.. uml:: ../resources/diagrams/plantuml/io_dev_registration.puml
+
+The storage abstraction layer provides mechanisms (``io_dev_init()``) to
+initialize storage devices before IO operations are called.
+
+.. uml:: ../resources/diagrams/plantuml/io_dev_init_and_check.puml
+
+The basic operations supported by the layer
 include ``open()``, ``close()``, ``read()``, ``write()``, ``size()`` and ``seek()``.
 Drivers do not have to implement all operations, but each platform must
 provide at least one driver for a device capable of supporting generic
index 02f8c5faaff5896d88736d0e086155c341191541..858996c817c77c0efc10acc39a6c55314a8a2f67 100644 (file)
@@ -1720,8 +1720,8 @@ Arm FVPs without shifted affinities, and that do not support threaded CPU cores
 -  ``FVP_Base_Cortex-A76x4``
 -  ``FVP_Base_Cortex-A76AEx4``
 -  ``FVP_Base_Cortex-A76AEx8``
+-  ``FVP_Base_Cortex-A77x4`` (Version 11.7 build 36)
 -  ``FVP_Base_Neoverse-N1x4``
--  ``FVP_Base_Deimos``
 -  ``FVP_CSS_SGI-575`` (Version 11.3 build 42)
 -  ``FVP_CSS_SGM-775`` (Version 11.3 build 42)
 -  ``FVP_RD_E1Edge`` (Version 11.3 build 42)
index 7ac0584cc0c7b58ee5ad31d1c391d30402e21cbc..2023ceb1d9cf976cd6292bfe94397c90fbe0eacf 100644 (file)
@@ -176,8 +176,8 @@ Arm FVPs without shifted affinities, and that do not support threaded CPU cores
 -  ``FVP_Base_Cortex-A76x4``
 -  ``FVP_Base_Cortex-A76AEx4`` (Tested with internal model)
 -  ``FVP_Base_Cortex-A76AEx8`` (Tested with internal model)
+-  ``FVP_Base_Cortex-A77x4`` (Version 11.7 build 36)
 -  ``FVP_Base_Neoverse-N1x4`` (Tested with internal model)
--  ``FVP_Base_Deimos``
 -  ``FVP_CSS_SGI-575`` (Version 11.3 build 42)
 -  ``FVP_CSS_SGM-775`` (Version 11.3 build 42)
 -  ``FVP_RD_E1Edge`` (Version 11.3 build 42)
index 098fc5f5b8b16cbdcdc7457b3773481cef091113..cbfc652fb08af1d4f5c12e10af03930a0c30540b 100644 (file)
@@ -112,8 +112,11 @@ HiSilicon Poplar platform port
 Intel SocFPGA platform ports
 ----------------------------
 :M: Tien Hock Loh <tien.hock.loh@intel.com>
-:G: `thloh85-intel`
+:G: `thloh85-intel`_
+:M: Hadi Asyrafi <muhammad.hadi.asyrafi.abdul.halim@intel.com>
+:G: `mabdulha`_
 :F: plat/intel/soc
+:F: drivers/intel/soc/
 
 MediaTek platform ports
 -----------------------
index b6fd8c8039c4b9d2caee7382cac838158e2c384b..4cc43026579b6c00390bce2a5cef3d5766a82db9 100644 (file)
@@ -2,9 +2,9 @@ PSCI Performance Measurements on Arm Juno Development Platform
 ==============================================================
 
 This document summarises the findings of performance measurements of key
-operations in the ARM Trusted Firmware (TF) Power State Coordination Interface
-(PSCI) implementation, using the in-built Performance Measurement Framework
-(PMF) and runtime instrumentation timestamps.
+operations in the Trusted Firmware-A Power State Coordination Interface (PSCI)
+implementation, using the in-built Performance Measurement Framework (PMF) and
+runtime instrumentation timestamps.
 
 Method
 ------
@@ -284,5 +284,9 @@ performance.
 We suspect the time for lead CPU 4 is shorter than CPU 5 due to subtle cache
 effects, given that these measurements are at the nano-second level.
 
+--------------
+
+*Copyright (c) 2019, Arm Limited and Contributors. All rights reserved.*
+
 .. _Juno R1 platform: https://www.arm.com/files/pdf/Juno_r1_ARM_Dev_datasheet.pdf
 .. _TF master as of 31/01/2017: https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/?id=c38b36d
index 525386321408bed3f39fcefc8121ed056f8210f1..6abf9e5f7580a94b002c4f8451682f9349314b5a 100644 (file)
@@ -1,12 +1,11 @@
 Arm Versatile Express
 =====================
 
-Versatile Express (VE) family development platform provides an
-ultra fast environment for prototyping arm-v7 System-on-Chip designs.
-VE Fixed Virtual Platforms (FVP) are simulations of Versatile Express boards.
-The platform in arm-trusted-firmware has been verified with Arm Cortex-A5
-and Cortex-A7 VE FVP's. This platform is tested on and only expected to work
-with single core models.
+Versatile Express (VE) family development platform provides an ultra fast
+environment for prototyping Armv7 System-on-Chip designs. VE Fixed Virtual
+Platforms (FVP) are simulations of Versatile Express boards. The platform in
+Trusted Firmware-A has been verified with Arm Cortex-A5 and Cortex-A7 VE FVP's.
+This platform is tested on and only expected to work with single core models.
 
 Boot Sequence
 -------------
@@ -20,7 +19,7 @@ Code Locations
 ~~~~~~~~~~~~~~
 -  `U-boot <https://git.linaro.org/landing-teams/working/arm/u-boot.git>`__
 
--  `arm-trusted-firmware <https://github.com/ARM-software/arm-trusted-firmware>`__
+-  `Trusted Firmware-A <https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git>`__
 
 Build Procedure
 ~~~~~~~~~~~~~~~
@@ -71,7 +70,7 @@ Run Procedure
 ~~~~~~~~~~~~~
 
 The following model parameters should be used to boot Linux using the build of
-arm-trusted-firmware-a made using the above make commands:
+Trusted Firmware-A made using the above make commands:
 
   .. code:: shell
 
diff --git a/docs/plat/intel-agilex.rst b/docs/plat/intel-agilex.rst
new file mode 100644 (file)
index 0000000..015a195
--- /dev/null
@@ -0,0 +1,85 @@
+Intel Agilex SoCFPGA
+========================
+
+Agilex SoCFPGA is a FPGA with integrated quad-core 64-bit Arm Cortex A53 processor.
+
+Upon boot, Boot ROM loads bl2 into OCRAM. Bl2 subsequently initializes
+the hardware, then loads bl31 and bl33 (UEFI) into DDR and boots to bl33.
+
+::
+
+    Boot ROM --> Trusted Firmware-A --> UEFI
+
+How to build
+------------
+
+Code Locations
+~~~~~~~~~~~~~~
+
+-  Trusted Firmware-A:
+   `link <https://github.com/ARM-software/arm-trusted-firmware>`__
+
+-  UEFI (to be updated with new upstreamed UEFI):
+   `link <https://github.com/altera-opensource/uefi-socfpga>`__
+
+Build Procedure
+~~~~~~~~~~~~~~~
+
+-  Fetch all the above 2 repositories into local host.
+   Make all the repositories in the same ${BUILD\_PATH}.
+
+-  Prepare the AARCH64 toolchain.
+
+-  Build UEFI using Agilex platform as configuration
+   This will be updated to use an updated UEFI using the latest EDK2 source
+
+.. code:: bash
+
+       make CROSS_COMPILE=aarch64-linux-gnu- device=agx
+
+-  Build atf providing the previously generated UEFI as the BL33 image
+
+.. code:: bash
+
+       make CROSS_COMPILE=aarch64-linux-gnu- bl2 fip PLAT=agilex
+       BL33=PEI.ROM
+
+Install Procedure
+~~~~~~~~~~~~~~~~~
+
+- dd fip.bin to a A2 partition on the MMC drive to be booted in Agilex
+  board.
+
+- Generate a SOF containing bl2
+
+.. code:: bash
+
+        aarch64-linux-gnu-objcopy -I binary -O ihex --change-addresses 0xffe00000 bl2.bin bl2.hex
+        quartus_cpf --bootloader bl2.hex <quartus_generated_sof> <output_sof_with_bl2>
+
+- Configure SOF to board
+
+.. code:: bash
+
+        nios2-configure-sof <output_sof_with_bl2>
+
+Boot trace
+----------
+
+::
+        INFO:    DDR: DRAM calibration success.
+        INFO:    ECC is disabled.
+        NOTICE:  BL2: v2.1(debug)
+        NOTICE:  BL2: Built
+        INFO:    BL2: Doing platform setup
+        NOTICE:  BL2: Booting BL31
+        INFO:    Entry point address = 0xffe1c000
+        INFO:    SPSR = 0x3cd
+        NOTICE:  BL31: v2.1(debug)
+        NOTICE:  BL31: Built
+        INFO:    ARM GICv2 driver initialized
+        INFO:    BL31: Initializing runtime services
+        WARNING: BL31: cortex_a53
+        INFO:    BL31: Preparing for EL3 exit to normal world
+        INFO:    Entry point address = 0x50000
+        INFO:    SPSR = 0x3c9
index 093d66be3e45fe73cf57e209401be3e99513510c..a53da77b94ccba777328f674afe1f2df6953eb69 100644 (file)
@@ -272,15 +272,15 @@ used (Banned) or are discouraged from use and must be used with care (Caution).
 +------------------------+-----------+--------------------------------------+
 |    libc function       | Status    | Comments                             |
 +========================+===========+======================================+
-| ``strcpy, wcscpy``     | Banned    | use strlcpy instead                  |
+| ``strcpy, wcscpy``,    | Banned    | use strlcpy instead                  |
 | ``strncpy``            |           |                                      |
 +------------------------+-----------+--------------------------------------+
-| ``strcat, wcscat``     | Banned    | use strlcat instead                  |
+| ``strcat, wcscat``,    | Banned    | use strlcat instead                  |
 | ``strncat``            |           |                                      |
-+----------------------- +-----------+--------------------------------------+
++------------------------+-----------+--------------------------------------+
 | ``sprintf, vsprintf``  | Banned    | use snprintf, vsnprintf              |
 |                        |           | instead                              |
-+---------------------- -+-----------+--------------------------------------+
++------------------------+-----------+--------------------------------------+
 | ``snprintf``           | Caution   | ensure result fits in buffer         |
 |                        |           | i.e : snprintf(buf,size...) < size   |
 +------------------------+-----------+--------------------------------------+
index 1c80eb5626ae08909a4346dd73a0f9851f48b9de..a11ba3860dc3f7b456b466aee345f99758d98018 100644 (file)
@@ -20,18 +20,19 @@ introduced to replace it. In case the migration to the new interface is trivial,
 the contributor of the change is expected to make good effort to migrate the
 upstream platforms to the new interface.
 
-The `Release information`_ documents the deprecated interfaces and the intended
-release after which it will be removed. When an interface is deprecated, the
-page must be updated to indicate the release after which the interface will be
-removed. This must be at least 1 full release cycle in future. For non-trivial
-interface changes, a `tf-issue`_ should be posted to notify platforms that they
-should migrate away from the deprecated interfaces. Platforms are expected to
-migrate before the removal of the deprecated interface.
+The deprecated interfaces are listed inside `Release information`_ as well as
+the release after which each one will be removed. When an interface is
+deprecated, the page must be updated to indicate the release after which the
+interface will be removed. This must be at least 1 full release cycle in future.
+For non-trivial interface changes, an email should be sent out to the `TF-A
+public mailing list`_ to notify platforms that they should migrate away from the
+deprecated interfaces. Platforms are expected to migrate before the removal of
+the deprecated interface.
 
 --------------
 
-*Copyright (c) 2018, Arm Limited and Contributors. All rights reserved.*
+*Copyright (c) 2018-2019, Arm Limited and Contributors. All rights reserved.*
 
 .. _Porting Guide: ../getting_started/porting-guide.rst
-.. _Release information: https://github.com/ARM-software/arm-trusted-firmware/wiki/TF-A-Release-information#removal-of-deprecated-interfaces
-.. _tf-issue: https://github.com/ARM-software/tf-issues/issues
+.. _Release information: ./release-information.rst#removal-of-deprecated-interfaces
+.. _TF-A public mailing list: https://lists.trustedfirmware.org/mailman/listinfo/tf-a
index 8f95774b6bcf37d23d5b940ae1116fef98d0a3c7..358ed0e3cc7a2ed4021e7cec2820138f4a38617b 100644 (file)
@@ -1,2 +1,3 @@
 sphinx>=2.0.0
-sphinx-rtd-theme>=0.4.3
\ No newline at end of file
+sphinx-rtd-theme>=0.4.3
+sphinxcontrib-plantuml>=0.15
index de7d8f3ffc11c19795e9b0e2d2ef6fee683cf284..7f583b52428a65f3fea8ebe52a8cc7ea2f9c8327 100644 (file)
@@ -1,10 +1,10 @@
 #
-# Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
+# Copyright (c) 2015-2019, Arm Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
 #
-# This Makefile generates the image files used in the ARM Trusted Firmware
+# This Makefile generates the image files used in the Trusted Firmware-A
 # document from the dia file.
 #
 # The PNG files in the present directory have been generated using Dia version
diff --git a/docs/resources/diagrams/plantuml/io_arm_class_diagram.puml b/docs/resources/diagrams/plantuml/io_arm_class_diagram.puml
new file mode 100644 (file)
index 0000000..53594c2
--- /dev/null
@@ -0,0 +1,109 @@
+@startuml
+
+package arm_io_storage {
+
+       class plat_io_policy {
+               dev_handle : uintptr_t*
+               image_spec : uintptr_t
+               {abstract} check() : fctptr
+       }
+
+       class FIP_IMAGE_ID {
+               memmap_dev_handle
+               fip_block_spec
+               open_memmap()
+       }
+
+       class BL2_IMAGE_ID{
+               fip_dev_handle
+               bl2_uuid_spec
+               open_fip()
+       }
+
+       class xxx_IMAGE_ID{
+               fip_dev_handle
+               xxx_uuid_spec
+               open_fip()
+       }
+
+       class arm_io_storage {
+               fip_dev_con : io_dev_connector_t*
+               fip_dev_handle : uintptr_t
+               memmap_dev_con : io_dev_connector_t*
+               memmap_dev_handle : uintptr_t
+
+               fip_block_spec : io_block_spec_t
+
+               policies : plat_io_policy[1..*]
+
+               -open_fip()
+               -open_memmap()
+
+               +arm_io_setup()
+               +plat_get_image_source()
+       }
+
+       FIP_IMAGE_ID -up-|> plat_io_policy
+       BL2_IMAGE_ID -up-|> plat_io_policy
+       xxx_IMAGE_ID -up-|> plat_io_policy
+
+       arm_io_storage *-"1..*" plat_io_policy
+}
+
+package IO {
+       class  io_storage {
+               io_dev_open()
+               io_dev_init()
+               io_dev_close()
+
+               .. synchronous operations ..
+               io_open()
+               io_seek()
+               io_size()
+               io_read()
+               io_write()
+               io_close()
+
+               io_register_device()
+       }
+
+       class io_fip {
+               register_io_dev_fip()
+               .. io_dev_funcs_t interface ..
+               fip_dev_funcs : io_dev_funcs_t
+       }
+
+       class io_memmap {
+               register_io_dev_memmap()
+               .. io_dev_funcs_t interface ..
+               memmap_dev_funcs : io_dev_funcs_t
+       }
+
+       interface io_driver {
+               io_entity_t
+               io_dev_info_t
+
+               .. io_dev_connector_t interface ..
+               dev_open()
+
+               .. io_dev_funcs_t interface ..
+                       type()
+                       open()
+                       seek()
+                       size()
+                       read()
+                       write()
+                       close()
+                       dev_init()
+                       dev_close()
+
+               io_register_device()
+       }
+}
+arm_io_storage .. io_driver
+arm_io_storage .. io_fip
+arm_io_storage .. io_memmap
+arm_io_storage .. io_storage
+
+
+@enduml
diff --git a/docs/resources/diagrams/plantuml/io_dev_init_and_check.puml b/docs/resources/diagrams/plantuml/io_dev_init_and_check.puml
new file mode 100644 (file)
index 0000000..2752b33
--- /dev/null
@@ -0,0 +1,62 @@
+@startuml
+
+participant arm_io_storage order 1
+participant io_storage order 2
+
+ -> arm_io_storage : plat_get_image_source(image_id, &dev_handle, &image_spec)
+
+group init and check device (image_id)
+
+alt image_id = BL2_IMAGE_ID
+note over arm_io_storage
+       get BL2_IMAGE_ID policy:
+       - fip_dev_handle
+       - open_fip()
+end note
+opt policy->check()
+       arm_io_storage -> arm_io_storage : open_fip(spec)
+       activate arm_io_storage
+       arm_io_storage -> io_storage : io_dev_init(fip_dev_handle, FIP_IMAGE_ID)
+       ref over io_storage : dev_init() on fip device
+
+       arm_io_storage -> io_storage : io_open(fip_dev_handle, spec, &local_image_handle)
+       ref over io_storage : io_open() on fip device
+
+       arm_io_storage -> io_storage : io_close(local_image_handle)
+       ref over io_storage : io_close() on fip device
+
+       hnote over arm_io_storage
+               fip_dev_handle ready
+       end note
+end opt
+deactivate arm_io_storage
+
+else image_id = FIP_IMAGE_ID
+activate arm_io_storage
+note over arm_io_storage
+       get FIP_IMAGE_ID policy:
+       - memmap_dev_handle
+       - open_memmap()
+end note
+opt policy->check()
+       arm_io_storage -> arm_io_storage : open_memmap(spec)
+       activate arm_io_storage
+       arm_io_storage -> io_storage : io_dev_init(memmap_dev_handle, NULL)
+       ref over io_storage : dev_init() on memmap device
+
+       arm_io_storage -> io_storage : io_open(memmap_dev_handle, spec, &local_image_handle)
+       ref over io_storage : io_open() on memmap device
+
+       arm_io_storage -> io_storage : io_close(local_image_handle)
+       ref over io_storage : io_close() on memmap device
+
+       hnote over arm_io_storage
+               memmap_dev_handle ready
+       end note
+       deactivate arm_io_storage
+end  opt
+deactivate arm_io_storage
+end alt
+
+end group
+@enduml
diff --git a/docs/resources/diagrams/plantuml/io_dev_registration.puml b/docs/resources/diagrams/plantuml/io_dev_registration.puml
new file mode 100644 (file)
index 0000000..114c3b7
--- /dev/null
@@ -0,0 +1,52 @@
+@startuml
+
+participant arm_io_storage order 1
+participant io_storage order 2
+participant io_fip order 3
+participant io_memmap order 4
+
+ -> arm_io_storage : arm_io_setup()
+
+group io dev registration
+
+arm_io_storage -> io_fip : register_io_dev_fip(&fip_dev_con)
+io_fip -> io_storage : io_register_device(&dev_info_pool[])
+note over io_storage
+       devices[dev_count] = (fip_)dev_info_pool
+       dev_count++
+end note
+
+arm_io_storage -> io_memmap : register_io_dev_memmap(&memmap_dev_con)
+io_memmap -> io_storage : io_register_device(&memmap_dev_info)
+note over io_storage
+       devices[dev_count] = memmap_dev_info
+       dev_count++
+end note
+
+arm_io_storage -> io_storage : io_dev_open(fip_dev_con, NULL, fip_dev_handle)
+ io_storage -> io_storage : dev_open(dev_con, dev_spec, handle)
+activate io_storage
+opt dev_open() on fip device
+       io_storage -> io_fip : fip_dev_open(dev_spec, dev_info)
+       note over io_fip
+               dev_info = one of the
+               "fip_dev_info" from
+               dev_info_pool[]
+       end note
+end opt
+deactivate io_storage
+
+
+arm_io_storage -> io_storage : io_dev_open(memmap_dev_con, NULL, memmap_dev_handle)
+io_storage -> io_storage : dev_open(dev_con, dev_spec, handle)
+activate io_storage
+opt dev_open() on memmap device
+       io_storage -> io_memmap : memmap_dev_open(dev_spec, dev_info)
+       note over io_memmap
+               dev_info = memmap_dev_info
+       end note
+end opt
+deactivate io_storage
+
+end group
+@enduml
diff --git a/docs/resources/diagrams/plantuml/io_framework_usage_overview.puml b/docs/resources/diagrams/plantuml/io_framework_usage_overview.puml
new file mode 100644 (file)
index 0000000..eb3e2b4
--- /dev/null
@@ -0,0 +1,59 @@
+@startuml
+
+participant bl_common order 1
+participant arm_io_storage order 2
+participant io_storage order 3
+
+== Platform Setup ==
+
+bl1_main -> xxx_bl1_setup : bl1_platform_setup()
+xxx_bl1_setup -> arm_io_storage : plat_arm_io_setup()
+
+arm_io_storage -> arm_io_storage : arm_io_setup()
+ref over arm_io_storage, io_storage : io device registration
+
+== Get Image ==
+bl1_main -> xxx_bl1_setup : bl1_plat_get_next_image_id()
+bl1_main <-- xxx_bl1_setup : BL2_IMAGE_ID
+
+bl1_main -> bl1_main : bl1_load_bl2()
+activate bl1_main
+bl1_main -> plat_bl1_common : bl1_plat_get_image_desc(BL2_IMAGE_ID)
+bl1_main <-- plat_bl1_common : BL2_IMAGE_DESC
+
+bl1_main -> plat_bl1_common : bl1_plat_handle_pre_image_load(BL2_IMAGE_ID)
+
+bl1_main -> bl_common : load_auth_image(BL2_IMAGE_ID, image_info)
+activate bl_common
+bl_common -> bl_common : load_auth_image_internal(BL2_IMAGE_ID, image_info, is_parent_image)
+activate bl_common
+bl_common -> bl_common : load_image(BL2_IMAGE_ID, image_info)
+activate bl_common
+bl_common -> arm_io_storage : plat_get_image_source(BL2_IMAGE_ID, &dev_handle, &image_spec)
+ref over arm_io_storage, io_storage : init and check device (BL2_IMAGE_ID)
+bl_common <-- arm_io_storage : dev_handle
+
+bl_common -> io_storage : io_open(dev_handle, image_spec, &image_handle)
+ref over io_storage : io_open() on fip device
+bl_common <-- io_storage : image_handle
+bl_common -> io_storage : io_size(image_handle, &image_size)
+ref over io_storage : io_size() on fip device
+bl_common -> io_storage : io_read(image_handle, image_base, image_size, &bytes_read)
+ref over io_storage : io_read() on fip device
+bl_common -> io_storage : io_close(image_handle)
+ref over io_storage : io_close() on fip device
+bl_common -> io_storage : io_dev_close(dev_handle)
+ref over io_storage : io_dev_close() on fip device
+
+deactivate bl_common
+deactivate bl_common
+deactivate bl_common
+
+== Prepare Next Image ==
+bl1_main -> plat_bl1_common : bl1_plat_handle_post_image_load(BL2_IMAGE_ID)
+
+deactivate bl1_main
+
+== Jump to next Image ==
+
+@enduml
diff --git a/docs/resources/diagrams/plantuml/plantuml_to_svg.sh b/docs/resources/diagrams/plantuml/plantuml_to_svg.sh
deleted file mode 100644 (file)
index 0bf8588..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/bash
-
-# Convert all PlantUML files in this directory to SVG files. The plantuml_jar
-# environment variable must be set to the path to PlantUML JAR file.
-
-if [ -z "$plantuml_jar" ]; then
-       echo "Usage: plantuml_jar=/path/to/plantuml.jar $0 *.puml" >&2
-       exit 1
-fi
-
-java -jar "$plantuml_jar" -nometadata -tsvg "$@"
-
-# vim:set noet sts=8 tw=80:
diff --git a/docs/resources/diagrams/plantuml/sdei_explicit_dispatch.svg b/docs/resources/diagrams/plantuml/sdei_explicit_dispatch.svg
deleted file mode 100644 (file)
index e12cae2..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentScriptType="application/ecmascript" contentStyleType="text/css" height="783px" preserveAspectRatio="none" style="width:745px;height:783px;" version="1.1" viewBox="0 0 745 783" width="745px" zoomAndPan="magnify"><defs><filter height="300%" id="f18zq03ani7xpz" width="300%" x="-1" y="-1"><feGaussianBlur result="blurOut" stdDeviation="2.0"/><feColorMatrix in="blurOut" result="blurOut2" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .4 0"/><feOffset dx="4.0" dy="4.0" in="blurOut2" result="blurOut3"/><feBlend in="SourceGraphic" in2="blurOut3" mode="normal"/></filter></defs><g><rect fill="#FFFFFF" filter="url(#f18zq03ani7xpz)" height="174.7969" style="stroke: #FFFFFF; stroke-width: 1.0;" width="10" x="56.5" y="48.2969"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="56.5" x2="56.5" y1="48.2969" y2="223.0938"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="66.5" y1="48.2969" y2="223.0938"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="56.5" x2="66.5" y1="48.2969" y2="48.2969"/><rect fill="#FFFFFF" filter="url(#f18zq03ani7xpz)" height="428.7266" style="stroke: #FFFFFF; stroke-width: 1.0;" width="10" x="56.5" y="263.8984"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="56.5" x2="56.5" y1="263.8984" y2="692.625"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="66.5" y1="263.8984" y2="692.625"/><rect fill="#FFFFFF" filter="url(#f18zq03ani7xpz)" height="1" style="stroke: #FFFFFF; stroke-width: 1.0;" width="10" x="56.5" y="733.4297"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="56.5" x2="56.5" y1="733.4297" y2="734.4297"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="66.5" y1="733.4297" y2="734.4297"/><rect fill="#FA8072" filter="url(#f18zq03ani7xpz)" height="68.2656" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="61.5" y="489.8281"/><rect fill="#FF0000" filter="url(#f18zq03ani7xpz)" height="68.2656" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="375.5" y="285.0313"/><rect fill="#FA8072" filter="url(#f18zq03ani7xpz)" height="204.7969" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="432" y="421.5625"/><rect fill="#FA8072" filter="url(#f18zq03ani7xpz)" height="68.2656" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="641" y="353.2969"/><rect fill="#FA8072" filter="url(#f18zq03ani7xpz)" height="29.1328" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="641" y="626.3594"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="61" x2="61" y1="38.2969" y2="223.0938"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 1.0,4.0;" x1="61" x2="61" y1="223.0938" y2="263.8984"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="61" x2="61" y1="263.8984" y2="692.625"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 1.0,4.0;" x1="61" x2="61" y1="692.625" y2="733.4297"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="61" x2="61" y1="733.4297" y2="743.4297"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="380" x2="380" y1="38.2969" y2="223.0938"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 1.0,4.0;" x1="380" x2="380" y1="223.0938" y2="263.8984"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="380" x2="380" y1="263.8984" y2="692.625"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 1.0,4.0;" x1="380" x2="380" y1="692.625" y2="733.4297"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="380" x2="380" y1="733.4297" y2="743.4297"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="437" x2="437" y1="38.2969" y2="223.0938"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 1.0,4.0;" x1="437" x2="437" y1="223.0938" y2="263.8984"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="437" x2="437" y1="263.8984" y2="692.625"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 1.0,4.0;" x1="437" x2="437" y1="692.625" y2="733.4297"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="437" x2="437" y1="733.4297" y2="743.4297"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="646" x2="646" y1="38.2969" y2="223.0938"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 1.0,4.0;" x1="646" x2="646" y1="223.0938" y2="263.8984"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="646" x2="646" y1="263.8984" y2="692.625"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 1.0,4.0;" x1="646" x2="646" y1="692.625" y2="733.4297"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="646" x2="646" y1="733.4297" y2="743.4297"/><rect fill="#FEFECE" filter="url(#f18zq03ani7xpz)" height="30.2969" style="stroke: #A80036; stroke-width: 1.5;" width="87" x="16" y="3"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="73" x="23" y="22.9951">SDEI client</text><rect fill="#FEFECE" filter="url(#f18zq03ani7xpz)" height="30.2969" style="stroke: #A80036; stroke-width: 1.5;" width="87" x="16" y="742.4297"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="73" x="23" y="762.4248">SDEI client</text><rect fill="#FEFECE" filter="url(#f18zq03ani7xpz)" height="30.2969" style="stroke: #A80036; stroke-width: 1.5;" width="39" x="359" y="3"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="25" x="366" y="22.9951">EL3</text><rect fill="#FEFECE" filter="url(#f18zq03ani7xpz)" height="30.2969" style="stroke: #A80036; stroke-width: 1.5;" width="39" x="359" y="742.4297"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="25" x="366" y="762.4248">EL3</text><rect fill="#FEFECE" filter="url(#f18zq03ani7xpz)" height="30.2969" style="stroke: #A80036; stroke-width: 1.5;" width="46" x="412" y="3"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="32" x="419" y="22.9951">SDEI</text><rect fill="#FEFECE" filter="url(#f18zq03ani7xpz)" height="30.2969" style="stroke: #A80036; stroke-width: 1.5;" width="46" x="412" y="742.4297"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="32" x="419" y="762.4248">SDEI</text><rect fill="#FEFECE" filter="url(#f18zq03ani7xpz)" height="30.2969" style="stroke: #A80036; stroke-width: 1.5;" width="86" x="601" y="3"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="72" x="608" y="22.9951">RAS Driver</text><rect fill="#FEFECE" filter="url(#f18zq03ani7xpz)" height="30.2969" style="stroke: #A80036; stroke-width: 1.5;" width="86" x="601" y="742.4297"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="72" x="608" y="762.4248">RAS Driver</text><rect fill="#FFFFFF" filter="url(#f18zq03ani7xpz)" height="174.7969" style="stroke: #FFFFFF; stroke-width: 1.0;" width="10" x="56.5" y="48.2969"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="56.5" x2="56.5" y1="48.2969" y2="223.0938"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="66.5" y1="48.2969" y2="223.0938"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="56.5" x2="66.5" y1="48.2969" y2="48.2969"/><rect fill="#FFFFFF" filter="url(#f18zq03ani7xpz)" height="428.7266" style="stroke: #FFFFFF; stroke-width: 1.0;" width="10" x="56.5" y="263.8984"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="56.5" x2="56.5" y1="263.8984" y2="692.625"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="66.5" y1="263.8984" y2="692.625"/><rect fill="#FFFFFF" filter="url(#f18zq03ani7xpz)" height="1" style="stroke: #FFFFFF; stroke-width: 1.0;" width="10" x="56.5" y="733.4297"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="56.5" x2="56.5" y1="733.4297" y2="734.4297"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="66.5" y1="733.4297" y2="734.4297"/><rect fill="#FA8072" filter="url(#f18zq03ani7xpz)" height="68.2656" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="61.5" y="489.8281"/><rect fill="#FF0000" filter="url(#f18zq03ani7xpz)" height="68.2656" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="375.5" y="285.0313"/><rect fill="#FA8072" filter="url(#f18zq03ani7xpz)" height="204.7969" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="432" y="421.5625"/><rect fill="#FA8072" filter="url(#f18zq03ani7xpz)" height="68.2656" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="641" y="353.2969"/><rect fill="#FA8072" filter="url(#f18zq03ani7xpz)" height="29.1328" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="641" y="626.3594"/><polygon fill="#A80036" points="368.5,65.4297,378.5,69.4297,368.5,73.4297,372.5,69.4297" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="374.5" y1="69.4297" y2="69.4297"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="21" x="73.5" y="64.3638">[1]</text><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="164" x="98.5" y="64.3638">SDEI_EVENT_REGISTER</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="101" x="262.5" y="64.3638">(ev, handler, ...)</text><polygon fill="#A80036" points="77.5,94.5625,67.5,98.5625,77.5,102.5625,73.5,98.5625" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="71.5" x2="379.5" y1="98.5625" y2="98.5625"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="21" x="83.5" y="93.4966">[2]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="51" x="108.5" y="93.4966">success</text><polygon fill="#A80036" points="368.5,123.6953,378.5,127.6953,368.5,131.6953,372.5,127.6953" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="374.5" y1="127.6953" y2="127.6953"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="21" x="73.5" y="122.6294">[3]</text><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="151" x="98.5" y="122.6294">SDEI_EVENT_ENABLE</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="25" x="249.5" y="122.6294">(ev)</text><polygon fill="#A80036" points="77.5,152.8281,67.5,156.8281,77.5,160.8281,73.5,156.8281" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="71.5" x2="379.5" y1="156.8281" y2="156.8281"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="21" x="83.5" y="151.7622">[4]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="51" x="108.5" y="151.7622">success</text><polygon fill="#A80036" points="368.5,181.9609,378.5,185.9609,368.5,189.9609,372.5,185.9609" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="374.5" y1="185.9609" y2="185.9609"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="21" x="73.5" y="180.895">[5]</text><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="129" x="98.5" y="180.895">SDEI_PE_UNMASK</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="10" x="227.5" y="180.895">()</text><polygon fill="#A80036" points="77.5,211.0938,67.5,215.0938,77.5,219.0938,73.5,215.0938" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="71.5" x2="379.5" y1="215.0938" y2="215.0938"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="21" x="83.5" y="210.0278">[6]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="8" x="108.5" y="210.0278">1</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="142" x="282.75" y="247.3042">&lt;&lt;Business as usual&gt;&gt;</text><polygon fill="#A80036" points="396.5,281.0313,386.5,285.0313,396.5,289.0313,392.5,285.0313" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 2.0,2.0;" x1="390.5" x2="733" y1="285.0313" y2="285.0313"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="21" x="402.5" y="279.9653">[7]</text><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="116" x="427.5" y="279.9653">CRITICAL EVENT</text><path d="M306,298.0313 L306,323.0313 L451,323.0313 L451,308.0313 L441,298.0313 L306,298.0313 " fill="#FBFB77" filter="url(#f18zq03ani7xpz)" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M441,298.0313 L441,308.0313 L451,308.0313 L441,298.0313 " fill="#FBFB77" style="stroke: #A80036; stroke-width: 1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="124" x="312" y="315.0981">Critical event triage</text><polygon fill="#A80036" points="629,349.2969,639,353.2969,629,357.2969,633,353.2969" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="380.5" x2="635" y1="353.2969" y2="353.2969"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="21" x="387.5" y="348.231">[8]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="118" x="412.5" y="348.231">dispatch to handle</text><path d="M563,366.2969 L563,391.2969 L725,391.2969 L725,376.2969 L715,366.2969 L563,366.2969 " fill="#FBFB77" filter="url(#f18zq03ani7xpz)" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M715,366.2969 L715,376.2969 L725,376.2969 L715,366.2969 " fill="#FBFB77" style="stroke: #A80036; stroke-width: 1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="141" x="569" y="383.3638">Critical event handling</text><polygon fill="#A80036" points="453,417.5625,443,421.5625,453,425.5625,449,421.5625" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 2.0,2.0;" x1="447" x2="645" y1="421.5625" y2="421.5625"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="21" x="459" y="416.4966">[9]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="155" x="484" y="416.4966">sdei_dispatch_event(ev)</text><path d="M353,434.5625 L353,459.5625 L516,459.5625 L516,444.5625 L506,434.5625 L353,434.5625 " fill="#FBFB77" filter="url(#f18zq03ani7xpz)" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M506,434.5625 L506,444.5625 L516,444.5625 L506,434.5625 " fill="#FBFB77" style="stroke: #A80036; stroke-width: 1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="142" x="359" y="451.6294">Prepare SDEI dispatch</text><polygon fill="#A80036" points="82.5,485.8281,72.5,489.8281,82.5,493.8281,78.5,489.8281" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="76.5" x2="431" y1="489.8281" y2="489.8281"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="30" x="88.5" y="484.7622">[10]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="54" x="122.5" y="484.7622">dispatch</text><path d="M8,502.8281 L8,527.8281 L111,527.8281 L111,512.8281 L101,502.8281 L8,502.8281 " fill="#FBFB77" filter="url(#f18zq03ani7xpz)" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M101,502.8281 L101,512.8281 L111,512.8281 L101,502.8281 " fill="#FBFB77" style="stroke: #A80036; stroke-width: 1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="82" x="14" y="519.895">SDEI handler</text><polygon fill="#A80036" points="420,554.0938,430,558.0938,420,562.0938,424,558.0938" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="426" y1="558.0938" y2="558.0938"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="30" x="73.5" y="553.0278">[11]</text><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="184" x="107.5" y="553.0278">SDEI_EVENT_COMPLETE()</text><path d="M347,571.0938 L347,596.0938 L522,596.0938 L522,581.0938 L512,571.0938 L347,571.0938 " fill="#FBFB77" filter="url(#f18zq03ani7xpz)" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M512,571.0938 L512,581.0938 L522,581.0938 L512,571.0938 " fill="#FBFB77" style="stroke: #A80036; stroke-width: 1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="154" x="353" y="588.1606">Complete SDEI dispatch</text><polygon fill="#A80036" points="629,622.3594,639,626.3594,629,630.3594,633,626.3594" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 2.0,2.0;" x1="437" x2="635" y1="626.3594" y2="626.3594"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="30" x="444" y="621.2935">[12]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="39" x="478" y="621.2935">return</text><polygon fill="#A80036" points="391.5,651.4922,381.5,655.4922,391.5,659.4922,387.5,655.4922" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="385.5" x2="645" y1="655.4922" y2="655.4922"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="30" x="397.5" y="650.4263">[13]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="125" x="431.5" y="650.4263">error handling done</text><polygon fill="#A80036" points="77.5,680.625,67.5,684.625,77.5,688.625,73.5,684.625" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="71.5" x2="379.5" y1="684.625" y2="684.625"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="30" x="83.5" y="679.5591">[14]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="197" x="117.5" y="679.5591">resumes preempted execution</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="190" x="258.75" y="716.8354">&lt;&lt;Normal execution resumes&gt;&gt;</text></g></svg>
\ No newline at end of file
diff --git a/docs/resources/diagrams/plantuml/sdei_general.svg b/docs/resources/diagrams/plantuml/sdei_general.svg
deleted file mode 100644 (file)
index e172112..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentScriptType="application/ecmascript" contentStyleType="text/css" height="676px" preserveAspectRatio="none" style="width:608px;height:676px;" version="1.1" viewBox="0 0 608 676" width="608px" zoomAndPan="magnify"><defs><filter height="300%" id="fvds2ijrtbp5u" width="300%" x="-1" y="-1"><feGaussianBlur result="blurOut" stdDeviation="2.0"/><feColorMatrix in="blurOut" result="blurOut2" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .4 0"/><feOffset dx="4.0" dy="4.0" in="blurOut2" result="blurOut3"/><feBlend in="SourceGraphic" in2="blurOut3" mode="normal"/></filter></defs><g><rect fill="#FFFFFF" filter="url(#fvds2ijrtbp5u)" height="233.0625" style="stroke: #FFFFFF; stroke-width: 1.0;" width="10" x="56.5" y="48.2969"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="56.5" x2="56.5" y1="48.2969" y2="281.3594"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="66.5" y1="48.2969" y2="281.3594"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="56.5" x2="66.5" y1="48.2969" y2="48.2969"/><rect fill="#FFFFFF" filter="url(#fvds2ijrtbp5u)" height="263.0625" style="stroke: #FFFFFF; stroke-width: 1.0;" width="10" x="56.5" y="322.1641"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="56.5" x2="56.5" y1="322.1641" y2="585.2266"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="66.5" y1="322.1641" y2="585.2266"/><rect fill="#FFFFFF" filter="url(#fvds2ijrtbp5u)" height="1" style="stroke: #FFFFFF; stroke-width: 1.0;" width="10" x="56.5" y="626.0313"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="56.5" x2="56.5" y1="626.0313" y2="627.0313"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="66.5" y1="626.0313" y2="627.0313"/><rect fill="#FA8072" filter="url(#fvds2ijrtbp5u)" height="68.2656" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="61.5" y="411.4297"/><rect fill="#FF0000" filter="url(#fvds2ijrtbp5u)" height="233.9297" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="375.5" y="343.1641"/><rect fill="#FA8072" filter="url(#fvds2ijrtbp5u)" height="204.7969" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="513.5" y="343.1641"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="61" x2="61" y1="38.2969" y2="281.3594"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 1.0,4.0;" x1="61" x2="61" y1="281.3594" y2="322.1641"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="61" x2="61" y1="322.1641" y2="585.2266"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 1.0,4.0;" x1="61" x2="61" y1="585.2266" y2="626.0313"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="61" x2="61" y1="626.0313" y2="636.0313"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="380" x2="380" y1="38.2969" y2="281.3594"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 1.0,4.0;" x1="380" x2="380" y1="281.3594" y2="322.1641"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="380" x2="380" y1="322.1641" y2="585.2266"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 1.0,4.0;" x1="380" x2="380" y1="585.2266" y2="626.0313"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="380" x2="380" y1="626.0313" y2="636.0313"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="518" x2="518" y1="38.2969" y2="281.3594"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 1.0,4.0;" x1="518" x2="518" y1="281.3594" y2="322.1641"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="518" x2="518" y1="322.1641" y2="585.2266"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 1.0,4.0;" x1="518" x2="518" y1="585.2266" y2="626.0313"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="518" x2="518" y1="626.0313" y2="636.0313"/><rect fill="#FEFECE" filter="url(#fvds2ijrtbp5u)" height="30.2969" style="stroke: #A80036; stroke-width: 1.5;" width="87" x="16" y="3"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="73" x="23" y="22.9951">SDEI client</text><rect fill="#FEFECE" filter="url(#fvds2ijrtbp5u)" height="30.2969" style="stroke: #A80036; stroke-width: 1.5;" width="87" x="16" y="635.0313"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="73" x="23" y="655.0264">SDEI client</text><rect fill="#FEFECE" filter="url(#fvds2ijrtbp5u)" height="30.2969" style="stroke: #A80036; stroke-width: 1.5;" width="39" x="359" y="3"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="25" x="366" y="22.9951">EL3</text><rect fill="#FEFECE" filter="url(#fvds2ijrtbp5u)" height="30.2969" style="stroke: #A80036; stroke-width: 1.5;" width="39" x="359" y="635.0313"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="25" x="366" y="655.0264">EL3</text><rect fill="#FEFECE" filter="url(#fvds2ijrtbp5u)" height="30.2969" style="stroke: #A80036; stroke-width: 1.5;" width="161" x="436" y="3"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="147" x="443" y="22.9951">SDEI interrupt source</text><rect fill="#FEFECE" filter="url(#fvds2ijrtbp5u)" height="30.2969" style="stroke: #A80036; stroke-width: 1.5;" width="161" x="436" y="635.0313"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="147" x="443" y="655.0264">SDEI interrupt source</text><rect fill="#FFFFFF" filter="url(#fvds2ijrtbp5u)" height="233.0625" style="stroke: #FFFFFF; stroke-width: 1.0;" width="10" x="56.5" y="48.2969"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="56.5" x2="56.5" y1="48.2969" y2="281.3594"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="66.5" y1="48.2969" y2="281.3594"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="56.5" x2="66.5" y1="48.2969" y2="48.2969"/><rect fill="#FFFFFF" filter="url(#fvds2ijrtbp5u)" height="263.0625" style="stroke: #FFFFFF; stroke-width: 1.0;" width="10" x="56.5" y="322.1641"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="56.5" x2="56.5" y1="322.1641" y2="585.2266"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="66.5" y1="322.1641" y2="585.2266"/><rect fill="#FFFFFF" filter="url(#fvds2ijrtbp5u)" height="1" style="stroke: #FFFFFF; stroke-width: 1.0;" width="10" x="56.5" y="626.0313"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="56.5" x2="56.5" y1="626.0313" y2="627.0313"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="66.5" y1="626.0313" y2="627.0313"/><rect fill="#FA8072" filter="url(#fvds2ijrtbp5u)" height="68.2656" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="61.5" y="411.4297"/><rect fill="#FF0000" filter="url(#fvds2ijrtbp5u)" height="233.9297" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="375.5" y="343.1641"/><rect fill="#FA8072" filter="url(#fvds2ijrtbp5u)" height="204.7969" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="513.5" y="343.1641"/><polygon fill="#A80036" points="368.5,65.2969,378.5,69.2969,368.5,73.2969,372.5,69.2969" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="374.5" y1="69.2969" y2="69.2969"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="21" x="73.5" y="64.3638">[1]</text><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="163" x="98.5" y="64.3638">SDEI_INTERRUPT_BIND</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="26" x="261.5" y="64.3638">(irq)</text><polygon fill="#A80036" points="77.5,94.4297,67.5,98.4297,77.5,102.4297,73.5,98.4297" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="71.5" x2="379.5" y1="98.4297" y2="98.4297"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="21" x="83.5" y="93.4966">[2]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="113" x="108.5" y="93.4966">event number: ev</text><polygon fill="#A80036" points="368.5,123.5625,378.5,127.5625,368.5,131.5625,372.5,127.5625" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="374.5" y1="127.5625" y2="127.5625"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="21" x="73.5" y="122.6294">[3]</text><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="164" x="98.5" y="122.6294">SDEI_EVENT_REGISTER</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="101" x="262.5" y="122.6294">(ev, handler, ...)</text><polygon fill="#A80036" points="77.5,152.6953,67.5,156.6953,77.5,160.6953,73.5,156.6953" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="71.5" x2="379.5" y1="156.6953" y2="156.6953"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="21" x="83.5" y="151.7622">[4]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="51" x="108.5" y="151.7622">success</text><polygon fill="#A80036" points="368.5,181.8281,378.5,185.8281,368.5,189.8281,372.5,185.8281" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="374.5" y1="185.8281" y2="185.8281"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="21" x="73.5" y="180.895">[5]</text><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="151" x="98.5" y="180.895">SDEI_EVENT_ENABLE</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="25" x="249.5" y="180.895">(ev)</text><polygon fill="#A80036" points="77.5,210.9609,67.5,214.9609,77.5,218.9609,73.5,214.9609" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="71.5" x2="379.5" y1="214.9609" y2="214.9609"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="21" x="83.5" y="210.0278">[6]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="51" x="108.5" y="210.0278">success</text><polygon fill="#A80036" points="368.5,240.0938,378.5,244.0938,368.5,248.0938,372.5,244.0938" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="374.5" y1="244.0938" y2="244.0938"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="21" x="73.5" y="239.1606">[7]</text><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="129" x="98.5" y="239.1606">SDEI_PE_UNMASK</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="10" x="227.5" y="239.1606">()</text><polygon fill="#A80036" points="77.5,269.2266,67.5,273.2266,77.5,277.2266,73.5,273.2266" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="71.5" x2="379.5" y1="273.2266" y2="273.2266"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="21" x="83.5" y="268.2935">[8]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="8" x="108.5" y="268.2935">1</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="142" x="219" y="305.5698">&lt;&lt;Business as usual&gt;&gt;</text><polygon fill="#A80036" points="396.5,339.1641,386.5,343.1641,396.5,347.1641,392.5,343.1641" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 2.0,2.0;" x1="390.5" x2="512.5" y1="343.1641" y2="343.1641"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="21" x="402.5" y="338.231">[9]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="89" x="427.5" y="338.231">SDEI interrupt</text><polygon fill="#FBFB77" filter="url(#fvds2ijrtbp5u)" points="297,356.2969,297,381.2969,460,381.2969,460,366.2969,450,356.2969,297,356.2969" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="450" x2="450" y1="356.2969" y2="366.2969"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="460" x2="450" y1="366.2969" y2="366.2969"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="142" x="303" y="373.3638">Prepare SDEI dispatch</text><polygon fill="#A80036" points="82.5,407.4297,72.5,411.4297,82.5,415.4297,78.5,411.4297" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="76.5" x2="374.5" y1="411.4297" y2="411.4297"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="30" x="88.5" y="406.4966">[10]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="54" x="122.5" y="406.4966">dispatch</text><polygon fill="#FBFB77" filter="url(#fvds2ijrtbp5u)" points="8,424.5625,8,449.5625,111,449.5625,111,434.5625,101,424.5625,8,424.5625" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="101" x2="101" y1="424.5625" y2="434.5625"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="111" x2="101" y1="434.5625" y2="434.5625"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="82" x="14" y="441.6294">SDEI handler</text><polygon fill="#A80036" points="363.5,475.6953,373.5,479.6953,363.5,483.6953,367.5,479.6953" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="66.5" x2="369.5" y1="479.6953" y2="479.6953"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="30" x="73.5" y="474.7622">[11]</text><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="184" x="107.5" y="474.7622">SDEI_EVENT_COMPLETE()</text><polygon fill="#FBFB77" filter="url(#fvds2ijrtbp5u)" points="291,492.8281,291,517.8281,466,517.8281,466,502.8281,456,492.8281,291,492.8281" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="456" x2="456" y1="492.8281" y2="502.8281"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="466" x2="456" y1="502.8281" y2="502.8281"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="154" x="297" y="509.895">Complete SDEI dispatch</text><polygon fill="#A80036" points="506.5,543.9609,516.5,547.9609,506.5,551.9609,510.5,547.9609" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 2.0,2.0;" x1="385.5" x2="512.5" y1="547.9609" y2="547.9609"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="30" x="392.5" y="543.0278">[12]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="21" x="426.5" y="543.0278">EOI</text><polygon fill="#A80036" points="77.5,573.0938,67.5,577.0938,77.5,581.0938,73.5,577.0938" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="71.5" x2="379.5" y1="577.0938" y2="577.0938"/><text fill="#000000" font-family="sans-serif" font-size="13" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="30" x="83.5" y="572.1606">[13]</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="197" x="117.5" y="572.1606">resumes preempted execution</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="190" x="195" y="609.437">&lt;&lt;Normal execution resumes&gt;&gt;</text></g></svg>
\ No newline at end of file
index da4cecd33f73c226bb3c11b1c92a3ee8a90a2baa..45ad139275f3129d425fd9f3d747e6e1f7651199 100644 (file)
 /*
- * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
 #include <asm_macros.S>
+#include <console_macros.S>
 
        /*
-        * This file contains a skeleton console implementation that can
-        * be used as basis for a real console implementation by platforms
-        * that do not contain PL011 hardware.
+        * This file contains a skeleton console driver that can be used as a
+        * basis for a real console driver. Console drivers in Trusted Firmware
+        * can be instantiated multiple times. Each instance is described by a
+        * separate console_t structure which must be registered with the common
+        * console framework via console_register(). Console drivers should
+        * define a console_xxx_register() function that initializes a new
+        * console_t structure passed in from the caller and registers it after
+        * initializing the console hardware. Drivers may define their own
+        * structures extending console_t to store private driver information.
+        * Console drivers *MUST* ensure that the console callbacks they
+        * implement only change registers allowed in the clobber lists defined
+        * in this file. (Note that in addition to the explicit clobber lists,
+        * any function may always clobber the intra-procedure-call register
+        * r12, but may never depend on it retaining its value across any
+        * function call.)
         */
 
-       .globl  console_core_init
-       .globl  console_core_putc
-       .globl  console_core_getc
-       .globl  console_core_flush
+       .globl  console_xxx_register
+       .globl  console_xxx_putc
+       .globl  console_xxx_getc
+       .globl  console_xxx_flush
 
        /* -----------------------------------------------
-        * int console_core_init(uintptr_t base_addr,
-        * unsigned int uart_clk, unsigned int baud_rate)
-        * Function to initialize the console without a
-        * C Runtime to print debug information. This
-        * function will be accessed by console_init and
-        * crash reporting.
-        * In: r0 - console base address
-        *     r1 - Uart clock in Hz
-        *     r2 - Baud rate
-        * Out: return 1 on success else 0 on error
-        * Clobber list : r1, r2
+        * int console_xxx_register(console_xxx_t *console,
+        *      ...additional parameters as desired...)
+        * Function to initialize and register the console.
+        * The caller needs to pass an empty console_xxx_t
+        * structure in which *MUST* be allocated in
+        * persistent memory (e.g. a global or static local
+        * variable, *NOT* on the stack).
+        * In : r0 - pointer to empty console_t structure
+        *      r1 through r7: additional parameters as desired
+        * Out: r0 - 1 on success, 0 on error
+        * Clobber list : r0 - r7
         * -----------------------------------------------
         */
-func console_core_init
-       /* Check the input base address */
-       cmp     r0, #0
-       beq     core_init_fail
-       /* Check baud rate and uart clock for sanity */
-       cmp     r1, #0
-       beq     core_init_fail
-       cmp     r2, #0
-       beq     core_init_fail
-       /* Insert implementation here */
-       mov     r0, #1
-       bx      lr
-core_init_fail:
+func console_xxx_register
+       /*
+        * Store parameters (e.g. hardware base address) in driver-specific
+        * console_xxx_t structure field if they will need to be retrieved
+        * by later console callback (e.g. putc).
+        * Example:
+        */
+       str     r1, [r0, #CONSOLE_T_XXX_BASE]
+       str     r2, [r0, #CONSOLE_T_XXX_SOME_OTHER_VALUE]
+
+       /*
+        * Initialize console hardware, using r1 - r7 parameters as needed.
+        * Keep console_t pointer in r0 for later.
+        */
+
+       /*
+        * Macro to finish up registration and return (needs valid r0 + lr).
+        * If any of the argument is unspecified, then the corresponding
+        * entry in console_t is set to 0.
+        */
+       finish_console_register xxx putc=1, getc=1, flush=1
+
+       /* Jump here if hardware init fails or parameters are invalid. */
+register_fail:
        mov     r0, #0
        bx      lr
-endfunc console_core_init
+endfunc console_xxx_register
 
        /* --------------------------------------------------------
-        * int console_core_putc(int c, uintptr_t base_addr)
+        * int console_xxx_putc(int c, console_xxx_t *console)
         * Function to output a character over the console. It
         * returns the character printed on success or -1 on error.
         * In : r0 - character to be printed
-        *      r1 - console base address
-        * Out : return -1 on error else return character.
-        * Clobber list : r2
+        *      r1 - pointer to console_t struct
+        * Out: r0 - printed character on success, < 0 on error.
+        * Clobber list : r0, r1, r2
         * --------------------------------------------------------
         */
-func console_core_putc
-       /* Check the input parameter */
-       cmp     r1, #0
-       beq     putc_error
-       /* Insert implementation here */
+func console_xxx_putc
+       /*
+        * Retrieve values we need (e.g. hardware base address) from
+        * console_xxx_t structure pointed to by r1.
+        * Example:
+        */
+       ldr     r1, [r1, #CONSOLE_T_XXX_BASE]
+
+       /*
+        * Write r0 to hardware.
+        */
+
        bx      lr
+
+       /* Jump here if output fails for any reason. */
 putc_error:
        mov     r0, #-1
        bx      lr
-endfunc console_core_putc
+endfunc console_xxx_putc
 
        /* ---------------------------------------------
-        * int console_core_getc(uintptr_t base_addr)
+        * int console_xxx_getc(console_xxx_t *console)
         * Function to get a character from the console.
-        * It returns the character grabbed on success
-        * or -1 on error.
-        * In : r0 - console base address
+        * Even though console_getc() is blocking, this
+        * callback has to be non-blocking and always
+        * return immediately to allow polling multiple
+        * drivers concurrently.
+        * Returns the character grabbed on success,
+        * ERROR_NO_PENDING_CHAR if no character was
+        * available at this time, or any value
+        * between -2 and -127 if there was an error.
+        * In : r0 - pointer to console_t struct
+        * Out: r0 - character on success,
+        *           ERROR_NO_PENDING_CHAR if no char,
+        *           < -1 on error
         * Clobber list : r0, r1
         * ---------------------------------------------
         */
-func console_core_getc
-       cmp     r0, #0
-       beq     getc_error
-       /* Insert implementation here */
+func console_xxx_getc
+       /*
+        * Retrieve values we need (e.g. hardware base address) from
+        * console_xxx_t structure pointed to by r0.
+        * Example:
+        */
+       ldr     r1, [r0, #CONSOLE_T_XXX_BASE]
+
+       /*
+        * Try to read character into r0 from hardware.
+        */
+
        bx      lr
+
+       /* Jump here if there is no character available at this time. */
+getc_no_char:
+       mov     r0, #ERROR_NO_PENDING_CHAR
+       bx      lr
+
+       /* Jump here if there was any hardware error. */
 getc_error:
-       mov     r0, #-1
+       mov     r0, #-2         /* may pick error codes between -2 and -127 */
        bx      lr
-endfunc console_core_getc
+endfunc console_xxx_getc
 
        /* ---------------------------------------------
-        * int console_core_flush(uintptr_t base_addr)
+        * int console_xxx_flush(console_xxx_t *console)
         * Function to force a write of all buffered
         * data that hasn't been output.
-        * In : r0 - console base address
-        * Out : return -1 on error else return 0.
-        * Clobber list : r0, r1
+        * In : r0 - pointer to console_xxx_t struct
+        * Out: r0 - 0 on success, < 0 on error
+        * Clobber list : r0, r1, r2, r3, r4, r5
         * ---------------------------------------------
         */
-func console_core_flush
-       cmp     r0, #0
-       beq     flush_error
-       /* Insert implementation here */
+func console_xxx_flush
+       /*
+        * Retrieve values we need (e.g. hardware base address) from
+        * console_xxx_t structure pointed to by r0.
+        * Example:
+        */
+       ldr     r1, [r0, #CONSOLE_T_XXX_BASE]
+
+       /*
+        * Flush all remaining output from hardware FIFOs. Do not return until
+        * all data has been flushed or there was an unrecoverable error.
+        */
+
        mov     r0, #0
        bx      lr
+
+       /* Jump here if an unrecoverable error has been encountered. */
 flush_error:
        mov     r0, #-1
        bx      lr
-endfunc console_core_flush
+endfunc console_xxx_flush
index c695ddec46ca57b89c7729f2c603b8e794ac935c..957ed83a96ed5728609b7a5efd0cfe312a4ba54f 100644 (file)
@@ -7,7 +7,7 @@
 #include <console_macros.S>
 
        /*
-        * This file contains a skeleton console driver that can be used as
+        * This file contains a skeleton console driver that can be used as a
         * basis for a real console driver. Console drivers in Trusted Firmware
         * can be instantiated multiple times. Each instance is described by a
         * separate console_t structure which must be registered with the common
@@ -16,7 +16,7 @@
         * console_t structure passed in from the caller and registers it after
         * initializing the console hardware. Drivers may define their own
         * structures extending console_t to store private driver information.
-        * Console drivers *MUST* take care that the console callbacks they
+        * Console drivers *MUST* ensure that the console callbacks they
         * implement only change registers allowed in the clobber lists defined
         * in this file. (Note that in addition to the explicit clobber lists,
         * any function may always clobber the intra-procedure-call registers
index 3a9859c98c79af9a2fe373cc6de41644ccea0d74..06fe88e13adc2ac2a70b4bf71662578958695124 100644 (file)
                                MCI_PHY_CTRL_PHY_ADDR_MSB_OFFSET)
 #define MCI_PHY_CTRL_PIDI_MODE_OFFSET                  31
 #define MCI_PHY_CTRL_PIDI_MODE                         \
-                               (1 << MCI_PHY_CTRL_PIDI_MODE_OFFSET)
+                               (1U << MCI_PHY_CTRL_PIDI_MODE_OFFSET)
 
 /* Number of times to wait for the MCI link ready after MCI configurations
  * Normally takes 34-35 successive reads
index d7d7373180bcf87bb26615dd41e38b61e41afa01..b4b4e0c82d66298e99e36d5b0e0fe4feeb789085 100644 (file)
                                (0x1 << MVEBU_AMB_IP_BRIDGE_WIN_EN_OFFSET)
 #define MVEBU_AMB_IP_BRIDGE_WIN_SIZE_OFFSET    16
 #define MVEBU_AMB_IP_BRIDGE_WIN_SIZE_MASK      \
-                               (0xffff << MVEBU_AMB_IP_BRIDGE_WIN_SIZE_OFFSET)
+                               (0xffffu << MVEBU_AMB_IP_BRIDGE_WIN_SIZE_OFFSET)
 
 #define MVEBU_SAMPLE_AT_RESET_REG      (0x440600)
 #define SAR_PCIE1_CLK_CFG_OFFSET       31
-#define SAR_PCIE1_CLK_CFG_MASK         (0x1 << SAR_PCIE1_CLK_CFG_OFFSET)
+#define SAR_PCIE1_CLK_CFG_MASK         (0x1u << SAR_PCIE1_CLK_CFG_OFFSET)
 #define SAR_PCIE0_CLK_CFG_OFFSET       30
 #define SAR_PCIE0_CLK_CFG_MASK         (0x1 << SAR_PCIE0_CLK_CFG_OFFSET)
 #define SAR_I2C_INIT_EN_OFFSET         24
index 565099c4a76b35826ca60da088ec9bac1e9366c1..a969dea74c50bff8a13f3fad600f3f1c85a8f8f1 100644 (file)
@@ -104,8 +104,8 @@ struct asd_desc {
 #define ASD_DESC_ERR_SET(d, v)                                 \
        (ASD_DESC_SET((d)->cfg, v, ASD_DESC_ERR_MASK, ASD_DESC_ERR_OFF))
 
-#define ASD_DESC_OWNER_OFF 31
-#define ASD_DESC_OWNER_MASK 0x1
+#define ASD_DESC_OWNER_OFF 31u
+#define ASD_DESC_OWNER_MASK 0x1u
 #define ASD_DESC_OWNER(d)                                      \
        (ASD_DESC_GET((d)->cfg, ASD_DESC_OWNER_MASK, ASD_DESC_OWNER_OFF))
 #define ASD_DESC_OWNER_SET(d, v)                               \
@@ -126,7 +126,7 @@ static void asd_compute_sha(struct asd_ctx *ctx, void *data, size_t len,
        assert((uintptr_t)&desc == (uintptr_t)&desc);
 
        ASD_DESC_LEN_SET(&desc, len);
-       ASD_DESC_OWNER_SET(&desc, 1);
+       ASD_DESC_OWNER_SET(&desc, 1u);
        ASD_DESC_ENCONLY_SET(&desc, 1);
        ASD_DESC_EOD_SET(&desc, 1);
        if (ctx->started == 0) {
index f7d8ec08a0c559f72e1ccd4e8d3864c0a9aa2a75..ece3462f450eaa0ddc09534ecd4c347bf7a6b767 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2017, Renesas Electronics Corporation. All rights
+ * Copyright (c) 2015-2019, Renesas Electronics Corporation. All rights
  * reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
@@ -25,7 +25,7 @@ extern int32_t rcar_get_certificate(const int32_t name, uint32_t *cert_addr);
 #define RCAR_BOOT_KEY_CERT_NEW (0xE6300F00U)
 #define        RST_BASE                (0xE6160000U)
 #define        RST_MODEMR              (RST_BASE + 0x0060U)
-#define        MFISSOFTMDR             (0xE6260600U)
+#define        MFISOFTMDR              (0xE6260600U)
 #define        MODEMR_MD5_MASK         (0x00000020U)
 #define        MODEMR_MD5_SHIFT        (5U)
 #define        SOFTMD_BOOTMODE_MASK    (0x00000001U)
@@ -139,7 +139,7 @@ static int32_t normal_boot_verify(uint32_t a, uint32_t b, void *c)
 void auth_mod_init(void)
 {
 #if RCAR_SECURE_BOOT
-       uint32_t soft_md = mmio_read_32(MFISSOFTMDR) & SOFTMD_BOOTMODE_MASK;
+       uint32_t soft_md = mmio_read_32(MFISOFTMDR) & SOFTMD_BOOTMODE_MASK;
        uint32_t md = mmio_read_32(RST_MODEMR) & MODEMR_MD5_MASK;
        uint32_t lcs, ret;
 
index 4830853739bffc234deb20d441d886a5d38bb907..5ffb2e1971cf8f801d5bbe1cb6be4df9a3260173 100644 (file)
@@ -68,7 +68,7 @@ static void cpld_write(uint8_t addr, uint32_t data)
 
        for (i = 0; i < 32; i++) {
                /* MSB first */
-               gpio_set_value(GPIO_OUTDT6, MOSI, data & (1 << 31));
+               gpio_set_value(GPIO_OUTDT6, MOSI, data & (1U << 31));
                gpio_set_value(GPIO_OUTDT6, SCLK, 1);
                data <<= 1;
                gpio_set_value(GPIO_OUTDT6, SCLK, 0);
index 7e9bde9d47aed14671e9ec2c95aa4565becd5290..aaa3b434a31e6461dcf3b55eedf034bb00c3883a 100644 (file)
@@ -610,7 +610,7 @@ void pfc_init_d3(void)
 
        /* initialize POC control register */
        pfc_reg_write(PFC_POCCTRL0,   0xC00FFFFFU);
-       pfc_reg_write(PFC_POCCTRL1,   0XFFFFFFFEU);
+       pfc_reg_write(PFC_POCCTRL2,   0XFFFFFFFEU);
        pfc_reg_write(PFC_TDSELCTRL0, 0x00000000U);
 
        /* initialize LSI pin pull-up/down control */
index 2946cbaaccdebee9b4ce263408fbff2a2005d07e..bd0048ebbfdc3b23928183cf565928f3259fef8e 100644 (file)
 #define GPSR5_SCK2_A           BIT(7)
 #define GPSR5_TX1              BIT(6)
 #define GPSR5_RX1              BIT(5)
-#define GPSR5_RTS0_TANS_A      BIT(4)
+#define GPSR5_RTS0_A           BIT(4)
 #define GPSR5_CTS0_A           BIT(3)
 #define GPSR5_TX0_A            BIT(2)
 #define GPSR5_RX0_A            BIT(1)
 #define IPSR_4_FUNC(x)         ((uint32_t)(x) << 4U)
 #define IPSR_0_FUNC(x)         ((uint32_t)(x) << 0U)
 
-#define IOCTRL30_MASK          (0x0007F000U)
+#define POCCTRL0_MASK          (0x0007F000U)
 #define POC_SD3_DS_33V         BIT(29)
 #define POC_SD3_DAT7_33V       BIT(28)
 #define POC_SD3_DAT6_33V       BIT(27)
 #define POC_SD0_CMD_33V                BIT(1)
 #define POC_SD0_CLK_33V                BIT(0)
 
-#define IOCTRL32_MASK          (0xFFFFFFFEU)
+#define POCCTRL2_MASK          (0xFFFFFFFEU)
 #define POC2_VREF_33V          BIT(0)
 
 #define MOD_SEL0_ADGB_A                ((uint32_t)0U << 29U)
@@ -561,7 +561,7 @@ void pfc_init_e3(void)
                      | GPSR5_RX2_A
                      | GPSR5_TX2_A
                      | GPSR5_SCK2_A
-                     | GPSR5_RTS0_TANS_A
+                     | GPSR5_RTS0_A
                      | GPSR5_CTS0_A);
        pfc_reg_write(PFC_GPSR6, GPSR6_USB30_PWEN
                      | GPSR6_SSI_SDATA6
@@ -581,7 +581,7 @@ void pfc_init_e3(void)
 
        /* initialize POC control */
        reg = mmio_read_32(PFC_POCCTRL0);
-       reg = ((reg & IOCTRL30_MASK) | POC_SD1_DAT3_33V
+       reg = ((reg & POCCTRL0_MASK) | POC_SD1_DAT3_33V
               | POC_SD1_DAT2_33V
               | POC_SD1_DAT1_33V
               | POC_SD1_DAT0_33V
@@ -594,9 +594,9 @@ void pfc_init_e3(void)
               | POC_SD0_CMD_33V
               | POC_SD0_CLK_33V);
        pfc_reg_write(PFC_POCCTRL0, reg);
-       reg = mmio_read_32(PFC_POCCTRL1);
-       reg = (reg & IOCTRL32_MASK);
-       pfc_reg_write(PFC_POCCTRL1, reg);
+       reg = mmio_read_32(PFC_POCCTRL2);
+       reg = (reg & POCCTRL2_MASK);
+       pfc_reg_write(PFC_POCCTRL2, reg);
 
        /* initialize LSI pin pull-up/down control */
        pfc_reg_write(PFC_PUD0, 0xFDF80000U);
index 7287c833915a1c0d2f4ec78544b3ca5d09eb1c64..effdc767ec55e2372d383e9f6cf6098245c4a6fe 100644 (file)
 #define GPSR5_RX2_A            BIT(11)
 #define GPSR5_TX2_A            BIT(10)
 #define GPSR5_SCK2             BIT(9)
-#define GPSR5_RTS1_TANS                BIT(8)
+#define GPSR5_RTS1             BIT(8)
 #define GPSR5_CTS1             BIT(7)
 #define GPSR5_TX1_A            BIT(6)
 #define GPSR5_RX1_A            BIT(5)
-#define GPSR5_RTS0_TANS                BIT(4)
+#define GPSR5_RTS0             BIT(4)
 #define GPSR5_CTS0             BIT(3)
 #define GPSR5_TX0              BIT(2)
 #define GPSR5_RX0              BIT(1)
 #define GPSR6_SSI_SDATA0       BIT(2)
 #define GPSR6_SSI_WS0129       BIT(1)
 #define GPSR6_SSI_SCK0129      BIT(0)
-#define GPSR7_HDMI1_CEC                BIT(3)
-#define GPSR7_HDMI0_CEC                BIT(2)
 #define GPSR7_AVS2             BIT(1)
 #define GPSR7_AVS1             BIT(0)
 
 #define DRVCTRL11_D15(x)       ((uint32_t)(x) << 24U)
 #define DRVCTRL11_AVS1(x)      ((uint32_t)(x) << 20U)
 #define DRVCTRL11_AVS2(x)      ((uint32_t)(x) << 16U)
-#define DRVCTRL11_HDMI0_CEC(x) ((uint32_t)(x) << 12U)
-#define DRVCTRL11_HDMI1_CEC(x) ((uint32_t)(x) << 8U)
+#define DRVCTRL11_GP7_02(x)    ((uint32_t)(x) << 12U)
+#define DRVCTRL11_GP7_03(x)    ((uint32_t)(x) << 8U)
 #define DRVCTRL11_DU_DOTCLKIN0(x)      ((uint32_t)(x) << 4U)
 #define DRVCTRL11_DU_DOTCLKIN1(x)      ((uint32_t)(x) << 0U)
 #define DRVCTRL12_DU_DOTCLKIN2(x)      ((uint32_t)(x) << 28U)
@@ -673,7 +671,6 @@ void pfc_init_h3_v1(void)
                      | IPSR_24_FUNC(0)
                      | IPSR_20_FUNC(0)
                      | IPSR_16_FUNC(0)
-                     | IPSR_12_FUNC(0)
                      | IPSR_8_FUNC(6)
                      | IPSR_4_FUNC(6)
                      | IPSR_0_FUNC(6));
@@ -829,11 +826,11 @@ void pfc_init_h3_v1(void)
                      | GPSR5_RX2_A
                      | GPSR5_TX2_A
                      | GPSR5_SCK2
-                     | GPSR5_RTS1_TANS
+                     | GPSR5_RTS1
                      | GPSR5_CTS1
                      | GPSR5_TX1_A
                      | GPSR5_RX1_A
-                     | GPSR5_RTS0_TANS
+                     | GPSR5_RTS0
                      | GPSR5_SCK0);
        pfc_reg_write(PFC_GPSR6, GPSR6_USB30_OVC
                      | GPSR6_USB30_PWEN
@@ -856,9 +853,7 @@ void pfc_init_h3_v1(void)
                      | GPSR6_SSI_SDATA0
                      | GPSR6_SSI_WS0129
                      | GPSR6_SSI_SCK0129);
-       pfc_reg_write(PFC_GPSR7, GPSR7_HDMI1_CEC
-                     | GPSR7_HDMI0_CEC
-                     | GPSR7_AVS2
+       pfc_reg_write(PFC_GPSR7, GPSR7_AVS2
                      | GPSR7_AVS1);
 
        /* initialize POC control register */
@@ -996,8 +991,8 @@ void pfc_init_h3_v1(void)
               | DRVCTRL11_D15(3)
               | DRVCTRL11_AVS1(7)
               | DRVCTRL11_AVS2(7)
-              | DRVCTRL11_HDMI0_CEC(7)
-              | DRVCTRL11_HDMI1_CEC(7)
+              | DRVCTRL11_GP7_02(7)
+              | DRVCTRL11_GP7_03(7)
               | DRVCTRL11_DU_DOTCLKIN0(3)
               | DRVCTRL11_DU_DOTCLKIN1(3));
        pfc_reg_write(PFC_DRVCTRL11, reg);
@@ -1153,6 +1148,7 @@ void pfc_init_h3_v1(void)
        mmio_write_32(GPIO_POSNEG4, 0x00000000U);
        mmio_write_32(GPIO_POSNEG5, 0x00000000U);
        mmio_write_32(GPIO_POSNEG6, 0x00000000U);
+       mmio_write_32(GPIO_POSNEG7, 0x00000000U);
 
        /* initialize general IO/interrupt switching */
        mmio_write_32(GPIO_IOINTSEL0, 0x00000000U);
@@ -1162,6 +1158,7 @@ void pfc_init_h3_v1(void)
        mmio_write_32(GPIO_IOINTSEL4, 0x00000000U);
        mmio_write_32(GPIO_IOINTSEL5, 0x00000000U);
        mmio_write_32(GPIO_IOINTSEL6, 0x00000000U);
+       mmio_write_32(GPIO_IOINTSEL7, 0x00000000U);
 
        /* initialize general output register */
        mmio_write_32(GPIO_OUTDT1, 0x00000000U);
@@ -1182,4 +1179,5 @@ void pfc_init_h3_v1(void)
        mmio_write_32(GPIO_INOUTSEL5, 0x0000020EU);
 #endif
        mmio_write_32(GPIO_INOUTSEL6, 0x00013880U);
+       mmio_write_32(GPIO_INOUTSEL7, 0x00000000U);
 }
index 8bba3c150687079b1812ab5785be13350e085847..a54b14b37f713964b1e455d05996751405008320 100644 (file)
 #define GPSR5_RX2_A            BIT(11)
 #define GPSR5_TX2_A            BIT(10)
 #define GPSR5_SCK2             BIT(9)
-#define GPSR5_RTS1_TANS                BIT(8)
+#define GPSR5_RTS1             BIT(8)
 #define GPSR5_CTS1             BIT(7)
 #define GPSR5_TX1_A            BIT(6)
 #define GPSR5_RX1_A            BIT(5)
-#define GPSR5_RTS0_TANS                BIT(4)
+#define GPSR5_RTS0             BIT(4)
 #define GPSR5_CTS0             BIT(3)
 #define GPSR5_TX0              BIT(2)
 #define GPSR5_RX0              BIT(1)
 #define GPSR6_SSI_SDATA0       BIT(2)
 #define GPSR6_SSI_WS0129       BIT(1)
 #define GPSR6_SSI_SCK0129      BIT(0)
-#define GPSR7_HDMI1_CEC                BIT(3)
-#define GPSR7_HDMI0_CEC                BIT(2)
 #define GPSR7_AVS2             BIT(1)
 #define GPSR7_AVS1             BIT(0)
 
 #define DRVCTRL11_D15(x)       ((uint32_t)(x) << 24U)
 #define DRVCTRL11_AVS1(x)      ((uint32_t)(x) << 20U)
 #define DRVCTRL11_AVS2(x)      ((uint32_t)(x) << 16U)
-#define DRVCTRL11_HDMI0_CEC(x) ((uint32_t)(x) << 12U)
-#define DRVCTRL11_HDMI1_CEC(x) ((uint32_t)(x) << 8U)
+#define DRVCTRL11_GP7_02(x)    ((uint32_t)(x) << 12U)
+#define DRVCTRL11_GP7_03(x)    ((uint32_t)(x) << 8U)
 #define DRVCTRL11_DU_DOTCLKIN0(x)      ((uint32_t)(x) << 4U)
 #define DRVCTRL11_DU_DOTCLKIN1(x)      ((uint32_t)(x) << 0U)
 #define DRVCTRL12_DU_DOTCLKIN2(x)      ((uint32_t)(x) << 28U)
@@ -697,7 +695,6 @@ void pfc_init_h3_v2(void)
                      | IPSR_24_FUNC(0)
                      | IPSR_20_FUNC(0)
                      | IPSR_16_FUNC(0)
-                     | IPSR_12_FUNC(0)
                      | IPSR_8_FUNC(6)
                      | IPSR_4_FUNC(6)
                      | IPSR_0_FUNC(6));
@@ -862,11 +859,11 @@ void pfc_init_h3_v2(void)
                      | GPSR5_RX2_A
                      | GPSR5_TX2_A
                      | GPSR5_SCK2
-                     | GPSR5_RTS1_TANS
+                     | GPSR5_RTS1
                      | GPSR5_CTS1
                      | GPSR5_TX1_A
                      | GPSR5_RX1_A
-                     | GPSR5_RTS0_TANS
+                     | GPSR5_RTS0
                      | GPSR5_SCK0);
        pfc_reg_write(PFC_GPSR6, GPSR6_USB30_OVC
                      | GPSR6_USB30_PWEN
@@ -889,9 +886,7 @@ void pfc_init_h3_v2(void)
                      | GPSR6_SSI_SDATA0
                      | GPSR6_SSI_WS0129
                      | GPSR6_SSI_SCK0129);
-       pfc_reg_write(PFC_GPSR7, GPSR7_HDMI1_CEC
-                     | GPSR7_HDMI0_CEC
-                     | GPSR7_AVS2
+       pfc_reg_write(PFC_GPSR7, GPSR7_AVS2
                      | GPSR7_AVS1);
 
        /* initialize POC control register */
@@ -1029,8 +1024,8 @@ void pfc_init_h3_v2(void)
               | DRVCTRL11_D15(3)
               | DRVCTRL11_AVS1(7)
               | DRVCTRL11_AVS2(7)
-              | DRVCTRL11_HDMI0_CEC(7)
-              | DRVCTRL11_HDMI1_CEC(7)
+              | DRVCTRL11_GP7_02(7)
+              | DRVCTRL11_GP7_03(7)
               | DRVCTRL11_DU_DOTCLKIN0(3)
               | DRVCTRL11_DU_DOTCLKIN1(3));
        pfc_reg_write(PFC_DRVCTRL11, reg);
@@ -1186,6 +1181,7 @@ void pfc_init_h3_v2(void)
        mmio_write_32(GPIO_POSNEG4, 0x00000000U);
        mmio_write_32(GPIO_POSNEG5, 0x00000000U);
        mmio_write_32(GPIO_POSNEG6, 0x00000000U);
+       mmio_write_32(GPIO_POSNEG7, 0x00000000U);
 
        /* initialize general IO/interrupt switching */
        mmio_write_32(GPIO_IOINTSEL0, 0x00000000U);
@@ -1195,6 +1191,7 @@ void pfc_init_h3_v2(void)
        mmio_write_32(GPIO_IOINTSEL4, 0x00000000U);
        mmio_write_32(GPIO_IOINTSEL5, 0x00000000U);
        mmio_write_32(GPIO_IOINTSEL6, 0x00000000U);
+       mmio_write_32(GPIO_IOINTSEL7, 0x00000000U);
 
        /* initialize general output register */
        mmio_write_32(GPIO_OUTDT1, 0x00000000U);
@@ -1215,4 +1212,5 @@ void pfc_init_h3_v2(void)
        mmio_write_32(GPIO_INOUTSEL5, 0x0000020EU);
 #endif
        mmio_write_32(GPIO_INOUTSEL6, 0x00013880U);
+       mmio_write_32(GPIO_INOUTSEL7, 0x00000000U);
 }
index 380899d3aea53b905d9aeca04119f71a47a92a80..0aa3bffce0ad1d12f5716523c3bc43cbbdb84efc 100644 (file)
 #define GPSR5_RX2_A            BIT(11)
 #define GPSR5_TX2_A            BIT(10)
 #define GPSR5_SCK2             BIT(9)
-#define GPSR5_RTS1_TANS                BIT(8)
+#define GPSR5_RTS1             BIT(8)
 #define GPSR5_CTS1             BIT(7)
 #define GPSR5_TX1_A            BIT(6)
 #define GPSR5_RX1_A            BIT(5)
-#define GPSR5_RTS0_TANS                BIT(4)
+#define GPSR5_RTS0             BIT(4)
 #define GPSR5_CTS0             BIT(3)
 #define GPSR5_TX0              BIT(2)
 #define GPSR5_RX0              BIT(1)
 #define GPSR6_SSI_SDATA0       BIT(2)
 #define GPSR6_SSI_WS0129       BIT(1)
 #define GPSR6_SSI_SCK0129      BIT(0)
-#define GPSR7_HDMI1_CEC                BIT(3)
-#define GPSR7_HDMI0_CEC                BIT(2)
 #define GPSR7_AVS2             BIT(1)
 #define GPSR7_AVS1             BIT(0)
 
 #define DRVCTRL11_D15(x)       ((uint32_t)(x) << 24U)
 #define DRVCTRL11_AVS1(x)      ((uint32_t)(x) << 20U)
 #define DRVCTRL11_AVS2(x)      ((uint32_t)(x) << 16U)
-#define DRVCTRL11_HDMI0_CEC(x) ((uint32_t)(x) << 12U)
-#define DRVCTRL11_HDMI1_CEC(x) ((uint32_t)(x) << 8U)
+#define DRVCTRL11_GP7_02(x)    ((uint32_t)(x) << 12U)
+#define DRVCTRL11_GP7_03(x)    ((uint32_t)(x) << 8U)
 #define DRVCTRL11_DU_DOTCLKIN0(x)      ((uint32_t)(x) << 4U)
 #define DRVCTRL11_DU_DOTCLKIN1(x)      ((uint32_t)(x) << 0U)
 #define DRVCTRL12_DU_DOTCLKIN2(x)      ((uint32_t)(x) << 28U)
@@ -792,7 +790,6 @@ void pfc_init_m3(void)
                      | IPSR_24_FUNC(0)
                      | IPSR_20_FUNC(0)
                      | IPSR_16_FUNC(0)
-                     | IPSR_12_FUNC(0)
                      | IPSR_8_FUNC(6)
                      | IPSR_4_FUNC(6)
                      | IPSR_0_FUNC(6));
@@ -957,11 +954,11 @@ void pfc_init_m3(void)
                      | GPSR5_RX2_A
                      | GPSR5_TX2_A
                      | GPSR5_SCK2
-                     | GPSR5_RTS1_TANS
+                     | GPSR5_RTS1
                      | GPSR5_CTS1
                      | GPSR5_TX1_A
                      | GPSR5_RX1_A
-                     | GPSR5_RTS0_TANS
+                     | GPSR5_RTS0
                      | GPSR5_SCK0);
        pfc_reg_write(PFC_GPSR6, GPSR6_USB30_OVC
                      | GPSR6_USB30_PWEN
@@ -984,9 +981,7 @@ void pfc_init_m3(void)
                      | GPSR6_SSI_SDATA0
                      | GPSR6_SSI_WS0129
                      | GPSR6_SSI_SCK0129);
-       pfc_reg_write(PFC_GPSR7, GPSR7_HDMI1_CEC
-                     | GPSR7_HDMI0_CEC
-                     | GPSR7_AVS2
+       pfc_reg_write(PFC_GPSR7, GPSR7_AVS2
                      | GPSR7_AVS1);
 
        /* initialize POC control register */
@@ -1124,8 +1119,8 @@ void pfc_init_m3(void)
               | DRVCTRL11_D15(3)
               | DRVCTRL11_AVS1(7)
               | DRVCTRL11_AVS2(7)
-              | DRVCTRL11_HDMI0_CEC(7)
-              | DRVCTRL11_HDMI1_CEC(7)
+              | DRVCTRL11_GP7_02(7)
+              | DRVCTRL11_GP7_03(7)
               | DRVCTRL11_DU_DOTCLKIN0(3)
               | DRVCTRL11_DU_DOTCLKIN1(3));
        pfc_reg_write(PFC_DRVCTRL11, reg);
@@ -1281,6 +1276,7 @@ void pfc_init_m3(void)
        mmio_write_32(GPIO_POSNEG4, 0x00000000U);
        mmio_write_32(GPIO_POSNEG5, 0x00000000U);
        mmio_write_32(GPIO_POSNEG6, 0x00000000U);
+       mmio_write_32(GPIO_POSNEG7, 0x00000000U);
 
        /* initialize general IO/interrupt switching */
        mmio_write_32(GPIO_IOINTSEL0, 0x00000000U);
@@ -1290,6 +1286,7 @@ void pfc_init_m3(void)
        mmio_write_32(GPIO_IOINTSEL4, 0x00000000U);
        mmio_write_32(GPIO_IOINTSEL5, 0x00000000U);
        mmio_write_32(GPIO_IOINTSEL6, 0x00000000U);
+       mmio_write_32(GPIO_IOINTSEL7, 0x00000000U);
 
        /* initialize general output register */
        mmio_write_32(GPIO_OUTDT1, 0x00000000U);
@@ -1310,4 +1307,5 @@ void pfc_init_m3(void)
        mmio_write_32(GPIO_INOUTSEL5, 0x0000020EU);
 #endif
        mmio_write_32(GPIO_INOUTSEL6, 0x00013880U);
+       mmio_write_32(GPIO_INOUTSEL7, 0x00000000U);
 }
index 3fac3758e9feaf7458f4146496609e2bf63caa55..501455610d9890297b9dc8c3e334978de53a9ce8 100644 (file)
 #define GPSR5_RX2_A            BIT(11)
 #define GPSR5_TX2_A            BIT(10)
 #define GPSR5_SCK2             BIT(9)
-#define GPSR5_RTS1_TANS                BIT(8)
+#define GPSR5_RTS1             BIT(8)
 #define GPSR5_CTS1             BIT(7)
 #define GPSR5_TX1_A            BIT(6)
 #define GPSR5_RX1_A            BIT(5)
-#define GPSR5_RTS0_TANS                BIT(4)
+#define GPSR5_RTS0             BIT(4)
 #define GPSR5_CTS0             BIT(3)
 #define GPSR5_TX0              BIT(2)
 #define GPSR5_RX0              BIT(1)
 #define GPSR6_SSI_SDATA0       BIT(2)
 #define GPSR6_SSI_WS0129       BIT(1)
 #define GPSR6_SSI_SCK0129      BIT(0)
-#define GPSR7_HDMI1_CEC                BIT(3)
-#define GPSR7_HDMI0_CEC                BIT(2)
 #define GPSR7_AVS2             BIT(1)
 #define GPSR7_AVS1             BIT(0)
 
 #define DRVCTRL11_D15(x)       ((uint32_t)(x) << 24U)
 #define DRVCTRL11_AVS1(x)      ((uint32_t)(x) << 20U)
 #define DRVCTRL11_AVS2(x)      ((uint32_t)(x) << 16U)
-#define DRVCTRL11_HDMI0_CEC(x) ((uint32_t)(x) << 12U)
-#define DRVCTRL11_HDMI1_CEC(x) ((uint32_t)(x) << 8U)
+#define DRVCTRL11_GP7_02(x)    ((uint32_t)(x) << 12U)
+#define DRVCTRL11_GP7_03(x)    ((uint32_t)(x) << 8U)
 #define DRVCTRL11_DU_DOTCLKIN0(x)      ((uint32_t)(x) << 4U)
 #define DRVCTRL11_DU_DOTCLKIN1(x)      ((uint32_t)(x) << 0U)
 #define DRVCTRL12_DU_DOTCLKIN2(x)      ((uint32_t)(x) << 28U)
@@ -699,7 +697,6 @@ void pfc_init_m3n(void)
                      | IPSR_24_FUNC(0)
                      | IPSR_20_FUNC(0)
                      | IPSR_16_FUNC(0)
-                     | IPSR_12_FUNC(0)
                      | IPSR_8_FUNC(6)
                      | IPSR_4_FUNC(6)
                      | IPSR_0_FUNC(6));
@@ -864,11 +861,11 @@ void pfc_init_m3n(void)
                      | GPSR5_RX2_A
                      | GPSR5_TX2_A
                      | GPSR5_SCK2
-                     | GPSR5_RTS1_TANS
+                     | GPSR5_RTS1
                      | GPSR5_CTS1
                      | GPSR5_TX1_A
                      | GPSR5_RX1_A
-                     | GPSR5_RTS0_TANS
+                     | GPSR5_RTS0
                      | GPSR5_SCK0);
        pfc_reg_write(PFC_GPSR6, GPSR6_USB30_OVC
                      | GPSR6_USB30_PWEN
@@ -891,9 +888,7 @@ void pfc_init_m3n(void)
                      | GPSR6_SSI_SDATA0
                      | GPSR6_SSI_WS0129
                      | GPSR6_SSI_SCK0129);
-       pfc_reg_write(PFC_GPSR7, GPSR7_HDMI1_CEC
-                     | GPSR7_HDMI0_CEC
-                     | GPSR7_AVS2
+       pfc_reg_write(PFC_GPSR7, GPSR7_AVS2
                      | GPSR7_AVS1);
 
        /* initialize POC control register */
@@ -1031,8 +1026,8 @@ void pfc_init_m3n(void)
               | DRVCTRL11_D15(3)
               | DRVCTRL11_AVS1(7)
               | DRVCTRL11_AVS2(7)
-              | DRVCTRL11_HDMI0_CEC(7)
-              | DRVCTRL11_HDMI1_CEC(7)
+              | DRVCTRL11_GP7_02(7)
+              | DRVCTRL11_GP7_03(7)
               | DRVCTRL11_DU_DOTCLKIN0(3)
               | DRVCTRL11_DU_DOTCLKIN1(3));
        pfc_reg_write(PFC_DRVCTRL11, reg);
@@ -1188,6 +1183,7 @@ void pfc_init_m3n(void)
        mmio_write_32(GPIO_POSNEG4, 0x00000000U);
        mmio_write_32(GPIO_POSNEG5, 0x00000000U);
        mmio_write_32(GPIO_POSNEG6, 0x00000000U);
+       mmio_write_32(GPIO_POSNEG7, 0x00000000U);
 
        /* initialize general IO/interrupt switching */
        mmio_write_32(GPIO_IOINTSEL0, 0x00000000U);
@@ -1197,6 +1193,7 @@ void pfc_init_m3n(void)
        mmio_write_32(GPIO_IOINTSEL4, 0x00000000U);
        mmio_write_32(GPIO_IOINTSEL5, 0x00000000U);
        mmio_write_32(GPIO_IOINTSEL6, 0x00000000U);
+       mmio_write_32(GPIO_IOINTSEL7, 0x00000000U);
 
        /* initialize general output register */
        mmio_write_32(GPIO_OUTDT1, 0x00000000U);
@@ -1217,4 +1214,5 @@ void pfc_init_m3n(void)
        mmio_write_32(GPIO_INOUTSEL5, 0x0000020EU);
 #endif
        mmio_write_32(GPIO_INOUTSEL6, 0x00013880U);
+       mmio_write_32(GPIO_INOUTSEL7, 0x00000000U);
 }
index 51d6f427cc7687141d825150b660a9b7a9445fc5..60637580745547d1fa23f5d8034328d6693e720a 100644 (file)
@@ -709,7 +709,7 @@ void pfc_init_v3m(void)
                                   | IOCTRL31_POC_VI0_DATA7
                                   | IOCTRL31_POC_VI0_DATA6);
 
-       pfc_reg_write(PFC_POCCTRL1, 0x00000000);
+       pfc_reg_write(PFC_POCCTRL2, 0x00000000);
 
        pfc_reg_write(PFC_TDSELCTRL0, 0x00000000);
 
index b0b4e6fd99abf1482a2e8a3aeba09706c419ba21..e7dd54397f9645e7bff9e6785acee10cb01d980d 100644 (file)
 #define PFC_DRVCTRL24          (PFC_BASE + 0x0360U)
 #define PFC_POCCTRL0           (PFC_BASE + 0x0380U)
 #define PFC_IOCTRL31           (PFC_BASE + 0x0384U)
-#define PFC_POCCTRL1           (PFC_BASE + 0x0388U)
+#define PFC_POCCTRL2           (PFC_BASE + 0x0388U)
 #define PFC_TDSELCTRL0         (PFC_BASE + 0x03C0U)
 #define PFC_IOCTRL             (PFC_BASE + 0x03E0U)
 #define PFC_TSREG              (PFC_BASE + 0x03E4U)
index d97e593bbdb82056ca5183b2424c534668b2bc2a..f4c9d3abcb70132d15814a5864101c8f9d39c4b6 100644 (file)
@@ -763,10 +763,10 @@ uint32_t rcar_pwrc_get_cluster(void)
 
        reg = mmio_read_32(RCAR_PRR);
 
-       if (reg & (1 << (STATE_CA53_CPU + RCAR_CA53CPU_NUM_MAX)))
+       if (reg & (1U << (STATE_CA53_CPU + RCAR_CA53CPU_NUM_MAX)))
                return RCAR_CLUSTER_CA57;
 
-       if (reg & (1 << (STATE_CA57_CPU + RCAR_CA57CPU_NUM_MAX)))
+       if (reg & (1U << (STATE_CA57_CPU + RCAR_CA57CPU_NUM_MAX)))
                return RCAR_CLUSTER_CA53;
 
        return RCAR_CLUSTER_A53A57;
@@ -810,7 +810,7 @@ uint32_t rcar_pwrc_get_cpu_num(uint32_t c)
 
 count_ca57:
        if (IS_A53A57(c) || IS_CA57(c)) {
-               if (reg & (1 << (STATE_CA57_CPU + RCAR_CA57CPU_NUM_MAX)))
+               if (reg & (1U << (STATE_CA57_CPU + RCAR_CA57CPU_NUM_MAX)))
                        goto done;
 
                for (i = 0; i < RCAR_CA57CPU_NUM_MAX; i++) {
index cfb35ff92350ceeb99a195b5ca1a3182fc0aba8c..e67c6ef2d60c97f1208d561906011b641380ce40 100644 (file)
@@ -15,7 +15,7 @@
 
 #define PWKUPR_WEN             (1ull << 31)
 
-#define PSYSR_AFF_L2           (1 << 31)
+#define PSYSR_AFF_L2           (1U << 31)
 #define PSYSR_AFF_L1           (1 << 30)
 #define PSYSR_AFF_L0           (1 << 29)
 #define PSYSR_WEN              (1 << 28)
index bea27521013f2e8cf381b3e290356f6b29a5edb0..5c11b62de6e30832505a45098d486bb9f5a079cb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2018, Renesas Electronics Corporation. All rights reserved.
+ * Copyright (c) 2015-2019, Renesas Electronics Corporation. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
 #include <lib/mmio.h>
 
 #include "cpg_registers.h"
-#include "rpc_registers.h"
+#include "rcar_def.h"
 #include "rcar_private.h"
+#include "rpc_registers.h"
 
 #define MSTPSR9_RPC_BIT                (0x00020000U)
 #define RPC_CMNCR_MD_BIT       (0x80000000U)
+#define RPC_PHYCNT_CAL         BIT(31)
+#define RPC_PHYCNT_STRTIM_M3V1 (0x6 << 15UL)
+#define RPC_PHYCNT_STRTIM      (0x7 << 15UL)
 
 static void rpc_enable(void)
 {
@@ -25,8 +29,25 @@ static void rpc_enable(void)
 
 static void rpc_setup(void)
 {
+       uint32_t product, cut, reg, phy_strtim;
+
        if (mmio_read_32(RPC_CMNCR) & RPC_CMNCR_MD_BIT)
                mmio_clrbits_32(RPC_CMNCR, RPC_CMNCR_MD_BIT);
+
+       product = mmio_read_32(RCAR_PRR) & RCAR_PRODUCT_MASK;
+       cut = mmio_read_32(RCAR_PRR) & RCAR_CUT_MASK;
+
+       if ((product ==  RCAR_PRODUCT_M3) && (cut < RCAR_CUT_VER30))
+               phy_strtim = RPC_PHYCNT_STRTIM_M3V1;
+       else
+               phy_strtim = RPC_PHYCNT_STRTIM;
+
+       reg = mmio_read_32(RPC_PHYCNT);
+       reg &= ~RPC_PHYCNT_STRTIM;
+       reg |= phy_strtim;
+       mmio_write_32(RPC_PHYCNT, reg);
+       reg |= RPC_PHYCNT_CAL;
+       mmio_write_32(RPC_PHYCNT, reg);
 }
 
 void rcar_rpc_init(void)
diff --git a/drivers/staging/renesas/rcar/ddr/ddr_a/boot_init_dram_regdef.h b/drivers/staging/renesas/rcar/ddr/ddr_a/boot_init_dram_regdef.h
new file mode 100644 (file)
index 0000000..397bde0
--- /dev/null
@@ -0,0 +1,291 @@
+/*
+ * Copyright (c) 2015-2019, Renesas Electronics Corporation
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef BOOT_INIT_DRAM_REGDEF_H_
+#define BOOT_INIT_DRAM_REGDEF_H_
+
+/* DBSC registers */
+#define DBSC_DBSYSCONF0                0xE6790000U
+#define DBSC_DBSYSCONF1                0xE6790004U
+#define DBSC_DBPHYCONF0                0xE6790010U
+#define DBSC_DBKIND            0xE6790020U
+#define DBSC_DBMEMCONF00       0xE6790030U
+#define DBSC_DBMEMCONF01       0xE6790034U
+#define DBSC_DBMEMCONF02       0xE6790038U
+#define DBSC_DBMEMCONF03       0xE679003CU
+#define DBSC_DBMEMCONF10       0xE6790040U
+#define DBSC_DBMEMCONF11       0xE6790044U
+#define DBSC_DBMEMCONF12       0xE6790048U
+#define DBSC_DBMEMCONF13       0xE679004CU
+#define DBSC_DBMEMCONF20       0xE6790050U
+#define DBSC_DBMEMCONF21       0xE6790054U
+#define DBSC_DBMEMCONF22       0xE6790058U
+#define DBSC_DBMEMCONF23       0xE679005CU
+#define DBSC_DBMEMCONF30       0xE6790060U
+#define DBSC_DBMEMCONF31       0xE6790064U
+#define DBSC_DBMEMCONF32       0xE6790068U
+#define DBSC_DBMEMCONF33       0xE679006CU
+#define DBSC_DBSYSCNT0         0xE6790100U
+#define DBSC_DBSVCR1           0xE6790104U
+#define DBSC_DBSTATE0          0xE6790108U
+#define DBSC_DBSTATE1          0xE679010CU
+#define DBSC_DBINTEN           0xE6790180U
+#define DBSC_DBINTSTAT0                0xE6790184U
+#define DBSC_DBACEN            0xE6790200U
+#define DBSC_DBRFEN            0xE6790204U
+#define DBSC_DBCMD             0xE6790208U
+#define DBSC_DBWAIT            0xE6790210U
+#define DBSC_DBSYSCTRL0                0xE6790280U
+#define DBSC_DBTR0             0xE6790300U
+#define DBSC_DBTR1             0xE6790304U
+#define DBSC_DBTR2             0xE6790308U
+#define DBSC_DBTR3             0xE679030CU
+#define DBSC_DBTR4             0xE6790310U
+#define DBSC_DBTR5             0xE6790314U
+#define DBSC_DBTR6             0xE6790318U
+#define DBSC_DBTR7             0xE679031CU
+#define DBSC_DBTR8             0xE6790320U
+#define DBSC_DBTR9             0xE6790324U
+#define DBSC_DBTR10            0xE6790328U
+#define DBSC_DBTR11            0xE679032CU
+#define DBSC_DBTR12            0xE6790330U
+#define DBSC_DBTR13            0xE6790334U
+#define DBSC_DBTR14            0xE6790338U
+#define DBSC_DBTR15            0xE679033CU
+#define DBSC_DBTR16            0xE6790340U
+#define DBSC_DBTR17            0xE6790344U
+#define DBSC_DBTR18            0xE6790348U
+#define DBSC_DBTR19            0xE679034CU
+#define DBSC_DBTR20            0xE6790350U
+#define DBSC_DBTR21            0xE6790354U
+#define DBSC_DBTR22            0xE6790358U
+#define DBSC_DBTR23            0xE679035CU
+#define DBSC_DBTR24            0xE6790360U
+#define DBSC_DBTR25            0xE6790364U
+#define DBSC_DBBL              0xE6790400U
+#define DBSC_DBRFCNF1          0xE6790414U
+#define DBSC_DBRFCNF2          0xE6790418U
+#define DBSC_DBTSPCNF          0xE6790420U
+#define DBSC_DBCALCNF          0xE6790424U
+#define DBSC_DBRNK2            0xE6790438U
+#define DBSC_DBRNK3            0xE679043CU
+#define DBSC_DBRNK4            0xE6790440U
+#define DBSC_DBRNK5            0xE6790444U
+#define DBSC_DBPDNCNF          0xE6790450U
+#define DBSC_DBODT0            0xE6790460U
+#define DBSC_DBODT1            0xE6790464U
+#define DBSC_DBODT2            0xE6790468U
+#define DBSC_DBODT3            0xE679046CU
+#define DBSC_DBODT4            0xE6790470U
+#define DBSC_DBODT5            0xE6790474U
+#define DBSC_DBODT6            0xE6790478U
+#define DBSC_DBODT7            0xE679047CU
+#define DBSC_DBADJ0            0xE6790500U
+#define DBSC_DBDBICNT          0xE6790518U
+#define DBSC_DBDFIPMSTRCNF     0xE6790520U
+#define DBSC_DBDFIPMSTRSTAT    0xE6790524U
+#define DBSC_DBDFILPCNF                0xE6790528U
+#define DBSC_DBDFICUPDCNF      0xE679052CU
+#define DBSC_DBDFISTAT0                0xE6790600U
+#define DBSC_DBDFICNT0         0xE6790604U
+#define DBSC_DBPDCNT00         0xE6790610U
+#define DBSC_DBPDCNT01         0xE6790614U
+#define DBSC_DBPDCNT02         0xE6790618U
+#define DBSC_DBPDCNT03         0xE679061CU
+#define DBSC_DBPDLK0           0xE6790620U
+#define DBSC_DBPDRGA0          0xE6790624U
+#define DBSC_DBPDRGD0          0xE6790628U
+#define DBSC_DBPDSTAT00                0xE6790630U
+#define DBSC_DBDFISTAT1                0xE6790640U
+#define DBSC_DBDFICNT1         0xE6790644U
+#define DBSC_DBPDCNT10         0xE6790650U
+#define DBSC_DBPDCNT11         0xE6790654U
+#define DBSC_DBPDCNT12         0xE6790658U
+#define DBSC_DBPDCNT13         0xE679065CU
+#define DBSC_DBPDLK1           0xE6790660U
+#define DBSC_DBPDRGA1          0xE6790664U
+#define DBSC_DBPDRGD1          0xE6790668U
+#define DBSC_DBPDSTAT10                0xE6790670U
+#define DBSC_DBDFISTAT2                0xE6790680U
+#define DBSC_DBDFICNT2         0xE6790684U
+#define DBSC_DBPDCNT20         0xE6790690U
+#define DBSC_DBPDCNT21         0xE6790694U
+#define DBSC_DBPDCNT22         0xE6790698U
+#define DBSC_DBPDCNT23         0xE679069CU
+#define DBSC_DBPDLK2           0xE67906A0U
+#define DBSC_DBPDRGA2          0xE67906A4U
+#define DBSC_DBPDRGD2          0xE67906A8U
+#define DBSC_DBPDSTAT20                0xE67906B0U
+#define DBSC_DBDFISTAT3                0xE67906C0U
+#define DBSC_DBDFICNT3         0xE67906C4U
+#define DBSC_DBPDCNT30         0xE67906D0U
+#define DBSC_DBPDCNT31         0xE67906D4U
+#define DBSC_DBPDCNT32         0xE67906D8U
+#define DBSC_DBPDCNT33         0xE67906DCU
+#define DBSC_DBPDLK3           0xE67906E0U
+#define DBSC_DBPDRGA3          0xE67906E4U
+#define DBSC_DBPDRGD3          0xE67906E8U
+#define DBSC_DBPDSTAT30                0xE67906F0U
+#define DBSC_DBBUS0CNF0                0xE6790800U
+#define DBSC_DBBUS0CNF1                0xE6790804U
+#define DBSC_DBCAM0CNF1                0xE6790904U
+#define DBSC_DBCAM0CNF2                0xE6790908U
+#define DBSC_DBCAM0CNF3                0xE679090CU
+#define DBSC_DBCAM0CTRL0       0xE6790940U
+#define DBSC_DBCAM0STAT0       0xE6790980U
+#define DBSC_DBCAM1STAT0       0xE6790990U
+#define DBSC_DBBCAMSWAP                0xE67909F0U
+#define DBSC_DBBCAMDIS         0xE67909FCU
+#define DBSC_DBSCHCNT0         0xE6791000U
+#define DBSC_DBSCHCNT1         0xE6791004U
+#define DBSC_DBSCHSZ0          0xE6791010U
+#define DBSC_DBSCHRW0          0xE6791020U
+#define DBSC_DBSCHRW1          0xE6791024U
+#define DBSC_DBSCHQOS00                0xE6791030U
+#define DBSC_DBSCHQOS01                0xE6791034U
+#define DBSC_DBSCHQOS02                0xE6791038U
+#define DBSC_DBSCHQOS03                0xE679103CU
+#define DBSC_DBSCHQOS10                0xE6791040U
+#define DBSC_DBSCHQOS11                0xE6791044U
+#define DBSC_DBSCHQOS12                0xE6791048U
+#define DBSC_DBSCHQOS13                0xE679104CU
+#define DBSC_DBSCHQOS20                0xE6791050U
+#define DBSC_DBSCHQOS21                0xE6791054U
+#define DBSC_DBSCHQOS22                0xE6791058U
+#define DBSC_DBSCHQOS23                0xE679105CU
+#define DBSC_DBSCHQOS30                0xE6791060U
+#define DBSC_DBSCHQOS31                0xE6791064U
+#define DBSC_DBSCHQOS32                0xE6791068U
+#define DBSC_DBSCHQOS33                0xE679106CU
+#define DBSC_DBSCHQOS40                0xE6791070U
+#define DBSC_DBSCHQOS41                0xE6791074U
+#define DBSC_DBSCHQOS42                0xE6791078U
+#define DBSC_DBSCHQOS43                0xE679107CU
+#define DBSC_DBSCHQOS50                0xE6791080U
+#define DBSC_DBSCHQOS51                0xE6791084U
+#define DBSC_DBSCHQOS52                0xE6791088U
+#define DBSC_DBSCHQOS53                0xE679108CU
+#define DBSC_DBSCHQOS60                0xE6791090U
+#define DBSC_DBSCHQOS61                0xE6791094U
+#define DBSC_DBSCHQOS62                0xE6791098U
+#define DBSC_DBSCHQOS63                0xE679109CU
+#define DBSC_DBSCHQOS70                0xE67910A0U
+#define DBSC_DBSCHQOS71                0xE67910A4U
+#define DBSC_DBSCHQOS72                0xE67910A8U
+#define DBSC_DBSCHQOS73                0xE67910ACU
+#define DBSC_DBSCHQOS80                0xE67910B0U
+#define DBSC_DBSCHQOS81                0xE67910B4U
+#define DBSC_DBSCHQOS82                0xE67910B8U
+#define DBSC_DBSCHQOS83                0xE67910BCU
+#define DBSC_DBSCHQOS90                0xE67910C0U
+#define DBSC_DBSCHQOS91                0xE67910C4U
+#define DBSC_DBSCHQOS92                0xE67910C8U
+#define DBSC_DBSCHQOS93                0xE67910CCU
+#define DBSC_DBSCHQOS100       0xE67910D0U
+#define DBSC_DBSCHQOS101       0xE67910D4U
+#define DBSC_DBSCHQOS102       0xE67910D8U
+#define DBSC_DBSCHQOS103       0xE67910DCU
+#define DBSC_DBSCHQOS110       0xE67910E0U
+#define DBSC_DBSCHQOS111       0xE67910E4U
+#define DBSC_DBSCHQOS112       0xE67910E8U
+#define DBSC_DBSCHQOS113       0xE67910ECU
+#define DBSC_DBSCHQOS120       0xE67910F0U
+#define DBSC_DBSCHQOS121       0xE67910F4U
+#define DBSC_DBSCHQOS122       0xE67910F8U
+#define DBSC_DBSCHQOS123       0xE67910FCU
+#define DBSC_DBSCHQOS130       0xE6791100U
+#define DBSC_DBSCHQOS131       0xE6791104U
+#define DBSC_DBSCHQOS132       0xE6791108U
+#define DBSC_DBSCHQOS133       0xE679110CU
+#define DBSC_DBSCHQOS140       0xE6791110U
+#define DBSC_DBSCHQOS141       0xE6791114U
+#define DBSC_DBSCHQOS142       0xE6791118U
+#define DBSC_DBSCHQOS143       0xE679111CU
+#define DBSC_DBSCHQOS150       0xE6791120U
+#define DBSC_DBSCHQOS151       0xE6791124U
+#define DBSC_DBSCHQOS152       0xE6791128U
+#define DBSC_DBSCHQOS153       0xE679112CU
+#define DBSC_SCFCTST0          0xE6791700U
+#define DBSC_SCFCTST1          0xE6791708U
+#define DBSC_SCFCTST2          0xE679170CU
+#define DBSC_DBMRRDR0          0xE6791800U
+#define DBSC_DBMRRDR1          0xE6791804U
+#define DBSC_DBMRRDR2          0xE6791808U
+#define DBSC_DBMRRDR3          0xE679180CU
+#define DBSC_DBMRRDR4          0xE6791810U
+#define DBSC_DBMRRDR5          0xE6791814U
+#define DBSC_DBMRRDR6          0xE6791818U
+#define DBSC_DBMRRDR7          0xE679181CU
+#define DBSC_DBDTMP0           0xE6791820U
+#define DBSC_DBDTMP1           0xE6791824U
+#define DBSC_DBDTMP2           0xE6791828U
+#define DBSC_DBDTMP3           0xE679182CU
+#define DBSC_DBDTMP4           0xE6791830U
+#define DBSC_DBDTMP5           0xE6791834U
+#define DBSC_DBDTMP6           0xE6791838U
+#define DBSC_DBDTMP7           0xE679183CU
+#define DBSC_DBDQSOSC00                0xE6791840U
+#define DBSC_DBDQSOSC01                0xE6791844U
+#define DBSC_DBDQSOSC10                0xE6791848U
+#define DBSC_DBDQSOSC11                0xE679184CU
+#define DBSC_DBDQSOSC20                0xE6791850U
+#define DBSC_DBDQSOSC21                0xE6791854U
+#define DBSC_DBDQSOSC30                0xE6791858U
+#define DBSC_DBDQSOSC31                0xE679185CU
+#define DBSC_DBDQSOSC40                0xE6791860U
+#define DBSC_DBDQSOSC41                0xE6791864U
+#define DBSC_DBDQSOSC50                0xE6791868U
+#define DBSC_DBDQSOSC51                0xE679186CU
+#define DBSC_DBDQSOSC60                0xE6791870U
+#define DBSC_DBDQSOSC61                0xE6791874U
+#define DBSC_DBDQSOSC70                0xE6791878U
+#define DBSC_DBDQSOSC71                0xE679187CU
+#define DBSC_DBOSCTHH00                0xE6791880U
+#define DBSC_DBOSCTHH01                0xE6791884U
+#define DBSC_DBOSCTHH10                0xE6791888U
+#define DBSC_DBOSCTHH11                0xE679188CU
+#define DBSC_DBOSCTHH20                0xE6791890U
+#define DBSC_DBOSCTHH21                0xE6791894U
+#define DBSC_DBOSCTHH30                0xE6791898U
+#define DBSC_DBOSCTHH31                0xE679189CU
+#define DBSC_DBOSCTHH40                0xE67918A0U
+#define DBSC_DBOSCTHH41                0xE67918A4U
+#define DBSC_DBOSCTHH50                0xE67918A8U
+#define DBSC_DBOSCTHH51                0xE67918ACU
+#define DBSC_DBOSCTHH60                0xE67918B0U
+#define DBSC_DBOSCTHH61                0xE67918B4U
+#define DBSC_DBOSCTHH70                0xE67918B8U
+#define DBSC_DBOSCTHH71                0xE67918BCU
+#define DBSC_DBOSCTHL00                0xE67918C0U
+#define DBSC_DBOSCTHL01                0xE67918C4U
+#define DBSC_DBOSCTHL10                0xE67918C8U
+#define DBSC_DBOSCTHL11                0xE67918CCU
+#define DBSC_DBOSCTHL20                0xE67918D0U
+#define DBSC_DBOSCTHL21                0xE67918D4U
+#define DBSC_DBOSCTHL30                0xE67918D8U
+#define DBSC_DBOSCTHL31                0xE67918DCU
+#define DBSC_DBOSCTHL40                0xE67918E0U
+#define DBSC_DBOSCTHL41                0xE67918E4U
+#define DBSC_DBOSCTHL50                0xE67918E8U
+#define DBSC_DBOSCTHL51                0xE67918ECU
+#define DBSC_DBOSCTHL60                0xE67918F0U
+#define DBSC_DBOSCTHL61                0xE67918F4U
+#define DBSC_DBOSCTHL70                0xE67918F8U
+#define DBSC_DBOSCTHL71                0xE67918FCU
+#define DBSC_DBMEMSWAPCONF0    0xE6792000U
+
+/* CPG registers */
+#define CPG_SRCR4              0xE61500BCU
+#define CPG_PLLECR             0xE61500D0U
+#define CPG_CPGWPR             0xE6150900U
+#define CPG_CPGWPCR            0xE6150904U
+#define CPG_SRSTCLR4           0xE6150950U
+
+/* MODE Monitor registers */
+#define RST_MODEMR             0xE6160060U
+
+#endif /* BOOT_INIT_DRAM_REGDEF_H_*/
diff --git a/drivers/staging/renesas/rcar/ddr/ddr_a/boot_init_dram_regdef_d3.h b/drivers/staging/renesas/rcar/ddr/ddr_a/boot_init_dram_regdef_d3.h
deleted file mode 100644 (file)
index e157ab1..0000000
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * Copyright (c) 2015-2017, Renesas Electronics Corporation
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-/*
- * Revision history
- *
- * rev.0.01    2017/05/22    New
- */
-
-#ifndef BOOT_INIT_DRAM_REGDEF_D3_H_
-#define BOOT_INIT_DRAM_REGDEF_D3_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-#define                                BIT0                                            0x00000001U
-#define                                BIT30                                           0x40000000U
-
-/* DBSC registers */
-
-#define                                DBSC_D3_DBSYSCONF1         0xE6790004U
-#define                                DBSC_D3_DBPHYCONF0         0xE6790010U
-#define                                DBSC_D3_DBKIND             0xE6790020U
-#define                                DBSC_D3_DBMEMCONF00        0xE6790030U
-#define                                DBSC_D3_DBMEMCONF01        0xE6790034U
-#define                                DBSC_D3_DBMEMCONF02        0xE6790038U
-#define                                DBSC_D3_DBMEMCONF03        0xE679003CU
-#define                                DBSC_D3_DBMEMCONF10        0xE6790040U
-#define                                DBSC_D3_DBMEMCONF11        0xE6790044U
-#define                                DBSC_D3_DBMEMCONF12        0xE6790048U
-#define                                DBSC_D3_DBMEMCONF13        0xE679004CU
-#define                                DBSC_D3_DBMEMCONF20        0xE6790050U
-#define                                DBSC_D3_DBMEMCONF21        0xE6790054U
-#define                                DBSC_D3_DBMEMCONF22        0xE6790058U
-#define                                DBSC_D3_DBMEMCONF23        0xE679005CU
-#define                                DBSC_D3_DBMEMCONF30        0xE6790060U
-#define                                DBSC_D3_DBMEMCONF31        0xE6790064U
-#define                                DBSC_D3_DBMEMCONF32        0xE6790068U
-#define                                DBSC_D3_DBMEMCONF33        0xE679006CU
-#define                                DBSC_D3_DBSYSCNT0          0xE6790100U
-#define                                DBSC_D3_DBSVCR1            0xE6790104U
-#define                                DBSC_D3_DBSTATE0           0xE6790108U
-#define                                DBSC_D3_DBSTATE1           0xE679010CU
-#define                                DBSC_D3_DBINTEN            0xE6790180U
-#define                                DBSC_D3_DBINTSTAT0         0xE6790184U
-#define                                DBSC_D3_DBACEN             0xE6790200U
-#define                                DBSC_D3_DBRFEN             0xE6790204U
-#define                                DBSC_D3_DBCMD              0xE6790208U
-#define                                DBSC_D3_DBWAIT             0xE6790210U
-#define                                DBSC_D3_DBSYSCTRL0         0xE6790280U
-#define                                DBSC_D3_DBTR0              0xE6790300U
-#define                                DBSC_D3_DBTR1              0xE6790304U
-#define                                DBSC_D3_DBTR2              0xE6790308U
-#define                                DBSC_D3_DBTR3              0xE679030CU
-#define                                DBSC_D3_DBTR4              0xE6790310U
-#define                                DBSC_D3_DBTR5              0xE6790314U
-#define                                DBSC_D3_DBTR6              0xE6790318U
-#define                                DBSC_D3_DBTR7              0xE679031CU
-#define                                DBSC_D3_DBTR8              0xE6790320U
-#define                                DBSC_D3_DBTR9              0xE6790324U
-#define                                DBSC_D3_DBTR10             0xE6790328U
-#define                                DBSC_D3_DBTR11             0xE679032CU
-#define                                DBSC_D3_DBTR12             0xE6790330U
-#define                                DBSC_D3_DBTR13             0xE6790334U
-#define                                DBSC_D3_DBTR14             0xE6790338U
-#define                                DBSC_D3_DBTR15             0xE679033CU
-#define                                DBSC_D3_DBTR16             0xE6790340U
-#define                                DBSC_D3_DBTR17             0xE6790344U
-#define                                DBSC_D3_DBTR18             0xE6790348U
-#define                                DBSC_D3_DBTR19             0xE679034CU
-#define                                DBSC_D3_DBTR20             0xE6790350U
-#define                                DBSC_D3_DBTR21             0xE6790354U
-#define                                DBSC_D3_DBTR22             0xE6790358U
-#define                                DBSC_D3_DBTR24             0xE6790360U
-#define                                DBSC_D3_DBTR25             0xE6790364U
-#define                                DBSC_D3_DBBL               0xE6790400U
-#define                                DBSC_D3_DBRFCNF1           0xE6790414U
-#define                                DBSC_D3_DBRFCNF2           0xE6790418U
-#define                                DBSC_D3_DBCALCNF           0xE6790424U
-#define                                DBSC_D3_DBRNK2             0xE6790438U
-#define                                DBSC_D3_DBRNK3             0xE679043CU
-#define                                DBSC_D3_DBRNK4             0xE6790440U
-#define                                DBSC_D3_DBRNK5             0xE6790444U
-#define                                DBSC_D3_DBPDNCNF           0xE6790450U
-#define                                DBSC_D3_DBODT0             0xE6790460U
-#define                                DBSC_D3_DBODT1             0xE6790464U
-#define                                DBSC_D3_DBODT2             0xE6790468U
-#define                                DBSC_D3_DBODT3             0xE679046CU
-#define                                DBSC_D3_DBADJ0             0xE6790500U
-#define                                DBSC_D3_DBDBICNT           0xE6790518U
-#define                                DBSC_D3_DBDFICUPDCNF       0xE679052CU
-#define                                DBSC_D3_DBDFICNT0          0xE6790604U
-#define                                DBSC_D3_DBPDLK0            0xE6790620U
-#define                                DBSC_D3_DBPDRGA0           0xE6790624U
-#define                                DBSC_D3_DBPDRGD0           0xE6790628U
-#define                                DBSC_D3_DBPDSTAT00         0xE6790630U
-#define                                DBSC_D3_DBDFISTAT1         0xE6790640U
-#define                                DBSC_D3_DBDFICNT1          0xE6790644U
-#define                                DBSC_D3_DBPDLK1            0xE6790660U
-#define                                DBSC_D3_DBPDRGA1           0xE6790664U
-#define                                DBSC_D3_DBPDRGD1           0xE6790668U
-#define                                DBSC_D3_DBDFICNT2          0xE6790684U
-#define                                DBSC_D3_DBPDLK2            0xE67906A0U
-#define                                DBSC_D3_DBPDRGA2           0xE67906A4U
-#define                                DBSC_D3_DBPDRGD2           0xE67906A8U
-#define                                DBSC_D3_DBPDSTAT20         0xE67906B0U
-#define                                DBSC_D3_DBDFISTAT3         0xE67906C0U
-#define                                DBSC_D3_DBDFICNT3          0xE67906C4U
-#define                                DBSC_D3_DBPDLK3            0xE67906E0U
-#define                                DBSC_D3_DBPDRGA3           0xE67906E4U
-#define                                DBSC_D3_DBPDRGD3           0xE67906E8U
-#define                                DBSC_D3_DBBUS0CNF1         0xE6790804U
-#define                                DBSC_D3_DBCAM0CNF1         0xE6790904U
-#define                                DBSC_D3_DBCAM0CNF2         0xE6790908U
-#define                                DBSC_D3_DBCAM0STAT0        0xE6790980U
-#define                                DBSC_D3_DBCAM1STAT0        0xE6790990U
-#define                                DBSC_D3_DBBCAMDIS          0xE67909FCU
-#define                                DBSC_D3_DBSCHCNT0          0xE6791000U
-#define                                DBSC_D3_DBSCHSZ0           0xE6791010U
-#define                                DBSC_D3_DBSCHRW0           0xE6791020U
-#define                                DBSC_D3_DBSCHRW1           0xE6791024U
-#define                                DBSC_D3_DBSCHQOS00         0xE6791030U
-#define                                DBSC_D3_DBSCHQOS01         0xE6791034U
-#define                                DBSC_D3_DBSCHQOS02         0xE6791038U
-#define                                DBSC_D3_DBSCHQOS03         0xE679103CU
-#define                                DBSC_D3_DBSCHQOS10         0xE6791040U
-#define                                DBSC_D3_DBSCHQOS11         0xE6791044U
-#define                                DBSC_D3_DBSCHQOS12         0xE6791048U
-#define                                DBSC_D3_DBSCHQOS13         0xE679104CU
-#define                                DBSC_D3_DBSCHQOS20         0xE6791050U
-#define                                DBSC_D3_DBSCHQOS21         0xE6791054U
-#define                                DBSC_D3_DBSCHQOS22         0xE6791058U
-#define                                DBSC_D3_DBSCHQOS23         0xE679105CU
-#define                                DBSC_D3_DBSCHQOS30         0xE6791060U
-#define                                DBSC_D3_DBSCHQOS31         0xE6791064U
-#define                                DBSC_D3_DBSCHQOS32         0xE6791068U
-#define                                DBSC_D3_DBSCHQOS33         0xE679106CU
-#define                                DBSC_D3_DBSCHQOS40         0xE6791070U
-#define                                DBSC_D3_DBSCHQOS41         0xE6791074U
-#define                                DBSC_D3_DBSCHQOS42         0xE6791078U
-#define                                DBSC_D3_DBSCHQOS43         0xE679107CU
-#define                                DBSC_D3_DBSCHQOS50         0xE6791080U
-#define                                DBSC_D3_DBSCHQOS51         0xE6791084U
-#define                                DBSC_D3_DBSCHQOS52         0xE6791088U
-#define                                DBSC_D3_DBSCHQOS53         0xE679108CU
-#define                                DBSC_D3_DBSCHQOS60         0xE6791090U
-#define                                DBSC_D3_DBSCHQOS61         0xE6791094U
-#define                                DBSC_D3_DBSCHQOS62         0xE6791098U
-#define                                DBSC_D3_DBSCHQOS63         0xE679109CU
-#define                                DBSC_D3_DBSCHQOS70         0xE67910A0U
-#define                                DBSC_D3_DBSCHQOS71         0xE67910A4U
-#define                                DBSC_D3_DBSCHQOS72         0xE67910A8U
-#define                                DBSC_D3_DBSCHQOS73         0xE67910ACU
-#define                                DBSC_D3_DBSCHQOS80         0xE67910B0U
-#define                                DBSC_D3_DBSCHQOS81         0xE67910B4U
-#define                                DBSC_D3_DBSCHQOS82         0xE67910B8U
-#define                                DBSC_D3_DBSCHQOS83         0xE67910BCU
-#define                                DBSC_D3_DBSCHQOS90         0xE67910C0U
-#define                                DBSC_D3_DBSCHQOS91         0xE67910C4U
-#define                                DBSC_D3_DBSCHQOS92         0xE67910C8U
-#define                                DBSC_D3_DBSCHQOS93         0xE67910CCU
-#define                                DBSC_D3_DBSCHQOS100        0xE67910D0U
-#define                                DBSC_D3_DBSCHQOS101        0xE67910D4U
-#define                                DBSC_D3_DBSCHQOS102        0xE67910D8U
-#define                                DBSC_D3_DBSCHQOS103        0xE67910DCU
-#define                                DBSC_D3_DBSCHQOS110        0xE67910E0U
-#define                                DBSC_D3_DBSCHQOS111        0xE67910E4U
-#define                                DBSC_D3_DBSCHQOS112        0xE67910E8U
-#define                                DBSC_D3_DBSCHQOS113        0xE67910ECU
-#define                                DBSC_D3_DBSCHQOS120        0xE67910F0U
-#define                                DBSC_D3_DBSCHQOS121        0xE67910F4U
-#define                                DBSC_D3_DBSCHQOS122        0xE67910F8U
-#define                                DBSC_D3_DBSCHQOS123        0xE67910FCU
-#define                                DBSC_D3_DBSCHQOS130        0xE6791100U
-#define                                DBSC_D3_DBSCHQOS131        0xE6791104U
-#define                                DBSC_D3_DBSCHQOS132        0xE6791108U
-#define                                DBSC_D3_DBSCHQOS133        0xE679110CU
-#define                                DBSC_D3_DBSCHQOS140        0xE6791110U
-#define                                DBSC_D3_DBSCHQOS141        0xE6791114U
-#define                                DBSC_D3_DBSCHQOS142        0xE6791118U
-#define                                DBSC_D3_DBSCHQOS143        0xE679111CU
-#define                                DBSC_D3_DBSCHQOS150        0xE6791120U
-#define                                DBSC_D3_DBSCHQOS151        0xE6791124U
-#define                                DBSC_D3_DBSCHQOS152        0xE6791128U
-#define                                DBSC_D3_DBSCHQOS153        0xE679112CU
-#define                                DBSC_D3_SCFCTST0           0xE6791700U
-#define                                DBSC_D3_SCFCTST1           0xE6791708U
-#define                                DBSC_D3_SCFCTST2           0xE679170CU
-#define                                DBSC_D3_DBMRRDR0           0xE6791800U
-#define                                DBSC_D3_DBMRRDR1           0xE6791804U
-#define                                DBSC_D3_DBMRRDR2           0xE6791808U
-#define                                DBSC_D3_DBMRRDR3           0xE679180CU
-#define                                DBSC_D3_DBMRRDR4           0xE6791810U
-#define                                DBSC_D3_DBMRRDR5           0xE6791814U
-#define                                DBSC_D3_DBMRRDR6           0xE6791818U
-#define                                DBSC_D3_DBMRRDR7           0xE679181CU
-
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* BOOT_INIT_DRAM_REGDEF_D3_H_*/
diff --git a/drivers/staging/renesas/rcar/ddr/ddr_a/boot_init_dram_regdef_e3.h b/drivers/staging/renesas/rcar/ddr/ddr_a/boot_init_dram_regdef_e3.h
deleted file mode 100644 (file)
index 8606f76..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (c) 2018, Renesas Electronics Corporation. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef BOOT_INIT_DRAM_REGDEF_E3_H
-#define BOOT_INIT_DRAM_REGDEF_E3_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-#define                                BIT0                                            0x00000001U
-#define                                BIT11                                           0x00000800U
-#define                                BIT30                                           0x40000000U
-
-/* DBSC registers */
-
-#define                                DBSC_E3_DBSYSCONF1         0xE6790004U
-#define                                DBSC_E3_DBPHYCONF0         0xE6790010U
-#define                                DBSC_E3_DBKIND             0xE6790020U
-#define                                DBSC_E3_DBMEMCONF00        0xE6790030U
-#define                                DBSC_E3_DBSYSCNT0          0xE6790100U
-#define                                DBSC_E3_DBACEN             0xE6790200U
-#define                                DBSC_E3_DBRFEN             0xE6790204U
-#define                                DBSC_E3_DBCMD              0xE6790208U
-#define                                DBSC_E3_DBWAIT             0xE6790210U
-#define                                DBSC_E3_DBTR0              0xE6790300U
-#define                                DBSC_E3_DBTR1              0xE6790304U
-#define                                DBSC_E3_DBTR2              0xE6790308U
-#define                                DBSC_E3_DBTR3              0xE679030CU
-#define                                DBSC_E3_DBTR4              0xE6790310U
-#define                                DBSC_E3_DBTR5              0xE6790314U
-#define                                DBSC_E3_DBTR6              0xE6790318U
-#define                                DBSC_E3_DBTR7              0xE679031CU
-#define                                DBSC_E3_DBTR8              0xE6790320U
-#define                                DBSC_E3_DBTR9              0xE6790324U
-#define                                DBSC_E3_DBTR10             0xE6790328U
-#define                                DBSC_E3_DBTR11             0xE679032CU
-#define                                DBSC_E3_DBTR12             0xE6790330U
-#define                                DBSC_E3_DBTR13             0xE6790334U
-#define                                DBSC_E3_DBTR14             0xE6790338U
-#define                                DBSC_E3_DBTR15             0xE679033CU
-#define                                DBSC_E3_DBTR16             0xE6790340U
-#define                                DBSC_E3_DBTR17             0xE6790344U
-#define                                DBSC_E3_DBTR18             0xE6790348U
-#define                                DBSC_E3_DBTR19             0xE679034CU
-#define                                DBSC_E3_DBTR20             0xE6790350U
-#define                                DBSC_E3_DBTR21             0xE6790354U
-#define                                DBSC_E3_DBBL               0xE6790400U
-#define                                DBSC_E3_DBRFCNF1           0xE6790414U
-#define                                DBSC_E3_DBRFCNF2           0xE6790418U
-#define                                DBSC_E3_DBCALCNF           0xE6790424U
-#define                                DBSC_E3_DBODT0             0xE6790460U
-#define                                DBSC_E3_DBADJ0             0xE6790500U
-#define                                DBSC_E3_DBDFICUPDCNF       0xE679052CU
-#define                                DBSC_E3_DBDFICNT0          0xE6790604U
-#define                                DBSC_E3_DBPDLK0            0xE6790620U
-#define                                DBSC_E3_DBPDRGA0           0xE6790624U
-#define                                DBSC_E3_DBPDRGD0           0xE6790628U
-#define                                DBSC_E3_DBBUS0CNF1         0xE6790804U
-#define                                DBSC_E3_DBCAM0CNF1         0xE6790904U
-#define                                DBSC_E3_DBCAM0CNF2         0xE6790908U
-#define                                DBSC_E3_DBCAM0STAT0        0xE6790980U
-#define                                DBSC_E3_DBBCAMDIS          0xE67909FCU
-#define                                DBSC_E3_DBSCHCNT0          0xE6791000U
-#define                                DBSC_E3_DBSCHSZ0           0xE6791010U
-#define                                DBSC_E3_DBSCHRW0           0xE6791020U
-#define                                DBSC_E3_DBSCHRW1           0xE6791024U
-#define                                DBSC_E3_DBSCHQOS00         0xE6791030U
-#define                                DBSC_E3_DBSCHQOS01         0xE6791034U
-#define                                DBSC_E3_DBSCHQOS02         0xE6791038U
-#define                                DBSC_E3_DBSCHQOS03         0xE679103CU
-#define                                DBSC_E3_DBSCHQOS40         0xE6791070U
-#define                                DBSC_E3_DBSCHQOS41         0xE6791074U
-#define                                DBSC_E3_DBSCHQOS42         0xE6791078U
-#define                                DBSC_E3_DBSCHQOS43         0xE679107CU
-#define                                DBSC_E3_DBSCHQOS90         0xE67910C0U
-#define                                DBSC_E3_DBSCHQOS91         0xE67910C4U
-#define                                DBSC_E3_DBSCHQOS92         0xE67910C8U
-#define                                DBSC_E3_DBSCHQOS93         0xE67910CCU
-#define                                DBSC_E3_DBSCHQOS130        0xE6791100U
-#define                                DBSC_E3_DBSCHQOS131        0xE6791104U
-#define                                DBSC_E3_DBSCHQOS132        0xE6791108U
-#define                                DBSC_E3_DBSCHQOS133        0xE679110CU
-#define                                DBSC_E3_DBSCHQOS140        0xE6791110U
-#define                                DBSC_E3_DBSCHQOS141        0xE6791114U
-#define                                DBSC_E3_DBSCHQOS142        0xE6791118U
-#define                                DBSC_E3_DBSCHQOS143        0xE679111CU
-#define                                DBSC_E3_DBSCHQOS150        0xE6791120U
-#define                                DBSC_E3_DBSCHQOS151        0xE6791124U
-#define                                DBSC_E3_DBSCHQOS152        0xE6791128U
-#define                                DBSC_E3_DBSCHQOS153        0xE679112CU
-#define                                DBSC_E3_SCFCTST0           0xE6791700U
-#define                                DBSC_E3_SCFCTST1           0xE6791708U
-#define                                DBSC_E3_SCFCTST2           0xE679170CU
-
-/* CPG registers */
-
-#define                                CPG_SRCR4                  0xE61500BCU
-#define                                CPG_PLLECR                 0xE61500D0U
-#define                                CPG_CPGWPR                 0xE6150900U
-#define                                CPG_CPGWPCR                0xE6150904U
-#define                                CPG_SRSTCLR4               0xE6150950U
-
-/* MODE Monitor registers */
-
-#define                                RST_MODEMR                 0xE6160060U
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* BOOT_INIT_DRAM_REGDEF_E3_H */
diff --git a/drivers/staging/renesas/rcar/ddr/ddr_a/boot_init_dram_regdef_v3m.h b/drivers/staging/renesas/rcar/ddr/ddr_a/boot_init_dram_regdef_v3m.h
deleted file mode 100644 (file)
index ecb8e62..0000000
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * Copyright (c) 2015-2016, Renesas Electronics Corporation
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef BOOT_INIT_DRAM_REGDEF_V3M_H_
-#define BOOT_INIT_DRAM_REGDEF_V3M_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-#define BIT0                           0x00000001U
-#define BIT30                          0x40000000U
-
-/* DBSC registers */
-
-// modified , last 2016.12.08
-
-#define DBSC_V3M_DBSYSCONF0            0xE6790000U
-#define DBSC_V3M_DBSYSCONF1            0xE6790004U
-#define DBSC_V3M_DBPHYCONF0            0xE6790010U
-#define DBSC_V3M_DBKIND                        0xE6790020U
-#define DBSC_V3M_DBMEMCONF00           0xE6790030U
-#define DBSC_V3M_DBMEMCONF01           0xE6790034U
-#define DBSC_V3M_DBMEMCONF02           0xE6790038U
-#define DBSC_V3M_DBMEMCONF03           0xE679003CU
-#define DBSC_V3M_DBMEMCONF10           0xE6790040U
-#define DBSC_V3M_DBMEMCONF11           0xE6790044U
-#define DBSC_V3M_DBMEMCONF12           0xE6790048U
-#define DBSC_V3M_DBMEMCONF13           0xE679004CU
-#define DBSC_V3M_DBMEMCONF20           0xE6790050U
-#define DBSC_V3M_DBMEMCONF21           0xE6790054U
-#define DBSC_V3M_DBMEMCONF22           0xE6790058U
-#define DBSC_V3M_DBMEMCONF23           0xE679005CU
-#define DBSC_V3M_DBMEMCONF30           0xE6790060U
-#define DBSC_V3M_DBMEMCONF31           0xE6790064U
-#define DBSC_V3M_DBMEMCONF32           0xE6790068U
-#define DBSC_V3M_DBMEMCONF33           0xE679006CU
-#define DBSC_V3M_DBSYSCNT0             0xE6790100U
-#define DBSC_V3M_DBSVCR1               0xE6790104U
-#define DBSC_V3M_DBSTATE0              0xE6790108U
-#define DBSC_V3M_DBSTATE1              0xE679010CU
-#define DBSC_V3M_DBINTEN               0xE6790180U
-#define DBSC_V3M_DBINTSTAT0            0xE6790184U
-#define DBSC_V3M_DBACEN                        0xE6790200U
-#define DBSC_V3M_DBRFEN                        0xE6790204U
-#define DBSC_V3M_DBCMD                 0xE6790208U
-#define DBSC_V3M_DBWAIT                        0xE6790210U
-#define DBSC_V3M_DBSYSCTRL0            0xE6790280U
-#define DBSC_V3M_DBTR0                 0xE6790300U
-#define DBSC_V3M_DBTR1                 0xE6790304U
-#define DBSC_V3M_DBTR2                 0xE6790308U
-#define DBSC_V3M_DBTR3                 0xE679030CU
-#define DBSC_V3M_DBTR4                 0xE6790310U
-#define DBSC_V3M_DBTR5                 0xE6790314U
-#define DBSC_V3M_DBTR6                 0xE6790318U
-#define DBSC_V3M_DBTR7                 0xE679031CU
-#define DBSC_V3M_DBTR8                 0xE6790320U
-#define DBSC_V3M_DBTR9                 0xE6790324U
-#define DBSC_V3M_DBTR10                        0xE6790328U
-#define DBSC_V3M_DBTR11                        0xE679032CU
-#define DBSC_V3M_DBTR12                        0xE6790330U
-#define DBSC_V3M_DBTR13                        0xE6790334U
-#define DBSC_V3M_DBTR14                        0xE6790338U
-#define DBSC_V3M_DBTR15                        0xE679033CU
-#define DBSC_V3M_DBTR16                        0xE6790340U
-#define DBSC_V3M_DBTR17                        0xE6790344U
-#define DBSC_V3M_DBTR18                        0xE6790348U
-#define DBSC_V3M_DBTR19                        0xE679034CU
-#define DBSC_V3M_DBTR20                        0xE6790350U
-#define DBSC_V3M_DBTR21                        0xE6790354U
-#define DBSC_V3M_DBTR22                        0xE6790358U
-#define DBSC_V3M_DBTR23                        0xE679035CU
-#define DBSC_V3M_DBTR24                        0xE6790360U
-#define DBSC_V3M_DBTR25                        0xE6790364U
-#define DBSC_V3M_DBBL                  0xE6790400U
-#define DBSC_V3M_DBRFCNF1              0xE6790414U
-#define DBSC_V3M_DBRFCNF2              0xE6790418U
-#define DBSC_V3M_DBTSPCNF              0xE6790420U
-#define DBSC_V3M_DBCALCNF              0xE6790424U
-#define DBSC_V3M_DBRNK2                        0xE6790438U
-#define DBSC_V3M_DBRNK3                        0xE679043CU
-#define DBSC_V3M_DBRNK4                        0xE6790440U
-#define DBSC_V3M_DBRNK5                        0xE6790444U
-#define DBSC_V3M_DBPDNCNF              0xE6790450U
-#define DBSC_V3M_DBODT0                        0xE6790460U
-#define DBSC_V3M_DBODT1                        0xE6790464U
-#define DBSC_V3M_DBODT2                        0xE6790468U
-#define DBSC_V3M_DBODT3                        0xE679046CU
-#define DBSC_V3M_DBODT4                        0xE6790470U
-#define DBSC_V3M_DBODT5                        0xE6790474U
-#define DBSC_V3M_DBODT6                        0xE6790478U
-#define DBSC_V3M_DBODT7                        0xE679047CU
-#define DBSC_V3M_DBADJ0                        0xE6790500U
-#define DBSC_V3M_DBDBICNT              0xE6790518U
-#define DBSC_V3M_DBDFIPMSTRCNF         0xE6790520U
-#define DBSC_V3M_DBDFIPMSTRSTAT                0xE6790524U
-#define DBSC_V3M_DBDFILPCNF            0xE6790528U
-#define DBSC_V3M_DBDFICUPDCNF          0xE679052CU
-#define DBSC_V3M_DBDFISTAT0            0xE6790600U
-#define DBSC_V3M_DBDFICNT0             0xE6790604U
-#define DBSC_V3M_DBPDCNT00             0xE6790610U
-#define DBSC_V3M_DBPDCNT01             0xE6790614U
-#define DBSC_V3M_DBPDCNT02             0xE6790618U
-#define DBSC_V3M_DBPDCNT03             0xE679061CU
-#define DBSC_V3M_DBPDLK0               0xE6790620U
-#define DBSC_V3M_DBPDRGA0              0xE6790624U
-#define DBSC_V3M_DBPDRGD0              0xE6790628U
-#define DBSC_V3M_DBPDSTAT00            0xE6790630U
-#define DBSC_V3M_DBDFISTAT1            0xE6790640U
-#define DBSC_V3M_DBDFICNT1             0xE6790644U
-#define DBSC_V3M_DBPDCNT10             0xE6790650U
-#define DBSC_V3M_DBPDCNT11             0xE6790654U
-#define DBSC_V3M_DBPDCNT12             0xE6790658U
-#define DBSC_V3M_DBPDCNT13             0xE679065CU
-#define DBSC_V3M_DBPDLK1               0xE6790660U
-#define DBSC_V3M_DBPDRGA1              0xE6790664U
-#define DBSC_V3M_DBPDRGD1              0xE6790668U
-#define DBSC_V3M_DBPDSTAT10            0xE6790670U
-#define DBSC_V3M_DBDFISTAT2            0xE6790680U
-#define DBSC_V3M_DBDFICNT2             0xE6790684U
-#define DBSC_V3M_DBPDCNT20             0xE6790690U
-#define DBSC_V3M_DBPDCNT21             0xE6790694U
-#define DBSC_V3M_DBPDCNT22             0xE6790698U
-#define DBSC_V3M_DBPDCNT23             0xE679069CU
-#define DBSC_V3M_DBPDLK2               0xE67906A0U
-#define DBSC_V3M_DBPDRGA2              0xE67906A4U
-#define DBSC_V3M_DBPDRGD2              0xE67906A8U
-#define DBSC_V3M_DBPDSTAT20            0xE67906B0U
-#define DBSC_V3M_DBDFISTAT3            0xE67906C0U
-#define DBSC_V3M_DBDFICNT3             0xE67906C4U
-#define DBSC_V3M_DBPDCNT30             0xE67906D0U
-#define DBSC_V3M_DBPDCNT31             0xE67906D4U
-#define DBSC_V3M_DBPDCNT32             0xE67906D8U
-#define DBSC_V3M_DBPDCNT33             0xE67906DCU
-#define DBSC_V3M_DBPDLK3               0xE67906E0U
-#define DBSC_V3M_DBPDRGA3              0xE67906E4U
-#define DBSC_V3M_DBPDRGD3              0xE67906E8U
-#define DBSC_V3M_DBPDSTAT30            0xE67906F0U
-#define DBSC_V3M_DBBUS0CNF0            0xE6790800U
-#define DBSC_V3M_DBBUS0CNF1            0xE6790804U
-#define DBSC_V3M_DBCAM0CNF1            0xE6790904U
-#define DBSC_V3M_DBCAM0CNF2            0xE6790908U
-#define DBSC_V3M_DBCAM0CNF3            0xE679090CU
-#define DBSC_V3M_DBCAM0CTRL0           0xE6790940U
-#define DBSC_V3M_DBCAM0STAT0           0xE6790980U
-#define DBSC_V3M_DBCAM1STAT0           0xE6790990U
-#define DBSC_V3M_DBBCAMSWAP            0xE67909F0U
-#define DBSC_V3M_DBBCAMDIS             0xE67909FCU
-#define DBSC_V3M_DBSCHCNT0             0xE6791000U
-#define DBSC_V3M_DBSCHCNT1             0xE6791004U
-#define DBSC_V3M_DBSCHSZ0              0xE6791010U
-#define DBSC_V3M_DBSCHRW0              0xE6791020U
-#define DBSC_V3M_DBSCHRW1              0xE6791024U
-#define DBSC_V3M_DBSCHQOS00            0xE6791030U
-#define DBSC_V3M_DBSCHQOS01            0xE6791034U
-#define DBSC_V3M_DBSCHQOS02            0xE6791038U
-#define DBSC_V3M_DBSCHQOS03            0xE679103CU
-#define DBSC_V3M_DBSCHQOS10            0xE6791040U
-#define DBSC_V3M_DBSCHQOS11            0xE6791044U
-#define DBSC_V3M_DBSCHQOS12            0xE6791048U
-#define DBSC_V3M_DBSCHQOS13            0xE679104CU
-#define DBSC_V3M_DBSCHQOS20            0xE6791050U
-#define DBSC_V3M_DBSCHQOS21            0xE6791054U
-#define DBSC_V3M_DBSCHQOS22            0xE6791058U
-#define DBSC_V3M_DBSCHQOS23            0xE679105CU
-#define DBSC_V3M_DBSCHQOS30            0xE6791060U
-#define DBSC_V3M_DBSCHQOS31            0xE6791064U
-#define DBSC_V3M_DBSCHQOS32            0xE6791068U
-#define DBSC_V3M_DBSCHQOS33            0xE679106CU
-#define DBSC_V3M_DBSCHQOS40            0xE6791070U
-#define DBSC_V3M_DBSCHQOS41            0xE6791074U
-#define DBSC_V3M_DBSCHQOS42            0xE6791078U
-#define DBSC_V3M_DBSCHQOS43            0xE679107CU
-#define DBSC_V3M_DBSCHQOS50            0xE6791080U
-#define DBSC_V3M_DBSCHQOS51            0xE6791084U
-#define DBSC_V3M_DBSCHQOS52            0xE6791088U
-#define DBSC_V3M_DBSCHQOS53            0xE679108CU
-#define DBSC_V3M_DBSCHQOS60            0xE6791090U
-#define DBSC_V3M_DBSCHQOS61            0xE6791094U
-#define DBSC_V3M_DBSCHQOS62            0xE6791098U
-#define DBSC_V3M_DBSCHQOS63            0xE679109CU
-#define DBSC_V3M_DBSCHQOS70            0xE67910A0U
-#define DBSC_V3M_DBSCHQOS71            0xE67910A4U
-#define DBSC_V3M_DBSCHQOS72            0xE67910A8U
-#define DBSC_V3M_DBSCHQOS73            0xE67910ACU
-#define DBSC_V3M_DBSCHQOS80            0xE67910B0U
-#define DBSC_V3M_DBSCHQOS81            0xE67910B4U
-#define DBSC_V3M_DBSCHQOS82            0xE67910B8U
-#define DBSC_V3M_DBSCHQOS83            0xE67910BCU
-#define DBSC_V3M_DBSCHQOS90            0xE67910C0U
-#define DBSC_V3M_DBSCHQOS91            0xE67910C4U
-#define DBSC_V3M_DBSCHQOS92            0xE67910C8U
-#define DBSC_V3M_DBSCHQOS93            0xE67910CCU
-#define DBSC_V3M_DBSCHQOS100           0xE67910D0U
-#define DBSC_V3M_DBSCHQOS101           0xE67910D4U
-#define DBSC_V3M_DBSCHQOS102           0xE67910D8U
-#define DBSC_V3M_DBSCHQOS103           0xE67910DCU
-#define DBSC_V3M_DBSCHQOS110           0xE67910E0U
-#define DBSC_V3M_DBSCHQOS111           0xE67910E4U
-#define DBSC_V3M_DBSCHQOS112           0xE67910E8U
-#define DBSC_V3M_DBSCHQOS113           0xE67910ECU
-#define DBSC_V3M_DBSCHQOS120           0xE67910F0U
-#define DBSC_V3M_DBSCHQOS121           0xE67910F4U
-#define DBSC_V3M_DBSCHQOS122           0xE67910F8U
-#define DBSC_V3M_DBSCHQOS123           0xE67910FCU
-#define DBSC_V3M_DBSCHQOS130           0xE6791100U
-#define DBSC_V3M_DBSCHQOS131           0xE6791104U
-#define DBSC_V3M_DBSCHQOS132           0xE6791108U
-#define DBSC_V3M_DBSCHQOS133           0xE679110CU
-#define DBSC_V3M_DBSCHQOS140           0xE6791110U
-#define DBSC_V3M_DBSCHQOS141           0xE6791114U
-#define DBSC_V3M_DBSCHQOS142           0xE6791118U
-#define DBSC_V3M_DBSCHQOS143           0xE679111CU
-#define DBSC_V3M_DBSCHQOS150           0xE6791120U
-#define DBSC_V3M_DBSCHQOS151           0xE6791124U
-#define DBSC_V3M_DBSCHQOS152           0xE6791128U
-#define DBSC_V3M_DBSCHQOS153           0xE679112CU
-#define DBSC_V3M_SCFCTST0              0xE6791700U
-#define DBSC_V3M_SCFCTST1              0xE6791708U
-#define DBSC_V3M_SCFCTST2              0xE679170CU
-#define DBSC_V3M_DBMRRDR0              0xE6791800U
-#define DBSC_V3M_DBMRRDR1              0xE6791804U
-#define DBSC_V3M_DBMRRDR2              0xE6791808U
-#define DBSC_V3M_DBMRRDR3              0xE679180CU
-#define DBSC_V3M_DBMRRDR4              0xE6791810U
-#define DBSC_V3M_DBMRRDR5              0xE6791814U
-#define DBSC_V3M_DBMRRDR6              0xE6791818U
-#define DBSC_V3M_DBMRRDR7              0xE679181CU
-#define DBSC_V3M_DBDTMP0               0xE6791820U
-#define DBSC_V3M_DBDTMP1               0xE6791824U
-#define DBSC_V3M_DBDTMP2               0xE6791828U
-#define DBSC_V3M_DBDTMP3               0xE679182CU
-#define DBSC_V3M_DBDTMP4               0xE6791830U
-#define DBSC_V3M_DBDTMP5               0xE6791834U
-#define DBSC_V3M_DBDTMP6               0xE6791838U
-#define DBSC_V3M_DBDTMP7               0xE679183CU
-#define DBSC_V3M_DBDQSOSC00            0xE6791840U
-#define DBSC_V3M_DBDQSOSC01            0xE6791844U
-#define DBSC_V3M_DBDQSOSC10            0xE6791848U
-#define DBSC_V3M_DBDQSOSC11            0xE679184CU
-#define DBSC_V3M_DBDQSOSC20            0xE6791850U
-#define DBSC_V3M_DBDQSOSC21            0xE6791854U
-#define DBSC_V3M_DBDQSOSC30            0xE6791858U
-#define DBSC_V3M_DBDQSOSC31            0xE679185CU
-#define DBSC_V3M_DBDQSOSC40            0xE6791860U
-#define DBSC_V3M_DBDQSOSC41            0xE6791864U
-#define DBSC_V3M_DBDQSOSC50            0xE6791868U
-#define DBSC_V3M_DBDQSOSC51            0xE679186CU
-#define DBSC_V3M_DBDQSOSC60            0xE6791870U
-#define DBSC_V3M_DBDQSOSC61            0xE6791874U
-#define DBSC_V3M_DBDQSOSC70            0xE6791878U
-#define DBSC_V3M_DBDQSOSC71            0xE679187CU
-#define DBSC_V3M_DBOSCTHH00            0xE6791880U
-#define DBSC_V3M_DBOSCTHH01            0xE6791884U
-#define DBSC_V3M_DBOSCTHH10            0xE6791888U
-#define DBSC_V3M_DBOSCTHH11            0xE679188CU
-#define DBSC_V3M_DBOSCTHH20            0xE6791890U
-#define DBSC_V3M_DBOSCTHH21            0xE6791894U
-#define DBSC_V3M_DBOSCTHH30            0xE6791898U
-#define DBSC_V3M_DBOSCTHH31            0xE679189CU
-#define DBSC_V3M_DBOSCTHH40            0xE67918A0U
-#define DBSC_V3M_DBOSCTHH41            0xE67918A4U
-#define DBSC_V3M_DBOSCTHH50            0xE67918A8U
-#define DBSC_V3M_DBOSCTHH51            0xE67918ACU
-#define DBSC_V3M_DBOSCTHH60            0xE67918B0U
-#define DBSC_V3M_DBOSCTHH61            0xE67918B4U
-#define DBSC_V3M_DBOSCTHH70            0xE67918B8U
-#define DBSC_V3M_DBOSCTHH71            0xE67918BCU
-#define DBSC_V3M_DBOSCTHL00            0xE67918C0U
-#define DBSC_V3M_DBOSCTHL01            0xE67918C4U
-#define DBSC_V3M_DBOSCTHL10            0xE67918C8U
-#define DBSC_V3M_DBOSCTHL11            0xE67918CCU
-#define DBSC_V3M_DBOSCTHL20            0xE67918D0U
-#define DBSC_V3M_DBOSCTHL21            0xE67918D4U
-#define DBSC_V3M_DBOSCTHL30            0xE67918D8U
-#define DBSC_V3M_DBOSCTHL31            0xE67918DCU
-#define DBSC_V3M_DBOSCTHL40            0xE67918E0U
-#define DBSC_V3M_DBOSCTHL41            0xE67918E4U
-#define DBSC_V3M_DBOSCTHL50            0xE67918E8U
-#define DBSC_V3M_DBOSCTHL51            0xE67918ECU
-#define DBSC_V3M_DBOSCTHL60            0xE67918F0U
-#define DBSC_V3M_DBOSCTHL61            0xE67918F4U
-#define DBSC_V3M_DBOSCTHL70            0xE67918F8U
-#define DBSC_V3M_DBOSCTHL71            0xE67918FCU
-#define DBSC_V3M_DBMEMSWAPCONF0                0xE6792000U
-
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* BOOT_INIT_DRAM_REGDEF_V3M_H_*/
index 9a9d06aebedbe16b06ffcc4f4a913a3dba30e935..d03b1b965a10488a76bdafac00d731a194599ad1 100644 (file)
@@ -1,5 +1,6 @@
 /*
- * Copyright (c) 2015-2017, Renesas Electronics Corporation. All rights reserved.
+ * Copyright (c) 2015-2019, Renesas Electronics Corporation.
+ * All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
 #include <lib/mmio.h>
 #include <common/debug.h>
 
-#include "boot_init_dram_regdef_d3.h"
+#include "boot_init_dram_regdef.h"
 
-#define RCAR_DDR_VERSION    "rev.0.01"
+#define RCAR_DDR_VERSION       "rev.0.01"
 
 #if RCAR_LSI != RCAR_D3
 #error "Don't have DDR initialize routine."
 #endif
 
-static void    WriteReg_32(uint32_t a, uint32_t v)
+static void init_ddr_d3_1866(void)
 {
-       (*(volatile uint32_t*)(uintptr_t)a) = v;
-}
+       uint32_t i, r2, r3, r5, r6, r7, r12;
+
+       mmio_write_32(DBSC_DBSYSCNT0, 0x00001234);
+       mmio_write_32(DBSC_DBKIND, 0x00000007);
+       mmio_write_32(DBSC_DBMEMCONF00, 0x0f030a01);
+       mmio_write_32(DBSC_DBPHYCONF0, 0x00000001);
+       mmio_write_32(DBSC_DBTR0, 0x0000000D);
+       mmio_write_32(DBSC_DBTR1, 0x00000009);
+       mmio_write_32(DBSC_DBTR2, 0x00000000);
+       mmio_write_32(DBSC_DBTR3, 0x0000000D);
+       mmio_write_32(DBSC_DBTR4, 0x000D000D);
+       mmio_write_32(DBSC_DBTR5, 0x0000002D);
+       mmio_write_32(DBSC_DBTR6, 0x00000020);
+       mmio_write_32(DBSC_DBTR7, 0x00060006);
+       mmio_write_32(DBSC_DBTR8, 0x00000021);
+       mmio_write_32(DBSC_DBTR9, 0x00000007);
+       mmio_write_32(DBSC_DBTR10, 0x0000000E);
+       mmio_write_32(DBSC_DBTR11, 0x0000000C);
+       mmio_write_32(DBSC_DBTR12, 0x00140014);
+       mmio_write_32(DBSC_DBTR13, 0x000000F2);
+       mmio_write_32(DBSC_DBTR14, 0x00170006);
+       mmio_write_32(DBSC_DBTR15, 0x00060005);
+       mmio_write_32(DBSC_DBTR16, 0x09210507);
+       mmio_write_32(DBSC_DBTR17, 0x040E0000);
+       mmio_write_32(DBSC_DBTR18, 0x00000200);
+       mmio_write_32(DBSC_DBTR19, 0x012B004B);
+       mmio_write_32(DBSC_DBTR20, 0x020000FB);
+       mmio_write_32(DBSC_DBTR21, 0x00040004);
+       mmio_write_32(DBSC_DBBL, 0x00000000);
+       mmio_write_32(DBSC_DBODT0, 0x00000001);
+       mmio_write_32(DBSC_DBADJ0, 0x00000001);
+       mmio_write_32(DBSC_DBSYSCONF1, 0x00000002);
+       mmio_write_32(DBSC_DBDFICNT0, 0x00000010);
+       mmio_write_32(DBSC_DBBCAMDIS, 0x00000001);
+       mmio_write_32(DBSC_DBSCHRW1, 0x00000046);
+       mmio_write_32(DBSC_SCFCTST0, 0x0D020D04);
+       mmio_write_32(DBSC_SCFCTST1, 0x0306040C);
+
+       mmio_write_32(DBSC_DBPDLK0, 0x0000A55A);
+       mmio_write_32(DBSC_DBCMD, 0x01000001);
+       mmio_write_32(DBSC_DBCMD, 0x08000000);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x80010000);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000008);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000B8000);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);
+       mmio_write_32(DBSC_DBPDRGD0, 0x04058A04);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000091);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0007BB6B);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000095);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0007BBAD);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000099);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0007BB6B);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);
+       mmio_write_32(DBSC_DBPDRGD0, 0x04058A00);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000021);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0024641E);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010073);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0C058A00);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);
+       mmio_write_32(DBSC_DBPDRGD0, 0x04058A00);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000003);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0780C700);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000007);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(30)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000004);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0A206F89);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000022);
+       mmio_write_32(DBSC_DBPDRGD0, 0x1000040B);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000023);
+       mmio_write_32(DBSC_DBPDRGD0, 0x35A00D77);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000024);
+       mmio_write_32(DBSC_DBPDRGD0, 0x2A8A2C28);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000025);
+       mmio_write_32(DBSC_DBPDRGD0, 0x30005E00);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000026);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0014CB49);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000027);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00000F14);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000028);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00000046);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000029);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000000A0);
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000002C);
+       mmio_write_32(DBSC_DBPDRGD0, 0x81003047);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000020);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00181884);
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000001A);
+       mmio_write_32(DBSC_DBPDRGD0, 0x33C03C10);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A7);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A8);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A9);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C7);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C8);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C9);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000D0D0D);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000000E);
+       r2 = (mmio_read_32(DBSC_DBPDRGD0) & 0x0000FF00) >> 0x9;
+       r3 = (r2 << 16) + (r2 << 8) + r2;
+       r6 = (r2 << 24) + (r2 << 16) + (r2 << 8) + r2;
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000011);
+       mmio_write_32(DBSC_DBPDRGD0, r3);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000012);
+       mmio_write_32(DBSC_DBPDRGD0, r3);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000016);
+       mmio_write_32(DBSC_DBPDRGD0, r6);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000017);
+       mmio_write_32(DBSC_DBPDRGD0, r6);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000018);
+       mmio_write_32(DBSC_DBPDRGD0, r6);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000019);
+       mmio_write_32(DBSC_DBPDRGD0, r6);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010181);
+       mmio_write_32(DBSC_DBCMD, 0x08000001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010601);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       for (i = 0; i < 2; i++) {
+               mmio_write_32(DBSC_DBPDRGA0, 0xB1 + i * 0x20);
+               r5 = (mmio_read_32(DBSC_DBPDRGD0) & 0xFF00) >> 0x8;
+               mmio_write_32(DBSC_DBPDRGA0, 0xB4 + i * 0x20);
+               r6 = mmio_read_32(DBSC_DBPDRGD0) & 0xFF;
+               mmio_write_32(DBSC_DBPDRGA0, 0xB3 + i * 0x20);
+               r7 = mmio_read_32(DBSC_DBPDRGD0) & 0x7;
+
+               if (r6 > 0) {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8;
+
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | ((r7 + 0x1) & 0x7));
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | r6);
+               } else {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | r7);
+
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 |
+                                                    ((r6 + (r5 << 1)) & 0xFF));
+               }
+       }
 
-static uint32_t ReadReg_32(uint32_t a)
-{
-       uint32_t w = (*(volatile uint32_t*)(uintptr_t)a);
-       return w;
-}
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000005);
+       mmio_write_32(DBSC_DBPDRGD0, 0xC1AA00C0);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010801);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000005);
+       mmio_write_32(DBSC_DBPDRGD0, 0xC1AA00D8);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0001F001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000AF);
+       r2 = mmio_read_32(DBSC_DBPDRGD0);
+       mmio_write_32(DBSC_DBPDRGD0, ((r2 + 0x1) & 0xFF) | (r2 & 0xFFFFFF00));
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000CF);
+       r2 = mmio_read_32(DBSC_DBPDRGD0);
+       mmio_write_32(DBSC_DBPDRGD0, ((r2 + 0x1) & 0xFF) | (r2 & 0xFFFFFF00));
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000002C);
+       mmio_write_32(DBSC_DBPDRGD0, 0x81003087);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010401);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       for (i = 0; i < 2; i++) {
+               mmio_write_32(DBSC_DBPDRGA0, 0xB1 + i * 0x20);
+               r5 = ((mmio_read_32(DBSC_DBPDRGD0) & 0xFF00) >> 0x8);
+               mmio_write_32(DBSC_DBPDRGA0, 0xB4 + i * 0x20);
+               r6 = mmio_read_32(DBSC_DBPDRGD0) & 0xFF;
+
+               mmio_write_32(DBSC_DBPDRGA0, 0xB3 + i * 0x20);
+               r7 = mmio_read_32(DBSC_DBPDRGD0) & 0x7;
+               r12 = (r5 >> 0x2);
+
+               if (r12 < r6) {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8;
+
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | ((r7 + 0x1) & 0x7));
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00;
+
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | ((r6 - r12) & 0xFF));
+               } else {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | (r7 & 0x7));
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 |
+                                                    ((r6 + r5 +
+                                                     (r5 >> 1) + r12) & 0xFF));
+               }
+       }
 
-static void init_ddr_d3_1866(void)
-{
-       uint32_t RegVal_R2, RegVal_R3, RegVal_R5, RegVal_R6, RegVal_R7, RegVal_R12;
-
-   WriteReg_32(DBSC_D3_DBSYSCNT0,0x00001234);
-   WriteReg_32(DBSC_D3_DBKIND,0x00000007);
-   WriteReg_32(DBSC_D3_DBMEMCONF00,0x0f030a01);
-   WriteReg_32(DBSC_D3_DBPHYCONF0,0x00000001);
-   WriteReg_32(DBSC_D3_DBTR0,0x0000000D);
-   WriteReg_32(DBSC_D3_DBTR1,0x00000009);
-   WriteReg_32(DBSC_D3_DBTR2,0x00000000);
-   WriteReg_32(DBSC_D3_DBTR3,0x0000000D);
-   WriteReg_32(DBSC_D3_DBTR4,0x000D000D);
-   WriteReg_32(DBSC_D3_DBTR5,0x0000002D);
-   WriteReg_32(DBSC_D3_DBTR6,0x00000020);
-   WriteReg_32(DBSC_D3_DBTR7,0x00060006);
-   WriteReg_32(DBSC_D3_DBTR8,0x00000021);
-   WriteReg_32(DBSC_D3_DBTR9,0x00000007);
-   WriteReg_32(DBSC_D3_DBTR10,0x0000000E);
-   WriteReg_32(DBSC_D3_DBTR11,0x0000000C);
-   WriteReg_32(DBSC_D3_DBTR12,0x00140014);
-   WriteReg_32(DBSC_D3_DBTR13,0x000000F2);
-   WriteReg_32(DBSC_D3_DBTR14,0x00170006);
-   WriteReg_32(DBSC_D3_DBTR15,0x00060005);
-   WriteReg_32(DBSC_D3_DBTR16,0x09210507);
-   WriteReg_32(DBSC_D3_DBTR17,0x040E0000);
-   WriteReg_32(DBSC_D3_DBTR18,0x00000200);
-   WriteReg_32(DBSC_D3_DBTR19,0x012B004B);
-   WriteReg_32(DBSC_D3_DBTR20,0x020000FB);
-   WriteReg_32(DBSC_D3_DBTR21,0x00040004);
-   WriteReg_32(DBSC_D3_DBBL,0x00000000);
-   WriteReg_32(DBSC_D3_DBODT0,0x00000001);
-   WriteReg_32(DBSC_D3_DBADJ0,0x00000001);
-   WriteReg_32(DBSC_D3_DBSYSCONF1,0x00000002);
-   WriteReg_32(DBSC_D3_DBDFICNT0,0x00000010);
-   WriteReg_32(DBSC_D3_DBBCAMDIS,0x00000001);
-   WriteReg_32(DBSC_D3_DBSCHRW1,0x00000046);
-   WriteReg_32(DBSC_D3_SCFCTST0,0x0D020D04);
-   WriteReg_32(DBSC_D3_SCFCTST1,0x0306040C);
-
-   WriteReg_32(DBSC_D3_DBPDLK0,0x0000A55A);
-   WriteReg_32(DBSC_D3_DBCMD,0x01000001);
-   WriteReg_32(DBSC_D3_DBCMD,0x08000000);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000001);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x80010000);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000008);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x000B8000);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000090);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x04058A04);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000091);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0007BB6B);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000095);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0007BBAD);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000099);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0007BB6B);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000090);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x04058A00);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000021);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0024641E);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000001);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x00010073);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000090);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0C058A00);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000090);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x04058A00);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000003);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0780C700);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000007);
-   while ( (BIT30 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000004);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0A206F89);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000022);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x1000040B);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000023);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x35A00D77);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000024);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x2A8A2C28);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000025);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x30005E00);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000026);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0014CB49);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000027);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x00000F14);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000028);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x00000046);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000029);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x000000A0);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x0000002C);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x81003047);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000020);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x00181884);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x0000001A);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x33C03C10);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000A7);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0D0D0D0D);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000A8);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0D0D0D0D);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000A9);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x000D0D0D);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000C7);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0D0D0D0D);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000C8);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0D0D0D0D);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000C9);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x000D0D0D);
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x0000000E);
-   RegVal_R2 = ((ReadReg_32(DBSC_D3_DBPDRGD0) & 0x0000FF00) >> 0x8) >> 0x1;
-   RegVal_R3 = (RegVal_R2 << 16) + (RegVal_R2 << 8) + RegVal_R2;
-   RegVal_R6 = (RegVal_R2 << 24) + (RegVal_R2 << 16) + (RegVal_R2 << 8) + RegVal_R2;
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000011);
-   WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R3);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000012);
-   WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R3);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000016);
-   WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R6);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000017);
-   WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R6);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000018);
-   WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R6);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000019);
-   WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R6);
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000001);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x00010181);
-   WriteReg_32(DBSC_D3_DBCMD,0x08000001);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000001);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x00010601);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   for (uint32_t i = 0; i<2; i++)
-   {
-      WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B1 + i*0x20);
-      RegVal_R5 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0x0000FF00) >> 0x8;
-      WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B4 + i*0x20);
-      RegVal_R6 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0x000000FF);
-      WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B3 + i*0x20);
-      RegVal_R7 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0x00000007);
-      if ( RegVal_R6 > 0 )
-      {
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B2 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0xFFFFFFF8);
-
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B2 + i*0x20);
-         WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R2 | ((RegVal_R7 + 0x1) & 0x00000007));
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B0 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0xFFFFFF00);
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B0 + i*0x20);
-         WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R2 | RegVal_R6);
-      } else
-      {
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B2 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0xFFFFFFF8);
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B2 + i*0x20);
-         WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R2 | RegVal_R7);
-
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B0 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0xFFFFFF00);
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B0 + i*0x20);
-         WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R2 | ((RegVal_R6 + ((RegVal_R5) << 1)) & 0x000000FF));
-      }
-   }
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000005);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0xC1AA00C0);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000A0);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x7C0002C5);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000C0);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x7C0002C5);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000001);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x00010801);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000005);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0xC1AA00D8);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000001);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0001F001);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000AF);
-   RegVal_R2 = ReadReg_32(DBSC_D3_DBPDRGD0);
-   WriteReg_32(DBSC_D3_DBPDRGD0,(((RegVal_R2 + 0x1) & 0x000000FF) | (RegVal_R2 & 0xFFFFFF00)));
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000CF);
-   RegVal_R2 = ReadReg_32(DBSC_D3_DBPDRGD0);
-   WriteReg_32(DBSC_D3_DBPDRGD0,(((RegVal_R2 + 0x1) & 0x000000FF) | (RegVal_R2 & 0xFFFFFF00)));
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000A0);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x7C000285);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000C0);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x7C000285);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x0000002C);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x81003087);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000001);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x00010401);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   for (uint32_t i = 0; i < 2; i++)
-   {
-      WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B1 + i*0x20);
-      RegVal_R5 = ((ReadReg_32(DBSC_D3_DBPDRGD0) & 0x0000FF00) >> 0x8);
-      WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B4 + i*0x20);
-      RegVal_R6 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0x000000FF);
-
-      WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B3 + i*0x20);
-      RegVal_R7 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0x00000007);
-      RegVal_R12 = (RegVal_R5 >> 0x2);
-      if ( RegVal_R12 < RegVal_R6 )
-      {
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B2 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0xFFFFFFF8);
-
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B2 + i*0x20);
-         WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R2 | ((RegVal_R7 + 0x1) & 0x00000007));
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B0 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0xFFFFFF00);
-
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B0 + i*0x20);
-         WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R2 | ((RegVal_R6 - (RegVal_R12)) & 0x000000FF));
-      }
-      else
-      {
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B2 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0xFFFFFFF8);
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B2 + i*0x20);
-         WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R2 | (RegVal_R7 & 0x00000007));
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B0 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0xFFFFFF00);
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B0 + i*0x20);
-         WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R2 | ((RegVal_R6 + (RegVal_R5) + ((RegVal_R5) >> 1) + (RegVal_R12)) & 0x000000FF));
-      }
-   }
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000A0);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x7C0002C5);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000C0);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x7C0002C5);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000001);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x00015001);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000003);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0380C700);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000007);
-   while ( (BIT30 & ReadReg_32(DBSC_D3_DBPDRGD0)) != 0 );
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000021);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0024643E);
-
-   WriteReg_32(DBSC_D3_DBBUS0CNF1,0x00000010);
-   WriteReg_32(DBSC_D3_DBCALCNF,0x0100401B);
-   WriteReg_32(DBSC_D3_DBRFCNF1,0x00080E23);
-   WriteReg_32(DBSC_D3_DBRFCNF2,0x00010000);
-   WriteReg_32(DBSC_D3_DBDFICUPDCNF,0x40100001);
-   WriteReg_32(DBSC_D3_DBRFEN,0x00000001);
-   WriteReg_32(DBSC_D3_DBACEN,0x00000001);
-   WriteReg_32(DBSC_D3_DBPDLK0,0x00000000);
-   WriteReg_32(DBSC_D3_DBSYSCNT0,0x00000000);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00015001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000003);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0380C700);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000007);
+       while (mmio_read_32(DBSC_DBPDRGD0) & BIT(30))
+               ;
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000021);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0024643E);
+
+       mmio_write_32(DBSC_DBBUS0CNF1, 0x00000010);
+       mmio_write_32(DBSC_DBCALCNF, 0x0100401B);
+       mmio_write_32(DBSC_DBRFCNF1, 0x00080E23);
+       mmio_write_32(DBSC_DBRFCNF2, 0x00010000);
+       mmio_write_32(DBSC_DBDFICUPDCNF, 0x40100001);
+       mmio_write_32(DBSC_DBRFEN, 0x00000001);
+       mmio_write_32(DBSC_DBACEN, 0x00000001);
+       mmio_write_32(DBSC_DBPDLK0, 0x00000000);
+       mmio_write_32(DBSC_DBSYSCNT0, 0x00000000);
 
 #ifdef ddr_qos_init_setting // only for non qos_init
-   WriteReg_32(DBSC_D3_DBSYSCNT0,0x00001234);
-   WriteReg_32(DBSC_D3_DBCAM0CNF1,0x00043218);
-   WriteReg_32(DBSC_D3_DBCAM0CNF2,0x000000F4);
-   WriteReg_32(DBSC_D3_DBSCHCNT0,0x000f0037);
-   WriteReg_32(DBSC_D3_DBSCHSZ0,0x00000001);
-   WriteReg_32(DBSC_D3_DBSCHRW0,0x22421111);
-   WriteReg_32(DBSC_D3_SCFCTST2,0x012F1123);
-   WriteReg_32(DBSC_D3_DBSCHQOS00,0x00000F00);
-   WriteReg_32(DBSC_D3_DBSCHQOS01,0x00000B00);
-   WriteReg_32(DBSC_D3_DBSCHQOS02,0x00000000);
-   WriteReg_32(DBSC_D3_DBSCHQOS03,0x00000000);
-   WriteReg_32(DBSC_D3_DBSCHQOS40,0x00000300);
-   WriteReg_32(DBSC_D3_DBSCHQOS41,0x000002F0);
-   WriteReg_32(DBSC_D3_DBSCHQOS42,0x00000200);
-   WriteReg_32(DBSC_D3_DBSCHQOS43,0x00000100);
-   WriteReg_32(DBSC_D3_DBSCHQOS90,0x00000300);
-   WriteReg_32(DBSC_D3_DBSCHQOS91,0x000002F0);
-   WriteReg_32(DBSC_D3_DBSCHQOS92,0x00000200);
-   WriteReg_32(DBSC_D3_DBSCHQOS93,0x00000100);
-   WriteReg_32(DBSC_D3_DBSCHQOS130,0x00000100);
-   WriteReg_32(DBSC_D3_DBSCHQOS131,0x000000F0);
-   WriteReg_32(DBSC_D3_DBSCHQOS132,0x000000A0);
-   WriteReg_32(DBSC_D3_DBSCHQOS133,0x00000040);
-   WriteReg_32(DBSC_D3_DBSCHQOS140,0x000000C0);
-   WriteReg_32(DBSC_D3_DBSCHQOS141,0x000000B0);
-   WriteReg_32(DBSC_D3_DBSCHQOS142,0x00000080);
-   WriteReg_32(DBSC_D3_DBSCHQOS143,0x00000040);
-   WriteReg_32(DBSC_D3_DBSCHQOS150,0x00000040);
-   WriteReg_32(DBSC_D3_DBSCHQOS151,0x00000030);
-   WriteReg_32(DBSC_D3_DBSCHQOS152,0x00000020);
-   WriteReg_32(DBSC_D3_DBSCHQOS153,0x00000010);
-   WriteReg_32(0xE67F0018,0x00000001);
-   WriteReg_32(DBSC_D3_DBSYSCNT0,0x00000000);
+       mmio_write_32(DBSC_DBSYSCNT0, 0x00001234);
+       mmio_write_32(DBSC_DBCAM0CNF1, 0x00043218);
+       mmio_write_32(DBSC_DBCAM0CNF2, 0x000000F4);
+       mmio_write_32(DBSC_DBSCHCNT0, 0x000f0037);
+       mmio_write_32(DBSC_DBSCHSZ0, 0x00000001);
+       mmio_write_32(DBSC_DBSCHRW0, 0x22421111);
+       mmio_write_32(DBSC_SCFCTST2, 0x012F1123);
+       mmio_write_32(DBSC_DBSCHQOS00, 0x00000F00);
+       mmio_write_32(DBSC_DBSCHQOS01, 0x00000B00);
+       mmio_write_32(DBSC_DBSCHQOS02, 0x00000000);
+       mmio_write_32(DBSC_DBSCHQOS03, 0x00000000);
+       mmio_write_32(DBSC_DBSCHQOS40, 0x00000300);
+       mmio_write_32(DBSC_DBSCHQOS41, 0x000002F0);
+       mmio_write_32(DBSC_DBSCHQOS42, 0x00000200);
+       mmio_write_32(DBSC_DBSCHQOS43, 0x00000100);
+       mmio_write_32(DBSC_DBSCHQOS90, 0x00000300);
+       mmio_write_32(DBSC_DBSCHQOS91, 0x000002F0);
+       mmio_write_32(DBSC_DBSCHQOS92, 0x00000200);
+       mmio_write_32(DBSC_DBSCHQOS93, 0x00000100);
+       mmio_write_32(DBSC_DBSCHQOS130, 0x00000100);
+       mmio_write_32(DBSC_DBSCHQOS131, 0x000000F0);
+       mmio_write_32(DBSC_DBSCHQOS132, 0x000000A0);
+       mmio_write_32(DBSC_DBSCHQOS133, 0x00000040);
+       mmio_write_32(DBSC_DBSCHQOS140, 0x000000C0);
+       mmio_write_32(DBSC_DBSCHQOS141, 0x000000B0);
+       mmio_write_32(DBSC_DBSCHQOS142, 0x00000080);
+       mmio_write_32(DBSC_DBSCHQOS143, 0x00000040);
+       mmio_write_32(DBSC_DBSCHQOS150, 0x00000040);
+       mmio_write_32(DBSC_DBSCHQOS151, 0x00000030);
+       mmio_write_32(DBSC_DBSCHQOS152, 0x00000020);
+       mmio_write_32(DBSC_DBSCHQOS153, 0x00000010);
+       mmio_write_32(0xE67F0018, 0x00000001);
+       mmio_write_32(DBSC_DBSYSCNT0, 0x00000000);
 #endif
 }
 
 static void init_ddr_d3_1600(void)
 {
-       uint32_t RegVal_R2, RegVal_R3, RegVal_R5, RegVal_R6, RegVal_R7, RegVal_R12;
-
-   WriteReg_32(DBSC_D3_DBSYSCNT0,0x00001234);
-   WriteReg_32(DBSC_D3_DBKIND,0x00000007);
-   WriteReg_32(DBSC_D3_DBMEMCONF00,0x0f030a01);
-   WriteReg_32(DBSC_D3_DBPHYCONF0,0x00000001);
-   WriteReg_32(DBSC_D3_DBTR0,0x0000000B);
-   WriteReg_32(DBSC_D3_DBTR1,0x00000008);
-   WriteReg_32(DBSC_D3_DBTR2,0x00000000);
-   WriteReg_32(DBSC_D3_DBTR3,0x0000000B);
-   WriteReg_32(DBSC_D3_DBTR4,0x000B000B);
-   WriteReg_32(DBSC_D3_DBTR5,0x00000027);
-   WriteReg_32(DBSC_D3_DBTR6,0x0000001C);
-   WriteReg_32(DBSC_D3_DBTR7,0x00060006);
-   WriteReg_32(DBSC_D3_DBTR8,0x00000020);
-   WriteReg_32(DBSC_D3_DBTR9,0x00000006);
-   WriteReg_32(DBSC_D3_DBTR10,0x0000000C);
-   WriteReg_32(DBSC_D3_DBTR11,0x0000000A);
-   WriteReg_32(DBSC_D3_DBTR12,0x00120012);
-   WriteReg_32(DBSC_D3_DBTR13,0x000000D0);
-   WriteReg_32(DBSC_D3_DBTR14,0x00140005);
-   WriteReg_32(DBSC_D3_DBTR15,0x00050004);
-   WriteReg_32(DBSC_D3_DBTR16,0x071F0305);
-   WriteReg_32(DBSC_D3_DBTR17,0x040C0000);
-   WriteReg_32(DBSC_D3_DBTR18,0x00000200);
-   WriteReg_32(DBSC_D3_DBTR19,0x01000040);
-   WriteReg_32(DBSC_D3_DBTR20,0x020000D8);
-   WriteReg_32(DBSC_D3_DBTR21,0x00040004);
-   WriteReg_32(DBSC_D3_DBBL,0x00000000);
-   WriteReg_32(DBSC_D3_DBODT0,0x00000001);
-   WriteReg_32(DBSC_D3_DBADJ0,0x00000001);
-   WriteReg_32(DBSC_D3_DBSYSCONF1,0x00000002);
-   WriteReg_32(DBSC_D3_DBDFICNT0,0x00000010);
-   WriteReg_32(DBSC_D3_DBBCAMDIS,0x00000001);
-   WriteReg_32(DBSC_D3_DBSCHRW1,0x00000046);
-   WriteReg_32(DBSC_D3_SCFCTST0,0x0D020C04);
-   WriteReg_32(DBSC_D3_SCFCTST1,0x0305040C);
-
-   WriteReg_32(DBSC_D3_DBPDLK0,0x0000A55A);
-   WriteReg_32(DBSC_D3_DBCMD,0x01000001);
-   WriteReg_32(DBSC_D3_DBCMD,0x08000000);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000001);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x80010000);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000008);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x000B8000);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000090);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x04058904);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000091);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0007BB6B);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000095);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0007BBAD);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000099);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0007BB6B);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000090);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x04058900);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000021);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0024641E);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000001);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x00010073);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000090);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0C058900);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000090);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x04058900);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000003);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0780C700);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000007);
-   while ( (BIT30 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000004);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x08C05FF0);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000022);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x1000040B);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000023);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x2D9C0B66);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000024);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x2A88C400);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000025);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x30005200);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000026);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0014A9C9);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000027);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x00000D70);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000028);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x00000046);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000029);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x00000098);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x0000002C);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x81003047);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000020);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x00181884);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x0000001A);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x33C03C10);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000A7);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0D0D0D0D);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000A8);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0D0D0D0D);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000A9);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x000D0D0D);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000C7);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0D0D0D0D);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000C8);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0D0D0D0D);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000C9);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x000D0D0D);
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x0000000E);
-   RegVal_R2 = ((ReadReg_32(DBSC_D3_DBPDRGD0) & 0x0000FF00) >> 0x8) >> 0x1;
-   RegVal_R3 = (RegVal_R2 << 16) + (RegVal_R2 << 8) + RegVal_R2;
-   RegVal_R6 = (RegVal_R2 << 24) + (RegVal_R2 << 16) + (RegVal_R2 << 8) + RegVal_R2;
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000011);
-   WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R3);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000012);
-   WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R3);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000016);
-   WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R6);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000017);
-   WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R6);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000018);
-   WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R6);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000019);
-   WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R6);
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000001);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x00010181);
-   WriteReg_32(DBSC_D3_DBCMD,0x08000001);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000001);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x00010601);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   for (uint32_t i = 0; i<2; i++)
-   {
-      WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B1 + i*0x20);
-      RegVal_R5 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0x0000FF00) >> 0x8;
-      WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B4 + i*0x20);
-      RegVal_R6 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0x000000FF);
-      WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B3 + i*0x20);
-      RegVal_R7 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0x00000007);
-      if ( RegVal_R6 > 0 )
-      {
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B2 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0xFFFFFFF8);
-
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B2 + i*0x20);
-         WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R2 | ((RegVal_R7 + 0x1) & 0x00000007));
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B0 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0xFFFFFF00);
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B0 + i*0x20);
-         WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R2 | RegVal_R6);
-      } else
-      {
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B2 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0xFFFFFFF8);
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B2 + i*0x20);
-         WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R2 | RegVal_R7);
-
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B0 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0xFFFFFF00);
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B0 + i*0x20);
-         WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R2 | ((RegVal_R6 + ((RegVal_R5) << 1)) & 0x000000FF));
-      }
-   }
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000005);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0xC1AA00C0);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000A0);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x7C0002C5);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000C0);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x7C0002C5);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000001);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x00010801);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000005);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0xC1AA00D8);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000001);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0001F001);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000AF);
-   RegVal_R2 = ReadReg_32(DBSC_D3_DBPDRGD0);
-   WriteReg_32(DBSC_D3_DBPDRGD0,(((RegVal_R2 + 0x1) & 0x000000FF) | (RegVal_R2 & 0xFFFFFF00)));
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000CF);
-   RegVal_R2 = ReadReg_32(DBSC_D3_DBPDRGD0);
-   WriteReg_32(DBSC_D3_DBPDRGD0,(((RegVal_R2 + 0x1) & 0x000000FF) | (RegVal_R2 & 0xFFFFFF00)));
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000A0);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x7C000285);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000C0);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x7C000285);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x0000002C);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x81003087);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000001);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x00010401);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   for (uint32_t i = 0; i < 2; i++)
-   {
-      WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B1 + i*0x20);
-      RegVal_R5 = ((ReadReg_32(DBSC_D3_DBPDRGD0) & 0x0000FF00) >> 0x8);
-      WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B4 + i*0x20);
-      RegVal_R6 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0x000000FF);
-
-      WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B3 + i*0x20);
-      RegVal_R7 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0x00000007);
-      RegVal_R12 = (RegVal_R5 >> 0x2);
-      if ( RegVal_R12 < RegVal_R6 )
-      {
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B2 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0xFFFFFFF8);
-
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B2 + i*0x20);
-         WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R2 | ((RegVal_R7 + 0x1) & 0x00000007));
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B0 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0xFFFFFF00);
-
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B0 + i*0x20);
-         WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R2 | ((RegVal_R6 - (RegVal_R12)) & 0x000000FF));
-      }
-      else
-      {
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B2 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0xFFFFFFF8);
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B2 + i*0x20);
-         WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R2 | (RegVal_R7 & 0x00000007));
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B0 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_D3_DBPDRGD0) & 0xFFFFFF00);
-         WriteReg_32(DBSC_D3_DBPDRGA0,0x000000B0 + i*0x20);
-         WriteReg_32(DBSC_D3_DBPDRGD0,RegVal_R2 | ((RegVal_R6 + (RegVal_R5) + ((RegVal_R5) >> 1) + (RegVal_R12)) & 0x000000FF));
-      }
-   }
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000A0);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x7C0002C5);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x000000C0);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x7C0002C5);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000001);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x00015001);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_D3_DBPDRGD0)) == 0 );
-
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000003);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0380C700);
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000007);
-   while ( (BIT30 & ReadReg_32(DBSC_D3_DBPDRGD0)) != 0 );
-   WriteReg_32(DBSC_D3_DBPDRGA0,0x00000021);
-   WriteReg_32(DBSC_D3_DBPDRGD0,0x0024643E);
-
-   WriteReg_32(DBSC_D3_DBBUS0CNF1,0x00000010);
-   WriteReg_32(DBSC_D3_DBCALCNF,0x0100401B);
-   WriteReg_32(DBSC_D3_DBRFCNF1,0x00080C30);
-   WriteReg_32(DBSC_D3_DBRFCNF2,0x00010000);
-   WriteReg_32(DBSC_D3_DBDFICUPDCNF,0x40100001);
-   WriteReg_32(DBSC_D3_DBRFEN,0x00000001);
-   WriteReg_32(DBSC_D3_DBACEN,0x00000001);
-   WriteReg_32(DBSC_D3_DBPDLK0,0x00000000);
-   WriteReg_32(DBSC_D3_DBSYSCNT0,0x00000000);
+       uint32_t i, r2, r3, r5, r6, r7, r12;
+
+       mmio_write_32(DBSC_DBSYSCNT0, 0x00001234);
+       mmio_write_32(DBSC_DBKIND, 0x00000007);
+       mmio_write_32(DBSC_DBMEMCONF00, 0x0f030a01);
+       mmio_write_32(DBSC_DBPHYCONF0, 0x00000001);
+       mmio_write_32(DBSC_DBTR0, 0x0000000B);
+       mmio_write_32(DBSC_DBTR1, 0x00000008);
+       mmio_write_32(DBSC_DBTR2, 0x00000000);
+       mmio_write_32(DBSC_DBTR3, 0x0000000B);
+       mmio_write_32(DBSC_DBTR4, 0x000B000B);
+       mmio_write_32(DBSC_DBTR5, 0x00000027);
+       mmio_write_32(DBSC_DBTR6, 0x0000001C);
+       mmio_write_32(DBSC_DBTR7, 0x00060006);
+       mmio_write_32(DBSC_DBTR8, 0x00000020);
+       mmio_write_32(DBSC_DBTR9, 0x00000006);
+       mmio_write_32(DBSC_DBTR10, 0x0000000C);
+       mmio_write_32(DBSC_DBTR11, 0x0000000A);
+       mmio_write_32(DBSC_DBTR12, 0x00120012);
+       mmio_write_32(DBSC_DBTR13, 0x000000D0);
+       mmio_write_32(DBSC_DBTR14, 0x00140005);
+       mmio_write_32(DBSC_DBTR15, 0x00050004);
+       mmio_write_32(DBSC_DBTR16, 0x071F0305);
+       mmio_write_32(DBSC_DBTR17, 0x040C0000);
+       mmio_write_32(DBSC_DBTR18, 0x00000200);
+       mmio_write_32(DBSC_DBTR19, 0x01000040);
+       mmio_write_32(DBSC_DBTR20, 0x020000D8);
+       mmio_write_32(DBSC_DBTR21, 0x00040004);
+       mmio_write_32(DBSC_DBBL, 0x00000000);
+       mmio_write_32(DBSC_DBODT0, 0x00000001);
+       mmio_write_32(DBSC_DBADJ0, 0x00000001);
+       mmio_write_32(DBSC_DBSYSCONF1, 0x00000002);
+       mmio_write_32(DBSC_DBDFICNT0, 0x00000010);
+       mmio_write_32(DBSC_DBBCAMDIS, 0x00000001);
+       mmio_write_32(DBSC_DBSCHRW1, 0x00000046);
+       mmio_write_32(DBSC_SCFCTST0, 0x0D020C04);
+       mmio_write_32(DBSC_SCFCTST1, 0x0305040C);
+
+       mmio_write_32(DBSC_DBPDLK0, 0x0000A55A);
+       mmio_write_32(DBSC_DBCMD, 0x01000001);
+       mmio_write_32(DBSC_DBCMD, 0x08000000);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x80010000);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000008);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000B8000);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);
+       mmio_write_32(DBSC_DBPDRGD0, 0x04058904);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000091);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0007BB6B);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000095);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0007BBAD);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000099);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0007BB6B);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);
+       mmio_write_32(DBSC_DBPDRGD0, 0x04058900);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000021);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0024641E);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010073);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0C058900);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);
+       mmio_write_32(DBSC_DBPDRGD0, 0x04058900);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000003);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0780C700);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000007);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(30)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000004);
+       mmio_write_32(DBSC_DBPDRGD0, 0x08C05FF0);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000022);
+       mmio_write_32(DBSC_DBPDRGD0, 0x1000040B);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000023);
+       mmio_write_32(DBSC_DBPDRGD0, 0x2D9C0B66);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000024);
+       mmio_write_32(DBSC_DBPDRGD0, 0x2A88C400);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000025);
+       mmio_write_32(DBSC_DBPDRGD0, 0x30005200);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000026);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0014A9C9);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000027);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00000D70);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000028);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00000046);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000029);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00000098);
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000002C);
+       mmio_write_32(DBSC_DBPDRGD0, 0x81003047);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000020);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00181884);
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000001A);
+       mmio_write_32(DBSC_DBPDRGD0, 0x33C03C10);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A7);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A8);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A9);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C7);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C8);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C9);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000D0D0D);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000000E);
+       r2 = (mmio_read_32(DBSC_DBPDRGD0) & 0x0000FF00) >> 0x9;
+       r3 = (r2 << 16) + (r2 << 8) + r2;
+       r6 = (r2 << 24) + (r2 << 16) + (r2 << 8) + r2;
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000011);
+       mmio_write_32(DBSC_DBPDRGD0, r3);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000012);
+       mmio_write_32(DBSC_DBPDRGD0, r3);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000016);
+       mmio_write_32(DBSC_DBPDRGD0, r6);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000017);
+       mmio_write_32(DBSC_DBPDRGD0, r6);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000018);
+       mmio_write_32(DBSC_DBPDRGD0, r6);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000019);
+       mmio_write_32(DBSC_DBPDRGD0, r6);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010181);
+       mmio_write_32(DBSC_DBCMD, 0x08000001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010601);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       for (i = 0; i < 2; i++) {
+               mmio_write_32(DBSC_DBPDRGA0, 0xB1 + i * 0x20);
+               r5 = (mmio_read_32(DBSC_DBPDRGD0) & 0xFF00) >> 0x8;
+               mmio_write_32(DBSC_DBPDRGA0, 0xB4 + i * 0x20);
+               r6 = mmio_read_32(DBSC_DBPDRGD0) & 0xFF;
+               mmio_write_32(DBSC_DBPDRGA0, 0xB3 + i * 0x20);
+               r7 = mmio_read_32(DBSC_DBPDRGD0) & 0x7;
+               if (r6 > 0) {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8;
+
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | ((r7 + 0x1) & 0x7));
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | r6);
+               } else {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | r7);
+
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 |
+                                                    ((r6 + (r5 << 1)) & 0xFF));
+               }
+       }
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000005);
+       mmio_write_32(DBSC_DBPDRGD0, 0xC1AA00C0);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010801);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000005);
+       mmio_write_32(DBSC_DBPDRGD0, 0xC1AA00D8);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0001F001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000AF);
+       r2 = mmio_read_32(DBSC_DBPDRGD0);
+       mmio_write_32(DBSC_DBPDRGD0, ((r2 + 0x1) & 0xFF) | (r2 & 0xFFFFFF00));
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000CF);
+       r2 = mmio_read_32(DBSC_DBPDRGD0);
+       mmio_write_32(DBSC_DBPDRGD0, ((r2 + 0x1) & 0xFF) | (r2 & 0xFFFFFF00));
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000002C);
+       mmio_write_32(DBSC_DBPDRGD0, 0x81003087);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010401);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       for (i = 0; i < 2; i++) {
+               mmio_write_32(DBSC_DBPDRGA0, 0xB1 + i * 0x20);
+               r5 = (mmio_read_32(DBSC_DBPDRGD0) & 0xFF00) >> 0x8;
+               mmio_write_32(DBSC_DBPDRGA0, 0xB4 + i * 0x20);
+               r6 = mmio_read_32(DBSC_DBPDRGD0) & 0xFF;
+
+               mmio_write_32(DBSC_DBPDRGA0, 0xB3 + i * 0x20);
+               r7 = mmio_read_32(DBSC_DBPDRGD0) & 0x7;
+               r12 = (r5 >> 0x2);
+
+               if (r12 < r6) {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8;
+
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | ((r7 + 0x1) & 0x7));
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00;
+
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | ((r6 - r12) & 0xFF));
+               } else {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | (r7 & 0x7));
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 |
+                                                    ((r6 + r5 +
+                                                     (r5 >> 1) + r12) & 0xFF));
+               }
+       }
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00015001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000003);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0380C700);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000007);
+       while (mmio_read_32(DBSC_DBPDRGD0) & BIT(30))
+               ;
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000021);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0024643E);
+
+       mmio_write_32(DBSC_DBBUS0CNF1, 0x00000010);
+       mmio_write_32(DBSC_DBCALCNF, 0x0100401B);
+       mmio_write_32(DBSC_DBRFCNF1, 0x00080C30);
+       mmio_write_32(DBSC_DBRFCNF2, 0x00010000);
+       mmio_write_32(DBSC_DBDFICUPDCNF, 0x40100001);
+       mmio_write_32(DBSC_DBRFEN, 0x00000001);
+       mmio_write_32(DBSC_DBACEN, 0x00000001);
+       mmio_write_32(DBSC_DBPDLK0, 0x00000000);
+       mmio_write_32(DBSC_DBSYSCNT0, 0x00000000);
 
 #ifdef ddr_qos_init_setting // only for non qos_init
-   WriteReg_32(DBSC_D3_DBSYSCNT0,0x00001234);
-   WriteReg_32(DBSC_D3_DBCAM0CNF1,0x00043218);
-   WriteReg_32(DBSC_D3_DBCAM0CNF2,0x000000F4);
-   WriteReg_32(DBSC_D3_DBSCHCNT0,0x000f0037);
-   WriteReg_32(DBSC_D3_DBSCHSZ0,0x00000001);
-   WriteReg_32(DBSC_D3_DBSCHRW0,0x22421111);
-   WriteReg_32(DBSC_D3_SCFCTST2,0x012F1123);
-   WriteReg_32(DBSC_D3_DBSCHQOS00,0x00000F00);
-   WriteReg_32(DBSC_D3_DBSCHQOS01,0x00000B00);
-   WriteReg_32(DBSC_D3_DBSCHQOS02,0x00000000);
-   WriteReg_32(DBSC_D3_DBSCHQOS03,0x00000000);
-   WriteReg_32(DBSC_D3_DBSCHQOS40,0x00000300);
-   WriteReg_32(DBSC_D3_DBSCHQOS41,0x000002F0);
-   WriteReg_32(DBSC_D3_DBSCHQOS42,0x00000200);
-   WriteReg_32(DBSC_D3_DBSCHQOS43,0x00000100);
-   WriteReg_32(DBSC_D3_DBSCHQOS90,0x00000300);
-   WriteReg_32(DBSC_D3_DBSCHQOS91,0x000002F0);
-   WriteReg_32(DBSC_D3_DBSCHQOS92,0x00000200);
-   WriteReg_32(DBSC_D3_DBSCHQOS93,0x00000100);
-   WriteReg_32(DBSC_D3_DBSCHQOS130,0x00000100);
-   WriteReg_32(DBSC_D3_DBSCHQOS131,0x000000F0);
-   WriteReg_32(DBSC_D3_DBSCHQOS132,0x000000A0);
-   WriteReg_32(DBSC_D3_DBSCHQOS133,0x00000040);
-   WriteReg_32(DBSC_D3_DBSCHQOS140,0x000000C0);
-   WriteReg_32(DBSC_D3_DBSCHQOS141,0x000000B0);
-   WriteReg_32(DBSC_D3_DBSCHQOS142,0x00000080);
-   WriteReg_32(DBSC_D3_DBSCHQOS143,0x00000040);
-   WriteReg_32(DBSC_D3_DBSCHQOS150,0x00000040);
-   WriteReg_32(DBSC_D3_DBSCHQOS151,0x00000030);
-   WriteReg_32(DBSC_D3_DBSCHQOS152,0x00000020);
-   WriteReg_32(DBSC_D3_DBSCHQOS153,0x00000010);
-   WriteReg_32(0xE67F0018,0x00000001);
-   WriteReg_32(DBSC_D3_DBSYSCNT0,0x00000000);
+       mmio_write_32(DBSC_DBSYSCNT0, 0x00001234);
+       mmio_write_32(DBSC_DBCAM0CNF1, 0x00043218);
+       mmio_write_32(DBSC_DBCAM0CNF2, 0x000000F4);
+       mmio_write_32(DBSC_DBSCHCNT0, 0x000f0037);
+       mmio_write_32(DBSC_DBSCHSZ0, 0x00000001);
+       mmio_write_32(DBSC_DBSCHRW0, 0x22421111);
+       mmio_write_32(DBSC_SCFCTST2, 0x012F1123);
+       mmio_write_32(DBSC_DBSCHQOS00, 0x00000F00);
+       mmio_write_32(DBSC_DBSCHQOS01, 0x00000B00);
+       mmio_write_32(DBSC_DBSCHQOS02, 0x00000000);
+       mmio_write_32(DBSC_DBSCHQOS03, 0x00000000);
+       mmio_write_32(DBSC_DBSCHQOS40, 0x00000300);
+       mmio_write_32(DBSC_DBSCHQOS41, 0x000002F0);
+       mmio_write_32(DBSC_DBSCHQOS42, 0x00000200);
+       mmio_write_32(DBSC_DBSCHQOS43, 0x00000100);
+       mmio_write_32(DBSC_DBSCHQOS90, 0x00000300);
+       mmio_write_32(DBSC_DBSCHQOS91, 0x000002F0);
+       mmio_write_32(DBSC_DBSCHQOS92, 0x00000200);
+       mmio_write_32(DBSC_DBSCHQOS93, 0x00000100);
+       mmio_write_32(DBSC_DBSCHQOS130, 0x00000100);
+       mmio_write_32(DBSC_DBSCHQOS131, 0x000000F0);
+       mmio_write_32(DBSC_DBSCHQOS132, 0x000000A0);
+       mmio_write_32(DBSC_DBSCHQOS133, 0x00000040);
+       mmio_write_32(DBSC_DBSCHQOS140, 0x000000C0);
+       mmio_write_32(DBSC_DBSCHQOS141, 0x000000B0);
+       mmio_write_32(DBSC_DBSCHQOS142, 0x00000080);
+       mmio_write_32(DBSC_DBSCHQOS143, 0x00000040);
+       mmio_write_32(DBSC_DBSCHQOS150, 0x00000040);
+       mmio_write_32(DBSC_DBSCHQOS151, 0x00000030);
+       mmio_write_32(DBSC_DBSCHQOS152, 0x00000020);
+       mmio_write_32(DBSC_DBSCHQOS153, 0x00000010);
+       mmio_write_32(0xE67F0018, 0x00000001);
+       mmio_write_32(DBSC_DBSYSCNT0, 0x00000000);
 #endif
 }
 
-#define PRR                    (0xFFF00044U)
-#define PRR_PRODUCT_MASK       (0x00007F00U)
-#define PRR_PRODUCT_D3         (0x00005800U)
+#define PRR                    0xFFF00044U
+#define PRR_PRODUCT_MASK       0x00007F00U
+#define PRR_PRODUCT_D3         0x00005800U
 
-#define        RST_MODEMR              (0xE6160060)
-#define        MODEMR_MD19             (0x00080000U)
+#define        MODEMR_MD19             BIT(19)
 
 int32_t rcar_dram_init(void)
 {
@@ -669,15 +678,14 @@ int32_t rcar_dram_init(void)
        uint32_t ddr_mbps;
 
        reg = mmio_read_32(PRR);
-
-       if (PRR_PRODUCT_D3 != (reg & PRR_PRODUCT_MASK)) {
+       if ((reg & PRR_PRODUCT_MASK) != PRR_PRODUCT_D3) {
                ERROR("LSI Product ID (PRR=0x%x) DDR initialize not supported.\n",
                      reg);
                panic();
        }
 
        reg = mmio_read_32(RST_MODEMR);
-       if (MODEMR_MD19 == (reg & MODEMR_MD19)) {
+       if (reg & MODEMR_MD19) {
                init_ddr_d3_1866();
                ddr_mbps = 1866;
        } else {
index c289c88fd8b464e091be89bd4d5dbe32a6e72a15..7aedc88d6bcd7851e9311231694818e1d38708d8 100644 (file)
 /*
- * Copyright (c) 2015-2018, Renesas Electronics Corporation. All rights reserved.
+ * Copyright (c) 2015-2019, Renesas Electronics Corporation.
+ * All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
+#include <lib/mmio.h>
 #include <stdint.h>
 
 #include <common/debug.h>
 
-#include "boot_init_dram_regdef_e3.h"
-#include "ddr_init_e3.h"
+#include "boot_init_dram.h"
+#include "boot_init_dram_regdef.h"
 
 #include "../dram_sub_func.h"
 
-/*  rev.0.04 add variables */
-/*******************************************************************************
- *  variables
- ******************************************************************************/
-uint32_t ddrBackup;
-
-/*  rev.0.03 add Prototypes */
-/*******************************************************************************
- *  Prototypes
- ******************************************************************************/
-/* static uint32_t init_ddr(void); rev.0.04 */
-/* static uint32_t recovery_from_backup_mode(void);  rev.0.04 */
-/* int32_t dram_update_boot_status(uint32_t status); rev.0.04 */
-
-/*  rev.0.03 add Comment */
-/*******************************************************************************
- *  register write/read function
- ******************************************************************************/
-static void    WriteReg_32(uint32_t a, uint32_t v)
-{
-    (*(volatile uint32_t*)(uintptr_t)a) = v;
-} /*  WriteReg_32 */
+#define RCAR_E3_DDR_VERSION    "rev.0.12"
 
-static uint32_t ReadReg_32(uint32_t a)
-{
-    uint32_t w = (*(volatile uint32_t*)(uintptr_t)a);
-    return w;
-} /*  ReadReg_32 */
+/* Average periodic refresh interval[ns]. Support 3900,7800 */
+#ifdef ddr_qos_init_setting
+#define REFRESH_RATE   3900U
+#else
+#if RCAR_REF_INT == 1
+#define REFRESH_RATE   7800U
+#else
+#define REFRESH_RATE   3900U
+#endif
+#endif
 
-/*  rev.0.04 add Comment */
-/*******************************************************************************
+/*
  *  Initialize ddr
- ******************************************************************************/
+ */
 uint32_t init_ddr(void)
 {
-   uint32_t RegVal_R2, RegVal_R5, RegVal_R6, RegVal_R7, RegVal_R12, i;
-   uint32_t ddr_md;
-
-/* rev.0.08 */
-   uint32_t RegVal, j;
-   uint32_t dqsgd_0c, bdlcount_0c, bdlcount_0c_div2, bdlcount_0c_div4, bdlcount_0c_div8, bdlcount_0c_div16;
-   uint32_t gatesl_0c, rdqsd_0c, rdqsnd_0c, rbd_0c[4];
-   uint32_t pdqsr_ctl, lcdl_ctl, lcdl_judge1, lcdl_judge2;
-/* rev.0.10 */
-   uint32_t pdr_ctl;
-/* rev.0.11 */
-   uint32_t byp_ctl;
-
-/* rev.0.08 */
-   if ((ReadReg_32(0xFFF00044) & 0x000000FF) == 0x00000000) {
-     pdqsr_ctl  = 1;
-     lcdl_ctl   = 1;
-     pdr_ctl    = 1;  /* rev.0.10 */
-     byp_ctl    = 1;  /* rev.0.11 */
-    } else {
-     pdqsr_ctl  = 0;
-     lcdl_ctl   = 0;
-     pdr_ctl    = 0;  /* rev.0.10 */
-     byp_ctl    = 0;  /* rev.0.11 */
-   }
-
-   /*  Judge the DDR bit rate (ddr_md : 0 = 1584Mbps, 1 = 1856Mbps) */
-   ddr_md = (ReadReg_32(RST_MODEMR) >> 19) & BIT0;
-
-   /*  1584Mbps setting */
-   if (ddr_md == 0) {
-      /* CPG setting ===============================================*/
-      WriteReg_32(CPG_CPGWPR, 0x5A5AFFFF);
-      WriteReg_32(CPG_CPGWPCR, 0xA5A50000);
-
-      WriteReg_32(CPG_SRCR4, 0x20000000);
-
-      WriteReg_32(0xE61500DC, 0xe2200000);  /*  Change to 1584Mbps */
-      while ((BIT11 & ReadReg_32(CPG_PLLECR)) == 0);
-
-      WriteReg_32(CPG_SRSTCLR4, 0x20000000);
-
-      WriteReg_32(CPG_CPGWPCR, 0xA5A50001);
-
-      /* CPG setting ===============================================*/
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBSYSCNT0, 0x00001234);
-   WriteReg_32(DBSC_E3_DBKIND, 0x00000007);
+       uint32_t i, r2, r5, r6, r7, r12;
+       uint32_t ddr_md;
+       uint32_t regval, j;
+       uint32_t dqsgd_0c, bdlcount_0c, bdlcount_0c_div2, bdlcount_0c_div4;
+       uint32_t bdlcount_0c_div8, bdlcount_0c_div16;
+       uint32_t gatesl_0c, rdqsd_0c, rdqsnd_0c, rbd_0c[4];
+       uint32_t pdqsr_ctl, lcdl_ctl, lcdl_judge1, lcdl_judge2;
+       uint32_t pdr_ctl;
+       uint32_t byp_ctl;
+
+       if ((mmio_read_32(0xFFF00044) & 0x000000FF) == 0x00000000) {
+               pdqsr_ctl = 1;
+               lcdl_ctl = 1;
+               pdr_ctl = 1;
+               byp_ctl = 1;
+       } else {
+               pdqsr_ctl = 0;
+               lcdl_ctl = 0;
+               pdr_ctl = 0;
+               byp_ctl = 0;
+       }
+
+       /* Judge the DDR bit rate (ddr_md : 0 = 1584Mbps, 1 = 1856Mbps) */
+       ddr_md = (mmio_read_32(RST_MODEMR) >> 19) & BIT(0);
+
+       /* 1584Mbps setting */
+       if (ddr_md == 0) {
+               mmio_write_32(CPG_CPGWPR, 0x5A5AFFFF);
+               mmio_write_32(CPG_CPGWPCR, 0xA5A50000);
+
+               mmio_write_32(CPG_SRCR4, 0x20000000);
+
+               mmio_write_32(0xE61500DC, 0xe2200000);  /* Change to 1584Mbps */
+               while (!(mmio_read_32(CPG_PLLECR) & BIT(11)))
+                       ;
+
+               mmio_write_32(CPG_SRSTCLR4, 0x20000000);
+
+               mmio_write_32(CPG_CPGWPCR, 0xA5A50001);
+       }
+
+       mmio_write_32(DBSC_DBSYSCNT0, 0x00001234);
+       mmio_write_32(DBSC_DBKIND, 0x00000007);
 
 #if RCAR_DRAM_DDR3L_MEMCONF == 0
-   WriteReg_32(DBSC_E3_DBMEMCONF00, 0x0f030a02); /*  1GB */
-#elif RCAR_DRAM_DDR3L_MEMCONF == 1
-   WriteReg_32(DBSC_E3_DBMEMCONF00, 0x10030a02); /*  2GB(default) */
-#elif RCAR_DRAM_DDR3L_MEMCONF == 2
-   WriteReg_32(DBSC_E3_DBMEMCONF00, 0x10030b02); /*  4GB */
+       mmio_write_32(DBSC_DBMEMCONF00, 0x0f030a02);    /* 1GB */
 #else
-   WriteReg_32(DBSC_E3_DBMEMCONF00, 0x10030a02); /*  2GB */
+       mmio_write_32(DBSC_DBMEMCONF00, 0x10030a02);    /* 2GB(default) */
 #endif
 
 #if RCAR_DRAM_DDR3L_MEMDUAL == 1
-        RegVal_R2 = (ReadReg_32(0xE6790614));
-         WriteReg_32(0xE6790614, RegVal_R2 | 0x00000003); /*  MCS1_N/MODT1 are activated. */
+       r2 = mmio_read_32(0xE6790614);
+       mmio_write_32(0xE6790614, r2 | 0x3); /* MCS1_N/MODT1 are activated. */
 #endif
 
-
-   WriteReg_32(DBSC_E3_DBPHYCONF0, 0x00000001);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBTR0, 0x0000000B);
-      WriteReg_32(DBSC_E3_DBTR1, 0x00000008);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBTR0, 0x0000000D);
-      WriteReg_32(DBSC_E3_DBTR1, 0x00000009);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBTR2, 0x00000000);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBTR3, 0x0000000B);
-      WriteReg_32(DBSC_E3_DBTR4, 0x000B000B);
-      WriteReg_32(DBSC_E3_DBTR5, 0x00000027);
-      WriteReg_32(DBSC_E3_DBTR6, 0x0000001C);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBTR3, 0x0000000D);
-      WriteReg_32(DBSC_E3_DBTR4, 0x000D000D);
-      WriteReg_32(DBSC_E3_DBTR5, 0x0000002D);
-      WriteReg_32(DBSC_E3_DBTR6, 0x00000020);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBTR7, 0x00060006);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBTR8, 0x00000020);
-      WriteReg_32(DBSC_E3_DBTR9, 0x00000006);
-      WriteReg_32(DBSC_E3_DBTR10, 0x0000000C);
-      WriteReg_32(DBSC_E3_DBTR11, 0x0000000A);
-      WriteReg_32(DBSC_E3_DBTR12, 0x00120012);
-      WriteReg_32(DBSC_E3_DBTR13, 0x000000CE);
-      WriteReg_32(DBSC_E3_DBTR14, 0x00140005);
-      WriteReg_32(DBSC_E3_DBTR15, 0x00050004);
-      WriteReg_32(DBSC_E3_DBTR16, 0x071F0305);
-      WriteReg_32(DBSC_E3_DBTR17, 0x040C0000);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBTR8, 0x00000021);
-      WriteReg_32(DBSC_E3_DBTR9, 0x00000007);
-      WriteReg_32(DBSC_E3_DBTR10, 0x0000000E);
-      WriteReg_32(DBSC_E3_DBTR11, 0x0000000C);
-      WriteReg_32(DBSC_E3_DBTR12, 0x00140014);
-      WriteReg_32(DBSC_E3_DBTR13, 0x000000F2);
-      WriteReg_32(DBSC_E3_DBTR14, 0x00170006);
-      WriteReg_32(DBSC_E3_DBTR15, 0x00060005);
-      WriteReg_32(DBSC_E3_DBTR16, 0x09210507);
-      WriteReg_32(DBSC_E3_DBTR17, 0x040E0000);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBTR18, 0x00000200);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBTR19, 0x01000040);
-      WriteReg_32(DBSC_E3_DBTR20, 0x020000D6);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBTR19, 0x0129004B);
-      WriteReg_32(DBSC_E3_DBTR20, 0x020000FB);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBTR21, 0x00040004);
-   WriteReg_32(DBSC_E3_DBBL, 0x00000000);
-   WriteReg_32(DBSC_E3_DBODT0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBADJ0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBSYSCONF1, 0x00000002);
-   WriteReg_32(DBSC_E3_DBDFICNT0, 0x00000010);
-   WriteReg_32(DBSC_E3_DBBCAMDIS, 0x00000001);
-   WriteReg_32(DBSC_E3_DBSCHRW1, 0x00000046);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_SCFCTST0, 0x0D050B03);
-      WriteReg_32(DBSC_E3_SCFCTST1, 0x0306030C);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_SCFCTST0, 0x0C050B03);
-      WriteReg_32(DBSC_E3_SCFCTST1, 0x0305030C);
-   } /*  ddr_md */
-
-   /*  rev.0.03 add Comment */
-   /****************************************************************************
-    *  Initial_Step0( INITBYP )
-    ***************************************************************************/
-   WriteReg_32(DBSC_E3_DBPDLK0, 0x0000A55A);
-   WriteReg_32(DBSC_E3_DBCMD, 0x01840001);
-   WriteReg_32(DBSC_E3_DBCMD, 0x08840000);
-   NOTICE("BL2: [COLD_BOOT]\n");       /* rev.0.11 */
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x80010000);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   /*  rev.0.03 add Comment */
-   /****************************************************************************
-    *  Initial_Step1( ZCAL,PLLINIT,DCAL,PHYRST training )
-    ***************************************************************************/
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000008);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x000B8000);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000090);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x04058904);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x04058A04);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000091);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0007BB6B);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000095);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0007BBAD);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000099);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0007BB6B);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000090);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x04058900);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x04058A00);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000021);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0024641E);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00010073);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   /*  rev.0.03 add Comment */
-   /****************************************************************************
-    *  Initial_Step2( DRAMRST/DRAMINT training )
-    ***************************************************************************/
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000090);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x0C058900);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x0C058A00);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000090);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x04058900);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x04058A00);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000003);
-   if (byp_ctl == 1) {
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x0780C720);
-   } else {
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x0780C700);
-   }
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000007);
-   while ((BIT30 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000004);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, (uint32_t)(REFRESH_RATE * 792 / 125) - 400 + 0x08B00000);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, (uint32_t)(REFRESH_RATE * 928 / 125) - 400 + 0x0A300000);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000022);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x1000040B);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000023);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x2D9C0B66);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x35A00D77);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000024);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x2A88B400);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x2A8A2C28);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000025);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x30005200);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x30005E00);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000026);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x0014A9C9);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x0014CB49);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000027);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000D70);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000F14);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000028);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000046);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000029);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      if (REFRESH_RATE > 3900) {
-          WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000018);  /*            [7]SRT=0 */
-      } else {
-          WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000098);  /*            [7]SRT=1 */
-      }
-   } else {                                        /*  1856Mbps */
-      if (REFRESH_RATE > 3900) {
-          WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000020);  /*            [7]SRT=0 */
-      } else {
-          WriteReg_32(DBSC_E3_DBPDRGD0, 0x000000A0);  /*            [7]SRT=1 */
-      } /*  REFRESH_RATE */
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x0000002C);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x81003047);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000020);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00181884);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x0000001A);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x33C03C10);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A7);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0D0D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A8);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0D0D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A9);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x000D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C7);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0D0D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C8);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0D0D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C9);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x000D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E7);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0D0D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E8);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0D0D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E9);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x000D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000107);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0D0D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000108);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0D0D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000109);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x000D0D0D);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00010181);
-   WriteReg_32(DBSC_E3_DBCMD, 0x08840001);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   /*  rev.0.03 add Comment */
-   /****************************************************************************
-    *  Initial_Step3( WL/QSG training )
-    ***************************************************************************/
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00010601);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   for (i = 0; i < 4; i++) {
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B1 + i * 0x20);
-      RegVal_R5 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0x0000FF00) >> 0x8;
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B4 + i * 0x20);
-      RegVal_R6 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0x000000FF);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B3 + i * 0x20);
-      RegVal_R7 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0x00000007);
-      if (RegVal_R6 > 0) {
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-        RegVal_R2 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFFF8);
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-         WriteReg_32(DBSC_E3_DBPDRGD0, RegVal_R2 | ((RegVal_R7 + 0x1) & 0x00000007));
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-        RegVal_R2 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFF00);
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-         WriteReg_32(DBSC_E3_DBPDRGD0, RegVal_R2 | RegVal_R6);
-      } else {
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-        RegVal_R2 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFFF8);
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-         WriteReg_32(DBSC_E3_DBPDRGD0, RegVal_R2 | RegVal_R7);
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-        RegVal_R2 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFF00);
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-         WriteReg_32(DBSC_E3_DBPDRGD0, RegVal_R2 | ((RegVal_R6 + ((RegVal_R5) << 1)) & 0x000000FF));
-      } /*  RegVal_R6 */
-   } /*  for i */
-
-   /*  rev.0.10 move Comment */
-   /****************************************************************************
-    *  Initial_Step4( WLADJ training )
-    ***************************************************************************/
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000005);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0xC1AA00C0);
-
-   /* rev.0.08 */
-   if (pdqsr_ctl == 1){} else {
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000100);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   }
-
-   /* PDR always off */        /* rev.0.10 */
-   if (pdr_ctl == 1) {
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000103);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-   }
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00010801);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   /****************************************************************************
-    *  Initial_Step5(Read Data Bit Deskew)
-    ***************************************************************************/
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000005);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0xC1AA00D8);
-
-   /* rev.0.08 */
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00011001);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-if (pdqsr_ctl == 1) {
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000100);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-}
-
-   /* PDR dynamic */   /* rev.0.10 */
-   if (pdr_ctl == 1) {
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000103);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-   }
-
-   /****************************************************************************
-    *  Initial_Step6(Write Data Bit Deskew)
-    ***************************************************************************/
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00012001);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   /****************************************************************************
-    *  Initial_Step7(Read Data Eye Training)
-    ***************************************************************************/
-if (pdqsr_ctl == 1) {
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C000285);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C000285);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C000285);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000100);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C000285);
-}
-
-   /* PDR always off */        /* rev.0.10 */
-   if (pdr_ctl == 1) {
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000103);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-   }
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00014001);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-if (pdqsr_ctl == 1) {
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000100);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-}
-
-   /* PDR dynamic */   /* rev.0.10 */
-   if (pdr_ctl == 1) {
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000103);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-   }
-
-   /****************************************************************************
-    *  Initial_Step8(Write Data Eye Training)
-    ***************************************************************************/
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00018001);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   /*  rev.0.03 add Comment */
-   /****************************************************************************
-    *  Initial_Step3_2( DQS Gate Training )
-    ***************************************************************************/
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C000285);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C000285);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C000285);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000100);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C000285);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x0000002C);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x81003087);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00010401);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   for (i = 0; i < 4; i++) {
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B1 + i * 0x20);
-      RegVal_R5 = ((ReadReg_32(DBSC_E3_DBPDRGD0) & 0x0000FF00) >> 0x8);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B4 + i * 0x20);
-      RegVal_R6 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0x000000FF);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B3 + i * 0x20);
-      RegVal_R7 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0x00000007);
-      RegVal_R12 = (RegVal_R5 >> 0x2);
-      if (RegVal_R12 < RegVal_R6) {
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-        RegVal_R2 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFFF8);
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-         WriteReg_32(DBSC_E3_DBPDRGD0, RegVal_R2 | ((RegVal_R7 + 0x1) & 0x00000007));
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-        RegVal_R2 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFF00);
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-         WriteReg_32(DBSC_E3_DBPDRGD0, RegVal_R2 | ((RegVal_R6 - (RegVal_R12)) & 0x000000FF));
-      } else {
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-        RegVal_R2 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFFF8);
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-         WriteReg_32(DBSC_E3_DBPDRGD0, RegVal_R2 | (RegVal_R7 & 0x00000007));
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-        RegVal_R2 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFF00);
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-         WriteReg_32(DBSC_E3_DBPDRGD0, RegVal_R2 | ((RegVal_R6 + (RegVal_R5) + ((RegVal_R5) >> 1) + (RegVal_R12)) & 0x000000FF));
-      } /*  RegVal_R12 < RegVal_R6 */
-   } /*  for i */
-
-   /*  rev.0.10 move Comment */
-   /****************************************************************************
-    *  Initial_Step5-2_7-2( Rd bit Rd eye )
-    ***************************************************************************/
-/* rev.0.08 */
-   if (pdqsr_ctl == 1){} else {
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000100);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   }
-
-   /* PDR always off */        /* rev.0.10 */
-   if (pdr_ctl == 1) {
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000103);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-   }
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00015001);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-/* rev.0.08 */
-   if (lcdl_ctl == 1) {
-       for (i = 0; i < 4; i++) {
-          WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-         dqsgd_0c = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0x000000FF);
-          WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B1 + i * 0x20);
-         bdlcount_0c = ((ReadReg_32(DBSC_E3_DBPDRGD0) & 0x0000FF00) >> 8);
-         bdlcount_0c_div2  = (bdlcount_0c >> 1);
-         bdlcount_0c_div4  = (bdlcount_0c >> 2);
-         bdlcount_0c_div8  = (bdlcount_0c >> 3);
-         bdlcount_0c_div16 = (bdlcount_0c >> 4);
-
-          if (ddr_md == 0) {                                 /*  1584Mbps */
-            lcdl_judge1 = bdlcount_0c_div2 + bdlcount_0c_div4 + bdlcount_0c_div8;
-            lcdl_judge2 = bdlcount_0c + bdlcount_0c_div4 + bdlcount_0c_div16;
-         } else {                                        /*  1856Mbps */
-            lcdl_judge1 = bdlcount_0c_div2 + bdlcount_0c_div4;
-            lcdl_judge2 = bdlcount_0c + bdlcount_0c_div4;
-         } /*  ddr_md */
-
-         if (dqsgd_0c > lcdl_judge1) {
-            if (dqsgd_0c <= lcdl_judge2) {
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-               RegVal = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFF00);
-                WriteReg_32(DBSC_E3_DBPDRGD0, ((dqsgd_0c - bdlcount_0c_div8) | RegVal));
-             } else {
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-               RegVal = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFF00);
-               WriteReg_32(DBSC_E3_DBPDRGD0, RegVal);
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-               gatesl_0c = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0x00000007);
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-               RegVal = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFFF8);
-                WriteReg_32(DBSC_E3_DBPDRGD0, (RegVal | (gatesl_0c + 1)));
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000AF + i * 0x20);
-               RegVal = (ReadReg_32(DBSC_E3_DBPDRGD0));
-               rdqsd_0c = (RegVal & 0x0000FF00) >> 8;
-               rdqsnd_0c = (RegVal & 0x00FF0000) >> 16;
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000AF + i * 0x20);
-                WriteReg_32(DBSC_E3_DBPDRGD0, ((RegVal & 0xFF0000FF) | ((rdqsd_0c + bdlcount_0c_div4) << 8) | ((rdqsnd_0c + bdlcount_0c_div4) << 16)));
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000AA + i * 0x20);
-               RegVal = (ReadReg_32(DBSC_E3_DBPDRGD0));
-                rbd_0c[0] = (RegVal) &0x0000001f;
-               rbd_0c[1] = (RegVal >>  8) & 0x0000001f;
-               rbd_0c[2] = (RegVal >> 16) & 0x0000001f;
-               rbd_0c[3] = (RegVal >> 24) & 0x0000001f;
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000AA + i * 0x20);
-               RegVal = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xE0E0E0E0);
-                for (j = 0; j < 4; j++) {
-                   rbd_0c[j] = (rbd_0c[j] + bdlcount_0c_div4);
-                   if (rbd_0c[j] > 0x1F) rbd_0c[j] = 0x1F;
-                    RegVal = RegVal | (rbd_0c[j] << 8 * j);
+       mmio_write_32(DBSC_DBPHYCONF0, 0x1);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0) {      /* 1584Mbps */
+               mmio_write_32(DBSC_DBTR0, 0xB);
+               mmio_write_32(DBSC_DBTR1, 0x8);
+       } else {                /* 1856Mbps */
+               mmio_write_32(DBSC_DBTR0, 0xD);
+               mmio_write_32(DBSC_DBTR1, 0x9);
+       }
+
+       mmio_write_32(DBSC_DBTR2, 0x00000000);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0) {      /* 1584Mbps */
+               mmio_write_32(DBSC_DBTR3, 0x0000000B);
+               mmio_write_32(DBSC_DBTR4, 0x000B000B);
+               mmio_write_32(DBSC_DBTR5, 0x00000027);
+               mmio_write_32(DBSC_DBTR6, 0x0000001C);
+       } else {                /* 1856Mbps */
+               mmio_write_32(DBSC_DBTR3, 0x0000000D);
+               mmio_write_32(DBSC_DBTR4, 0x000D000D);
+               mmio_write_32(DBSC_DBTR5, 0x0000002D);
+               mmio_write_32(DBSC_DBTR6, 0x00000020);
+       }
+
+       mmio_write_32(DBSC_DBTR7, 0x00060006);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0) {      /* 1584Mbps */
+               mmio_write_32(DBSC_DBTR8, 0x00000020);
+               mmio_write_32(DBSC_DBTR9, 0x00000006);
+               mmio_write_32(DBSC_DBTR10, 0x0000000C);
+               mmio_write_32(DBSC_DBTR11, 0x0000000A);
+               mmio_write_32(DBSC_DBTR12, 0x00120012);
+               mmio_write_32(DBSC_DBTR13, 0x000000CE);
+               mmio_write_32(DBSC_DBTR14, 0x00140005);
+               mmio_write_32(DBSC_DBTR15, 0x00050004);
+               mmio_write_32(DBSC_DBTR16, 0x071F0305);
+               mmio_write_32(DBSC_DBTR17, 0x040C0000);
+       } else {                /* 1856Mbps */
+               mmio_write_32(DBSC_DBTR8, 0x00000021);
+               mmio_write_32(DBSC_DBTR9, 0x00000007);
+               mmio_write_32(DBSC_DBTR10, 0x0000000E);
+               mmio_write_32(DBSC_DBTR11, 0x0000000C);
+               mmio_write_32(DBSC_DBTR12, 0x00140014);
+               mmio_write_32(DBSC_DBTR13, 0x000000F2);
+               mmio_write_32(DBSC_DBTR14, 0x00170006);
+               mmio_write_32(DBSC_DBTR15, 0x00060005);
+               mmio_write_32(DBSC_DBTR16, 0x09210507);
+               mmio_write_32(DBSC_DBTR17, 0x040E0000);
+       }
+
+       mmio_write_32(DBSC_DBTR18, 0x00000200);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0) {      /* 1584Mbps */
+               mmio_write_32(DBSC_DBTR19, 0x01000040);
+               mmio_write_32(DBSC_DBTR20, 0x020000D6);
+       } else {                /* 1856Mbps */
+               mmio_write_32(DBSC_DBTR19, 0x0129004B);
+               mmio_write_32(DBSC_DBTR20, 0x020000FB);
+       }
+
+       mmio_write_32(DBSC_DBTR21, 0x00040004);
+       mmio_write_32(DBSC_DBBL, 0x00000000);
+       mmio_write_32(DBSC_DBODT0, 0x00000001);
+       mmio_write_32(DBSC_DBADJ0, 0x00000001);
+       mmio_write_32(DBSC_DBSYSCONF1, 0x00000002);
+       mmio_write_32(DBSC_DBDFICNT0, 0x00000010);
+       mmio_write_32(DBSC_DBBCAMDIS, 0x00000001);
+       mmio_write_32(DBSC_DBSCHRW1, 0x00000046);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0) {      /* 1584Mbps */
+               mmio_write_32(DBSC_SCFCTST0, 0x0D050B03);
+               mmio_write_32(DBSC_SCFCTST1, 0x0306030C);
+       } else {                /* 1856Mbps */
+               mmio_write_32(DBSC_SCFCTST0, 0x0C050B03);
+               mmio_write_32(DBSC_SCFCTST1, 0x0305030C);
+       }
+
+       /*
+        * Initial_Step0( INITBYP )
+        */
+       mmio_write_32(DBSC_DBPDLK0, 0x0000A55A);
+       mmio_write_32(DBSC_DBCMD, 0x01840001);
+       mmio_write_32(DBSC_DBCMD, 0x08840000);
+       NOTICE("BL2: [COLD_BOOT]\n");
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x80010000);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       /*
+        * Initial_Step1( ZCAL,PLLINIT,DCAL,PHYRST training )
+        */
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000008);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000B8000);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0)        /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x04058904);
+       else                    /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x04058A04);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000091);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0007BB6B);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000095);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0007BBAD);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000099);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0007BB6B);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0)        /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x04058900);
+       else                    /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x04058A00);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000021);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0024641E);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010073);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       /*
+        * Initial_Step2( DRAMRST/DRAMINT training )
+        */
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0)        /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x0C058900);
+       else                    /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x0C058A00);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0)        /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x04058900);
+       else                    /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x04058A00);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000003);
+       if (byp_ctl == 1)
+               mmio_write_32(DBSC_DBPDRGD0, 0x0780C720);
+       else
+               mmio_write_32(DBSC_DBPDRGD0, 0x0780C700);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000007);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(30)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000004);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0) {      /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, (REFRESH_RATE * 792 / 125) -
+                                            400 + 0x08B00000);
+       } else {                /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, (REFRESH_RATE * 928 / 125) -
+                                            400 + 0x0A300000);
+       }
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000022);
+       mmio_write_32(DBSC_DBPDRGD0, 0x1000040B);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000023);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0)        /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x2D9C0B66);
+       else                    /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x35A00D77);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000024);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0)        /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x2A88B400);
+       else                    /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x2A8A2C28);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000025);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0)        /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x30005200);
+       else                    /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x30005E00);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000026);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0)        /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x0014A9C9);
+       else                    /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x0014CB49);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000027);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0)        /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000D70);
+       else                    /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000F14);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000028);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00000046);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000029);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0) {      /* 1584Mbps */
+               if (REFRESH_RATE > 3900)        /* [7]SRT=0 */
+                       mmio_write_32(DBSC_DBPDRGD0, 0x18);
+               else                            /* [7]SRT=1 */
+                       mmio_write_32(DBSC_DBPDRGD0, 0x98);
+       } else {                /* 1856Mbps */
+               if (REFRESH_RATE > 3900)        /* [7]SRT=0 */
+                       mmio_write_32(DBSC_DBPDRGD0, 0x20);
+               else                            /* [7]SRT=1 */
+                       mmio_write_32(DBSC_DBPDRGD0, 0xA0);
+       }
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000002C);
+       mmio_write_32(DBSC_DBPDRGD0, 0x81003047);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000020);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00181884);
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000001A);
+       mmio_write_32(DBSC_DBPDRGD0, 0x33C03C10);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A7);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A8);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A9);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C7);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C8);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C9);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000E7);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000E8);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000E9);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000107);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000108);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000109);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000D0D0D);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010181);
+       mmio_write_32(DBSC_DBCMD, 0x08840001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       /*
+        * Initial_Step3( WL/QSG training )
+        */
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010601);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       for (i = 0; i < 4; i++) {
+               mmio_write_32(DBSC_DBPDRGA0, 0xB1 + i * 0x20);
+               r5 = (mmio_read_32(DBSC_DBPDRGD0) & 0xFF00) >> 0x8;
+               mmio_write_32(DBSC_DBPDRGA0, 0xB4 + i * 0x20);
+               r6 = mmio_read_32(DBSC_DBPDRGD0) & 0xFF;
+               mmio_write_32(DBSC_DBPDRGA0, 0xB3 + i * 0x20);
+               r7 = mmio_read_32(DBSC_DBPDRGD0) & 0x7;
+
+               if (r6 > 0) {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | ((r7 + 0x1) & 0x7));
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | r6);
+               } else {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | r7);
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 |
+                                                    ((r6 + ((r5) << 1)) &
+                                                    0xFF));
+               }
+       }
+
+       /*
+        * Initial_Step4( WLADJ training )
+        */
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000005);
+       mmio_write_32(DBSC_DBPDRGD0, 0xC1AA00C0);
+
+       if (pdqsr_ctl == 0) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000100);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       }
+
+       /* PDR always off */
+       if (pdr_ctl == 1) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000103);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+       }
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010801);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       /*
+        * Initial_Step5(Read Data Bit Deskew)
+        */
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000005);
+       mmio_write_32(DBSC_DBPDRGD0, 0xC1AA00D8);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00011001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       if (pdqsr_ctl == 1) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000100);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       }
+
+       /* PDR dynamic */
+       if (pdr_ctl == 1) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000103);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+       }
+
+       /*
+        * Initial_Step6(Write Data Bit Deskew)
+        */
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00012001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       /*
+        * Initial_Step7(Read Data Eye Training)
+        */
+       if (pdqsr_ctl == 1) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000100);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+       }
+
+       /* PDR always off */
+       if (pdr_ctl == 1) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000103);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+       }
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00014001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       if (pdqsr_ctl == 1) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000100);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       }
+
+       /* PDR dynamic */
+       if (pdr_ctl == 1) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000103);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+       }
+
+       /*
+        * Initial_Step8(Write Data Eye Training)
+        */
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00018001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       /*
+        * Initial_Step3_2( DQS Gate Training )
+        */
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000E0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000100);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000002C);
+       mmio_write_32(DBSC_DBPDRGD0, 0x81003087);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010401);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       for (i = 0; i < 4; i++) {
+               mmio_write_32(DBSC_DBPDRGA0, 0xB1 + i * 0x20);
+               r5 = ((mmio_read_32(DBSC_DBPDRGD0) & 0xFF00) >> 0x8);
+               mmio_write_32(DBSC_DBPDRGA0, 0xB4 + i * 0x20);
+               r6 = mmio_read_32(DBSC_DBPDRGD0) & 0xFF;
+               mmio_write_32(DBSC_DBPDRGA0, 0xB3 + i * 0x20);
+               r7 = mmio_read_32(DBSC_DBPDRGD0) & 0x7;
+               r12 = (r5 >> 0x2);
+               if (r12 < r6) {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | ((r7 + 0x1) & 0x7));
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | ((r6 - r12) & 0xFF));
+               } else {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | (r7 & 0x7));
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | ((r6 + r5 +
+                                                    (r5 >> 1) + r12) & 0xFF));
                }
-               WriteReg_32(DBSC_E3_DBPDRGD0, RegVal);
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000AB + i * 0x20);
-               RegVal = (ReadReg_32(DBSC_E3_DBPDRGD0));
-                rbd_0c[0] = (RegVal) &0x0000001f;
-               rbd_0c[1] = (RegVal >>  8) & 0x0000001f;
-               rbd_0c[2] = (RegVal >> 16) & 0x0000001f;
-               rbd_0c[3] = (RegVal >> 24) & 0x0000001f;
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000AB + i * 0x20);
-               RegVal = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xE0E0E0E0);
-                for (j = 0; j < 4; j++) {
-                   rbd_0c[j] = (rbd_0c[j] + bdlcount_0c_div4);
-                   if (rbd_0c[j] > 0x1F) rbd_0c[j] = 0x1F;
-                    RegVal = RegVal | (rbd_0c[j] << 8 * j);
+       }
+
+       /*
+        * Initial_Step5-2_7-2( Rd bit Rd eye )
+        */
+       if (pdqsr_ctl == 0) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000100);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       }
+
+       /* PDR always off */
+       if (pdr_ctl == 1) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000103);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+       }
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00015001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       if (lcdl_ctl == 1) {
+               for (i = 0; i < 4; i++) {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       dqsgd_0c = mmio_read_32(DBSC_DBPDRGD0) & 0xFF;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB1 + i * 0x20);
+                       bdlcount_0c = (mmio_read_32(DBSC_DBPDRGD0) & 0xFF00) >>
+                                       8;
+                       bdlcount_0c_div2 = bdlcount_0c >> 1;
+                       bdlcount_0c_div4 = bdlcount_0c >> 2;
+                       bdlcount_0c_div8 = bdlcount_0c >> 3;
+                       bdlcount_0c_div16 = bdlcount_0c >> 4;
+
+                       if (ddr_md == 0) {      /* 1584Mbps */
+                               lcdl_judge1 = bdlcount_0c_div2 +
+                                             bdlcount_0c_div4 +
+                                             bdlcount_0c_div8;
+                               lcdl_judge2 = bdlcount_0c +
+                                             bdlcount_0c_div4 +
+                                             bdlcount_0c_div16;
+                       } else {                /* 1856Mbps */
+                               lcdl_judge1 = bdlcount_0c_div2 +
+                                             bdlcount_0c_div4;
+                               lcdl_judge2 = bdlcount_0c +
+                                             bdlcount_0c_div4;
+                       }
+
+                       if (dqsgd_0c <= lcdl_judge1)
+                               continue;
+
+                       if (dqsgd_0c <= lcdl_judge2) {
+                               mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                               regval = mmio_read_32(DBSC_DBPDRGD0) &
+                                               0xFFFFFF00;
+                               mmio_write_32(DBSC_DBPDRGD0,
+                                             (dqsgd_0c - bdlcount_0c_div8) |
+                                             regval);
+                       } else {
+                               mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                               regval = mmio_read_32(DBSC_DBPDRGD0) &
+                                               0xFFFFFF00;
+                               mmio_write_32(DBSC_DBPDRGD0, regval);
+                               mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                               gatesl_0c = mmio_read_32(DBSC_DBPDRGD0) & 0x7;
+                               mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                               regval = mmio_read_32(DBSC_DBPDRGD0) &
+                                               0xFFFFFFF8;
+                               mmio_write_32(DBSC_DBPDRGD0, regval |
+                                                            (gatesl_0c + 1));
+                               mmio_write_32(DBSC_DBPDRGA0, 0xAF + i * 0x20);
+                               regval = (mmio_read_32(DBSC_DBPDRGD0));
+                               rdqsd_0c = (regval & 0xFF00) >> 8;
+                               rdqsnd_0c = (regval & 0xFF0000) >> 16;
+                               mmio_write_32(DBSC_DBPDRGA0, 0xAF + i * 0x20);
+                               mmio_write_32(DBSC_DBPDRGD0,
+                                             (regval & 0xFF0000FF) |
+                                             ((rdqsd_0c +
+                                               bdlcount_0c_div4) << 8) |
+                                             ((rdqsnd_0c +
+                                               bdlcount_0c_div4) << 16));
+                               mmio_write_32(DBSC_DBPDRGA0, 0xAA + i * 0x20);
+                               regval = (mmio_read_32(DBSC_DBPDRGD0));
+                               rbd_0c[0] = (regval) & 0x1f;
+                               rbd_0c[1] = (regval >> 8) & 0x1f;
+                               rbd_0c[2] = (regval >> 16) & 0x1f;
+                               rbd_0c[3] = (regval >> 24) & 0x1f;
+                               mmio_write_32(DBSC_DBPDRGA0, 0xAA + i * 0x20);
+                               regval = mmio_read_32(DBSC_DBPDRGD0) &
+                                       0xE0E0E0E0;
+                               for (j = 0; j < 4; j++) {
+                                       rbd_0c[j] = rbd_0c[j] +
+                                                   bdlcount_0c_div4;
+                                       if (rbd_0c[j] > 0x1F)
+                                               rbd_0c[j] = 0x1F;
+                                       regval = regval | (rbd_0c[j] << 8 * j);
+                               }
+                               mmio_write_32(DBSC_DBPDRGD0, regval);
+                               mmio_write_32(DBSC_DBPDRGA0, 0xAB + i * 0x20);
+                               regval = (mmio_read_32(DBSC_DBPDRGD0));
+                               rbd_0c[0] = (regval) & 0x1f;
+                               rbd_0c[1] = (regval >> 8) & 0x1f;
+                               rbd_0c[2] = (regval >> 16) & 0x1f;
+                               rbd_0c[3] = (regval >> 24) & 0x1f;
+                               mmio_write_32(DBSC_DBPDRGA0, 0xAB + i * 0x20);
+                               regval = mmio_read_32(DBSC_DBPDRGD0) &
+                                       0xE0E0E0E0;
+                               for (j = 0; j < 4; j++) {
+                                       rbd_0c[j] = rbd_0c[j] +
+                                                   bdlcount_0c_div4;
+                                       if (rbd_0c[j] > 0x1F)
+                                               rbd_0c[j] = 0x1F;
+                                       regval = regval | (rbd_0c[j] << 8 * j);
+                               }
+                               mmio_write_32(DBSC_DBPDRGD0, regval);
+                       }
                }
-               WriteReg_32(DBSC_E3_DBPDRGD0, RegVal);
-            }
-         }
-       }
-       WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000002);
-       WriteReg_32(DBSC_E3_DBPDRGD0, 0x07D81E37);
-   }
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000003);
-   if (byp_ctl == 1) {
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x0380C720);
-   } else {
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x0380C700);
-   }
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000007);
-   while ((BIT30 & ReadReg_32(DBSC_E3_DBPDRGD0)) != 0);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000021);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0024643E);
-
-   WriteReg_32(DBSC_E3_DBBUS0CNF1, 0x00000010);
-   WriteReg_32(DBSC_E3_DBCALCNF, (uint32_t)(64000000 / REFRESH_RATE) + 0x01000000);
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBRFCNF1, (uint32_t)(REFRESH_RATE * 99 / 125) + 0x00080000);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBRFCNF1, (uint32_t)(REFRESH_RATE * 116 / 125) + 0x00080000);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBRFCNF2, 0x00010000);
-   WriteReg_32(DBSC_E3_DBDFICUPDCNF, 0x40100001);
-   WriteReg_32(DBSC_E3_DBRFEN, 0x00000001);
-   WriteReg_32(DBSC_E3_DBACEN, 0x00000001);
-
-/* rev.0.08 */
-   if (pdqsr_ctl == 1) {
-   WriteReg_32(0xE67F0018, 0x00000001);
-   RegVal = ReadReg_32(0x40000000);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000000);
-   WriteReg_32(DBSC_E3_DBPDRGD0, RegVal);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000100);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   }
-
-   /* PDR dynamic */   /* rev.0.10 */
-   if (pdr_ctl == 1) {
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000103);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-   }
-
-   /*  rev.0.03 add Comment */
-   /****************************************************************************
-    *  Initial_Step9( Initial End )
-    ***************************************************************************/
-   WriteReg_32(DBSC_E3_DBPDLK0, 0x00000000);
-   WriteReg_32(DBSC_E3_DBSYSCNT0, 0x00000000);
-
-#ifdef ddr_qos_init_setting /*  only for non qos_init */
-   WriteReg_32(DBSC_E3_DBSYSCNT0, 0x00001234);
-   WriteReg_32(DBSC_E3_DBCAM0CNF1, 0x00043218);
-   WriteReg_32(DBSC_E3_DBCAM0CNF2, 0x000000F4);
-   WriteReg_32(DBSC_E3_DBSCHCNT0, 0x000f0037);
-   WriteReg_32(DBSC_E3_DBSCHSZ0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBSCHRW0, 0x22421111);
-   WriteReg_32(DBSC_E3_SCFCTST2, 0x012F1123);
-   WriteReg_32(DBSC_E3_DBSCHQOS00, 0x00000F00);
-   WriteReg_32(DBSC_E3_DBSCHQOS01, 0x00000B00);
-   WriteReg_32(DBSC_E3_DBSCHQOS02, 0x00000000);
-   WriteReg_32(DBSC_E3_DBSCHQOS03, 0x00000000);
-   WriteReg_32(DBSC_E3_DBSCHQOS40, 0x00000300);
-   WriteReg_32(DBSC_E3_DBSCHQOS41, 0x000002F0);
-   WriteReg_32(DBSC_E3_DBSCHQOS42, 0x00000200);
-   WriteReg_32(DBSC_E3_DBSCHQOS43, 0x00000100);
-   WriteReg_32(DBSC_E3_DBSCHQOS90, 0x00000100);
-   WriteReg_32(DBSC_E3_DBSCHQOS91, 0x000000F0);
-   WriteReg_32(DBSC_E3_DBSCHQOS92, 0x000000A0);
-   WriteReg_32(DBSC_E3_DBSCHQOS93, 0x00000040);
-   WriteReg_32(DBSC_E3_DBSCHQOS130, 0x00000100);
-   WriteReg_32(DBSC_E3_DBSCHQOS131, 0x000000F0);
-   WriteReg_32(DBSC_E3_DBSCHQOS132, 0x000000A0);
-   WriteReg_32(DBSC_E3_DBSCHQOS133, 0x00000040);
-   WriteReg_32(DBSC_E3_DBSCHQOS140, 0x000000C0);
-   WriteReg_32(DBSC_E3_DBSCHQOS141, 0x000000B0);
-   WriteReg_32(DBSC_E3_DBSCHQOS142, 0x00000080);
-   WriteReg_32(DBSC_E3_DBSCHQOS143, 0x00000040);
-   WriteReg_32(DBSC_E3_DBSCHQOS150, 0x00000040);
-   WriteReg_32(DBSC_E3_DBSCHQOS151, 0x00000030);
-   WriteReg_32(DBSC_E3_DBSCHQOS152, 0x00000020);
-   WriteReg_32(DBSC_E3_DBSCHQOS153, 0x00000010);
-
-/* rev.0.08 */
-   if (pdqsr_ctl == 1){} else {
-   WriteReg_32(0xE67F0018, 0x00000001);
-   }
-
-   WriteReg_32(DBSC_E3_DBSYSCNT0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x2);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7D81E37);
+       }
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000003);
+       if (byp_ctl == 1)
+               mmio_write_32(DBSC_DBPDRGD0, 0x0380C720);
+       else
+               mmio_write_32(DBSC_DBPDRGD0, 0x0380C700);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000007);
+       while (mmio_read_32(DBSC_DBPDRGD0) & BIT(30))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000021);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0024643E);
+
+       mmio_write_32(DBSC_DBBUS0CNF1, 0x00000010);
+       mmio_write_32(DBSC_DBCALCNF, (64000000 / REFRESH_RATE) + 0x01000000);
+       /* Select setting value in bps */
+       if (ddr_md == 0) {      /* 1584Mbps */
+               mmio_write_32(DBSC_DBRFCNF1,
+                             (REFRESH_RATE * 99 / 125) + 0x00080000);
+       } else {                /* 1856Mbps */
+               mmio_write_32(DBSC_DBRFCNF1,
+                             (REFRESH_RATE * 116 / 125) + 0x00080000);
+       }
+
+       mmio_write_32(DBSC_DBRFCNF2, 0x00010000);
+       mmio_write_32(DBSC_DBDFICUPDCNF, 0x40100001);
+       mmio_write_32(DBSC_DBRFEN, 0x00000001);
+       mmio_write_32(DBSC_DBACEN, 0x00000001);
+
+       if (pdqsr_ctl == 1) {
+               mmio_write_32(0xE67F0018, 0x00000001);
+               regval = mmio_read_32(0x40000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGD0, regval);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000100);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       }
+
+       /* PDR dynamic */
+       if (pdr_ctl == 1) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000103);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+       }
+
+       /*
+        * Initial_Step9( Initial End )
+        */
+       mmio_write_32(DBSC_DBPDLK0, 0x00000000);
+       mmio_write_32(DBSC_DBSYSCNT0, 0x00000000);
+
+#ifdef ddr_qos_init_setting /* only for non qos_init */
+       mmio_write_32(DBSC_DBSYSCNT0, 0x00001234);
+       mmio_write_32(DBSC_DBCAM0CNF1, 0x00043218);
+       mmio_write_32(DBSC_DBCAM0CNF2, 0x000000F4);
+       mmio_write_32(DBSC_DBSCHCNT0, 0x000f0037);
+       mmio_write_32(DBSC_DBSCHSZ0, 0x00000001);
+       mmio_write_32(DBSC_DBSCHRW0, 0x22421111);
+       mmio_write_32(DBSC_SCFCTST2, 0x012F1123);
+       mmio_write_32(DBSC_DBSCHQOS00, 0x00000F00);
+       mmio_write_32(DBSC_DBSCHQOS01, 0x00000B00);
+       mmio_write_32(DBSC_DBSCHQOS02, 0x00000000);
+       mmio_write_32(DBSC_DBSCHQOS03, 0x00000000);
+       mmio_write_32(DBSC_DBSCHQOS40, 0x00000300);
+       mmio_write_32(DBSC_DBSCHQOS41, 0x000002F0);
+       mmio_write_32(DBSC_DBSCHQOS42, 0x00000200);
+       mmio_write_32(DBSC_DBSCHQOS43, 0x00000100);
+       mmio_write_32(DBSC_DBSCHQOS90, 0x00000100);
+       mmio_write_32(DBSC_DBSCHQOS91, 0x000000F0);
+       mmio_write_32(DBSC_DBSCHQOS92, 0x000000A0);
+       mmio_write_32(DBSC_DBSCHQOS93, 0x00000040);
+       mmio_write_32(DBSC_DBSCHQOS130, 0x00000100);
+       mmio_write_32(DBSC_DBSCHQOS131, 0x000000F0);
+       mmio_write_32(DBSC_DBSCHQOS132, 0x000000A0);
+       mmio_write_32(DBSC_DBSCHQOS133, 0x00000040);
+       mmio_write_32(DBSC_DBSCHQOS140, 0x000000C0);
+       mmio_write_32(DBSC_DBSCHQOS141, 0x000000B0);
+       mmio_write_32(DBSC_DBSCHQOS142, 0x00000080);
+       mmio_write_32(DBSC_DBSCHQOS143, 0x00000040);
+       mmio_write_32(DBSC_DBSCHQOS150, 0x00000040);
+       mmio_write_32(DBSC_DBSCHQOS151, 0x00000030);
+       mmio_write_32(DBSC_DBSCHQOS152, 0x00000020);
+       mmio_write_32(DBSC_DBSCHQOS153, 0x00000010);
+
+       if (pdqsr_ctl == 0)
+               mmio_write_32(0xE67F0018, 0x00000001);
+
+       mmio_write_32(DBSC_DBSYSCNT0, 0x00000000);
 #endif
 
-   return 1;   /*  rev.0.04 Restore the return code */
-
-} /*  init_ddr */
+       return 1;
+}
 
-/*  rev.0.04 add function */
-uint32_t recovery_from_backup_mode(void)
+static uint32_t recovery_from_backup_mode(uint32_t ddr_backup)
 {
-   /****************************************************************************
-    *  recovery_Step0(DBSC Setting 1) / same "init_ddr"
-    ***************************************************************************/
-   uint32_t RegVal_R2, RegVal_R5, RegVal_R6, RegVal_R7, RegVal_R12, i;
-   uint32_t ddr_md;
-   uint32_t err;
-
-/* rev.0.08 */
-   uint32_t RegVal, j;
-   uint32_t dqsgd_0c, bdlcount_0c, bdlcount_0c_div2, bdlcount_0c_div4, bdlcount_0c_div8, bdlcount_0c_div16;
-   uint32_t gatesl_0c, rdqsd_0c, rdqsnd_0c, rbd_0c[4];
-   uint32_t pdqsr_ctl, lcdl_ctl, lcdl_judge1, lcdl_judge2;
-   /* rev.0.10 */
-   uint32_t pdr_ctl;
-   /* rev.0.11 */
-   uint32_t byp_ctl;
-
-/* rev.0.08 */
-   if ((ReadReg_32(0xFFF00044) & 0x000000FF) == 0x00000000) {
-     pdqsr_ctl  = 1;
-     lcdl_ctl   = 1;
-     pdr_ctl    = 1;  /* rev.0.10 */
-     byp_ctl    = 1;  /* rev.0.11 */
-    } else {
-     pdqsr_ctl  = 0;
-     lcdl_ctl   = 0;
-     pdr_ctl    = 0;  /* rev.0.10 */
-     byp_ctl    = 0;  /* rev.0.11 */
-   }
-
-   /*  Judge the DDR bit rate (ddr_md : 0 = 1584Mbps, 1 = 1856Mbps) */
-   ddr_md = (ReadReg_32(RST_MODEMR) >> 19) & BIT0;
-
-   /*  1584Mbps setting */
-   if (ddr_md == 0) {
-   /* CPG setting ===============================================*/
-   WriteReg_32(CPG_CPGWPR, 0x5A5AFFFF);
-   WriteReg_32(CPG_CPGWPCR, 0xA5A50000);
-
-   WriteReg_32(CPG_SRCR4, 0x20000000);
-
-   WriteReg_32(0xE61500DC, 0xe2200000);  /*  Change to 1584Mbps */
-   while ((BIT11 & ReadReg_32(CPG_PLLECR)) == 0);
-
-   WriteReg_32(CPG_SRSTCLR4, 0x20000000);
-
-   WriteReg_32(CPG_CPGWPCR, 0xA5A50001);
-
-   /* CPG setting ===============================================*/
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBSYSCNT0, 0x00001234);
-   WriteReg_32(DBSC_E3_DBKIND, 0x00000007);
+       /*
+        * recovery_Step0(DBSC Setting 1) / same "init_ddr"
+        */
+       uint32_t r2, r5, r6, r7, r12, i;
+       uint32_t ddr_md;
+       uint32_t err;
+       uint32_t regval, j;
+       uint32_t dqsgd_0c, bdlcount_0c, bdlcount_0c_div2, bdlcount_0c_div4;
+       uint32_t bdlcount_0c_div8, bdlcount_0c_div16;
+       uint32_t gatesl_0c, rdqsd_0c, rdqsnd_0c, rbd_0c[4];
+       uint32_t pdqsr_ctl, lcdl_ctl, lcdl_judge1, lcdl_judge2;
+       uint32_t pdr_ctl;
+       uint32_t byp_ctl;
+
+       if ((mmio_read_32(0xFFF00044) & 0x000000FF) == 0x00000000) {
+               pdqsr_ctl = 1;
+               lcdl_ctl = 1;
+               pdr_ctl = 1;
+               byp_ctl = 1;
+       } else {
+               pdqsr_ctl = 0;
+               lcdl_ctl = 0;
+               pdr_ctl = 0;
+               byp_ctl = 0;
+       }
+
+       /* Judge the DDR bit rate (ddr_md : 0 = 1584Mbps, 1 = 1856Mbps) */
+       ddr_md = (mmio_read_32(RST_MODEMR) >> 19) & BIT(0);
+
+       /* 1584Mbps setting */
+       if (ddr_md == 0) {
+               mmio_write_32(CPG_CPGWPR, 0x5A5AFFFF);
+               mmio_write_32(CPG_CPGWPCR, 0xA5A50000);
+
+               mmio_write_32(CPG_SRCR4, 0x20000000);
+
+               mmio_write_32(0xE61500DC, 0xe2200000);  /* Change to 1584Mbps */
+               while (!(mmio_read_32(CPG_PLLECR) & BIT(11)))
+                       ;
+
+               mmio_write_32(CPG_SRSTCLR4, 0x20000000);
+
+               mmio_write_32(CPG_CPGWPCR, 0xA5A50001);
+       }
+
+       mmio_write_32(DBSC_DBSYSCNT0, 0x00001234);
+       mmio_write_32(DBSC_DBKIND, 0x00000007);
 
 #if RCAR_DRAM_DDR3L_MEMCONF == 0
-   WriteReg_32(DBSC_E3_DBMEMCONF00, 0x0f030a02);
-#elif RCAR_DRAM_DDR3L_MEMCONF == 1
-   WriteReg_32(DBSC_E3_DBMEMCONF00, 0x10030a02);
-#elif RCAR_DRAM_DDR3L_MEMCONF == 2
-   WriteReg_32(DBSC_E3_DBMEMCONF00, 0x10030b02);
+       mmio_write_32(DBSC_DBMEMCONF00, 0x0f030a02);
 #else
-   WriteReg_32(DBSC_E3_DBMEMCONF00, 0x10030a02);
+       mmio_write_32(DBSC_DBMEMCONF00, 0x10030a02);
 #endif
 
-/* rev.0.08 */
 #if RCAR_DRAM_DDR3L_MEMDUAL == 1
-        RegVal_R2 = (ReadReg_32(0xE6790614));
-         WriteReg_32(0xE6790614, RegVal_R2 | 0x00000003); /*  MCS1_N/MODT1 are activated. */
+       r2 = mmio_read_32(0xE6790614);
+       mmio_write_32(0xE6790614, r2 | 0x3); /* MCS1_N/MODT1 are activated. */
 #endif
 
-   WriteReg_32(DBSC_E3_DBPHYCONF0, 0x00000001);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBTR0, 0x0000000B);
-      WriteReg_32(DBSC_E3_DBTR1, 0x00000008);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBTR0, 0x0000000D);
-      WriteReg_32(DBSC_E3_DBTR1, 0x00000009);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBTR2, 0x00000000);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBTR3, 0x0000000B);
-      WriteReg_32(DBSC_E3_DBTR4, 0x000B000B);
-      WriteReg_32(DBSC_E3_DBTR5, 0x00000027);
-      WriteReg_32(DBSC_E3_DBTR6, 0x0000001C);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBTR3, 0x0000000D);
-      WriteReg_32(DBSC_E3_DBTR4, 0x000D000D);
-      WriteReg_32(DBSC_E3_DBTR5, 0x0000002D);
-      WriteReg_32(DBSC_E3_DBTR6, 0x00000020);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBTR7, 0x00060006);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBTR8, 0x00000020);
-      WriteReg_32(DBSC_E3_DBTR9, 0x00000006);
-      WriteReg_32(DBSC_E3_DBTR10, 0x0000000C);
-      WriteReg_32(DBSC_E3_DBTR11, 0x0000000A);
-      WriteReg_32(DBSC_E3_DBTR12, 0x00120012);
-      WriteReg_32(DBSC_E3_DBTR13, 0x000000CE);
-      WriteReg_32(DBSC_E3_DBTR14, 0x00140005);
-      WriteReg_32(DBSC_E3_DBTR15, 0x00050004);
-      WriteReg_32(DBSC_E3_DBTR16, 0x071F0305);
-      WriteReg_32(DBSC_E3_DBTR17, 0x040C0000);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBTR8, 0x00000021);
-      WriteReg_32(DBSC_E3_DBTR9, 0x00000007);
-      WriteReg_32(DBSC_E3_DBTR10, 0x0000000E);
-      WriteReg_32(DBSC_E3_DBTR11, 0x0000000C);
-      WriteReg_32(DBSC_E3_DBTR12, 0x00140014);
-      WriteReg_32(DBSC_E3_DBTR13, 0x000000F2);
-      WriteReg_32(DBSC_E3_DBTR14, 0x00170006);
-      WriteReg_32(DBSC_E3_DBTR15, 0x00060005);
-      WriteReg_32(DBSC_E3_DBTR16, 0x09210507);
-      WriteReg_32(DBSC_E3_DBTR17, 0x040E0000);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBTR18, 0x00000200);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBTR19, 0x01000040);
-      WriteReg_32(DBSC_E3_DBTR20, 0x020000D6);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBTR19, 0x0129004B);
-      WriteReg_32(DBSC_E3_DBTR20, 0x020000FB);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBTR21, 0x00040004);
-   WriteReg_32(DBSC_E3_DBBL, 0x00000000);
-   WriteReg_32(DBSC_E3_DBODT0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBADJ0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBSYSCONF1, 0x00000002);
-   WriteReg_32(DBSC_E3_DBDFICNT0, 0x00000010);
-   WriteReg_32(DBSC_E3_DBBCAMDIS, 0x00000001);
-   WriteReg_32(DBSC_E3_DBSCHRW1, 0x00000046);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_SCFCTST0, 0x0D050B03);
-      WriteReg_32(DBSC_E3_SCFCTST1, 0x0306030C);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_SCFCTST0, 0x0C050B03);
-      WriteReg_32(DBSC_E3_SCFCTST1, 0x0305030C);
-   } /*  ddr_md */
-
-   /****************************************************************************
-    *  recovery_Step1(PHY setting 1)
-    ***************************************************************************/
-   WriteReg_32(DBSC_E3_DBPDLK0, 0x0000A55A);
-   WriteReg_32(DBSC_E3_DBCMD, 0x01840001);
-   WriteReg_32(DBSC_E3_DBCMD, 0x0A840000);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000008); /*  DDR_PLLCR */
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x000B8000);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000003); /*  DDR_PGCR1 */
-   if (byp_ctl == 1) {
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x0780C720);
-   } else {
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x0780C700);
-   }
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000020); /*  DDR_DXCCR */
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00181884);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x0000001A); /*  DDR_ACIOCR0 */
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x33C03C10);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000007);
-   while ((BIT30 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000004);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, (uint32_t)(REFRESH_RATE * 792 / 125) - 400 + 0x08B00000);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, (uint32_t)(REFRESH_RATE * 928 / 125) - 400 + 0x0A300000);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000022);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x1000040B);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000023);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x2D9C0B66);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x35A00D77);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000024);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x2A88B400);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x2A8A2C28);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000025);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x30005200);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x30005E00);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000026);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x0014A9C9);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x0014CB49);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000027);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000D70);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000F14);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000028);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000046);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000029);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      if (REFRESH_RATE > 3900) {
-          WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000018);  /*            [7]SRT=0 */
-      } else {
-          WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000098);  /*            [7]SRT=1 */
-      }
-   } else {                                        /*  1856Mbps */
-      if (REFRESH_RATE > 3900) {
-          WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000020);  /*            [7]SRT=0 */
-      } else {
-          WriteReg_32(DBSC_E3_DBPDRGD0, 0x000000A0);  /*            [7]SRT=1 */
-      } /*  REFRESH_RATE */
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x0000002C);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x81003047);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000091);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0007BB6B);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000095);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0007BBAD);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000099);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0007BB6B);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000021); /*  DDR_DSGCR */
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0024641E);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006); /*  DDR_PGSR0 */
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001); /*  DDR_PIR */
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x40010000);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006); /*  DDR_PGSR0 */
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000092); /*  DDR_ZQ0DR */
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0xC2C59AB5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000096); /*  DDR_ZQ1DR */
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0xC4285FBF);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x0000009A); /*  DDR_ZQ2DR */
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0xC2C59AB5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000090); /*  DDR_ZQCR */
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x0C058900);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x0C058A00);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000090); /*  DDR_ZQCR */
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x04058900);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x04058A00);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001); /*  DDR_PIR */
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00050001);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006); /*  DDR_PGSR0 */
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   /*  ddr backupmode end */
-   if (ddrBackup) {
-      NOTICE("BL2: [WARM_BOOT]\n");
-   } else {
-      NOTICE("BL2: [COLD_BOOT]\n");
-   } /*  ddrBackup */
-   err = rcar_dram_update_boot_status(ddrBackup);
-   if (err) {
-      NOTICE("BL2: [BOOT_STATUS_UPDATE_ERROR]\n");
-      return INITDRAM_ERR_I;
-   } /*  err */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000092); /*  DDR_ZQ0DR */
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x02C59AB5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000096); /*  DDR_ZQ1DR */
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x04285FBF);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x0000009A); /*  DDR_ZQ2DR */
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x02C59AB5);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001); /*  DDR_PIR */
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x08000000);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001); /*  DDR_PIR */
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000003);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006); /*  DDR_PGSR0 */
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001); /*  DDR_PIR */
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x80010000);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006); /*  DDR_PGSR0 */
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001); /*  DDR_PIR */
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00010073);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006); /*  DDR_PGSR0 */
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000090); /*  DDR_ZQCR */
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x0C058900);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x0C058A00);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000090); /*  DDR_ZQCR */
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x04058900);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x04058A00);
-   } /*  ddr_md */
-
-/* rev0.08 */
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x0000000C);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x18000040);
-
-   /****************************************************************************
-    *  recovery_Step2(PHY setting 2)
-    ***************************************************************************/
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A7);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0D0D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A8);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0D0D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A9);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x000D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C7);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0D0D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C8);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0D0D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C9);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x000D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E7);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0D0D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E8);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0D0D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E9);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x000D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000107);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0D0D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000108);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0D0D0D0D);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000109);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x000D0D0D);
-
-   WriteReg_32(DBSC_E3_DBCALCNF, (uint32_t)(64000000 / REFRESH_RATE) + 0x01000000);
-   WriteReg_32(DBSC_E3_DBBUS0CNF1, 0x00000010);
-
-   /*  Select setting value in bps */
-   if (ddr_md == 0) {                                 /*  1584Mbps */
-      WriteReg_32(DBSC_E3_DBRFCNF1, (uint32_t)(REFRESH_RATE * 99 / 125) + 0x00080000);
-   } else {                                        /*  1856Mbps */
-      WriteReg_32(DBSC_E3_DBRFCNF1, (uint32_t)(REFRESH_RATE * 116 / 125) + 0x00080000);
-   } /*  ddr_md */
-
-   WriteReg_32(DBSC_E3_DBRFCNF2, 0x00010000);
-   WriteReg_32(DBSC_E3_DBRFEN, 0x00000001);
-   WriteReg_32(DBSC_E3_DBCMD, 0x0A840001);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBWAIT)) != 0);
-
-   WriteReg_32(DBSC_E3_DBCMD, 0x00000000);
-
-   WriteReg_32(DBSC_E3_DBCMD, 0x04840010);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBWAIT)) != 0);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006); /*  DDR_PGSR0 */
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001); /*  DDR_PIR */
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00010701);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006); /*  DDR_PGSR0 */
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   for (i = 0; i < 4; i++)
-   {
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B1 + i * 0x20);
-      RegVal_R5 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0x0000FF00) >> 0x8;
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B4 + i * 0x20);
-      RegVal_R6 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0x000000FF);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B3 + i * 0x20);
-      RegVal_R7 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0x00000007);
-
-      if (RegVal_R6 > 0) {
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-        RegVal_R2 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFFF8);
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-         WriteReg_32(DBSC_E3_DBPDRGD0, RegVal_R2 | ((RegVal_R7 + 0x1) & 0x00000007));
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-        RegVal_R2 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFF00);
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-         WriteReg_32(DBSC_E3_DBPDRGD0, RegVal_R2 | RegVal_R6);
-      } else {
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-        RegVal_R2 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFFF8);
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-         WriteReg_32(DBSC_E3_DBPDRGD0, RegVal_R2 | RegVal_R7);
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-        RegVal_R2 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFF00);
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-         WriteReg_32(DBSC_E3_DBPDRGD0, RegVal_R2 | ((RegVal_R6 + ((RegVal_R5) << 1)) & 0x000000FF));
-      } /*  RegVal_R6 */
-   } /*  for i */
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000005);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0xC1AA00C0);
-
-   /* rev.0.08 */
-   if (pdqsr_ctl == 1){} else {
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000100);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   }
-
-   /* PDR always off */        /* rev.0.10 */
-   if (pdr_ctl == 1) {
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000103);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-   }
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00010801);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000005);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0xC1AA00D8);
-
-   /* rev.0.08 */
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00011001);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-if (pdqsr_ctl == 1) {
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000100);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-}
-
-   /* PDR dynamic */   /* rev.0.10 */
-   if (pdr_ctl == 1) {
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000103);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-   }
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00012001);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-if (pdqsr_ctl == 1) {
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C000285);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C000285);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C000285);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000100);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C000285);
-}
-
-   /* PDR always off */        /* rev.0.10 */
-   if (pdr_ctl == 1) {
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000103);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-   }
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00014001);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-if (pdqsr_ctl == 1) {
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000100);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-}
-
-   /* PDR dynamic */   /* rev.0.10 */
-   if (pdr_ctl == 1) {
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000103);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-   }
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00018001);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C000285);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C000285);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C000285);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000100);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C000285);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x0000002C);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x81003087);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00010401);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-   for (i = 0; i < 4; i++) {
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B1 + i * 0x20);
-      RegVal_R5 = ((ReadReg_32(DBSC_E3_DBPDRGD0) & 0x0000FF00) >> 0x8);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B4 + i * 0x20);
-      RegVal_R6 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0x000000FF);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B3 + i * 0x20);
-      RegVal_R7 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0x00000007);
-      RegVal_R12 = (RegVal_R5 >> 0x2);
-
-      if (RegVal_R12 < RegVal_R6) {
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-        RegVal_R2 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFFF8);
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-         WriteReg_32(DBSC_E3_DBPDRGD0, RegVal_R2 | ((RegVal_R7 + 0x1) & 0x00000007));
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-        RegVal_R2 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFF00);
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-         WriteReg_32(DBSC_E3_DBPDRGD0, RegVal_R2 | ((RegVal_R6 - (RegVal_R12)) & 0x000000FF));
-      } else {
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-        RegVal_R2 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFFF8);
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-         WriteReg_32(DBSC_E3_DBPDRGD0, RegVal_R2 | (RegVal_R7 & 0x00000007));
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-        RegVal_R2 = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFF00);
-         WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-         WriteReg_32(DBSC_E3_DBPDRGD0, RegVal_R2 | ((RegVal_R6 + (RegVal_R5) + ((RegVal_R5) >> 1) + (RegVal_R12)) & 0x000000FF));
-      } /*  RegVal_R12 < RegVal_R6 */
-   } /*  for i */
-
-/* rev.0.08 */
-   if (pdqsr_ctl == 1){} else {
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000100);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   }
-
-   /* PDR always off */        /* rev.0.10 */
-   if (pdr_ctl == 1) {
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000103);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000008);
-   }
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x00015001);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000006);
-   while ((BIT0 & ReadReg_32(DBSC_E3_DBPDRGD0)) == 0);
-
-/* rev.0.08 */
-   if (lcdl_ctl == 1) {
-       for (i = 0; i < 4; i++) {
-          WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-         dqsgd_0c = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0x000000FF);
-          WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B1 + i * 0x20);
-         bdlcount_0c = ((ReadReg_32(DBSC_E3_DBPDRGD0) & 0x0000FF00) >> 8);
-         bdlcount_0c_div2  = (bdlcount_0c >> 1);
-         bdlcount_0c_div4  = (bdlcount_0c >> 2);
-         bdlcount_0c_div8  = (bdlcount_0c >> 3);
-         bdlcount_0c_div16 = (bdlcount_0c >> 4);
-
-          if (ddr_md == 0) {                                 /*  1584Mbps */
-            lcdl_judge1 = bdlcount_0c_div2 + bdlcount_0c_div4 + bdlcount_0c_div8;
-            lcdl_judge2 = bdlcount_0c + bdlcount_0c_div4 + bdlcount_0c_div16;
-         } else {                                        /*  1856Mbps */
-            lcdl_judge1 = bdlcount_0c_div2 + bdlcount_0c_div4;
-            lcdl_judge2 = bdlcount_0c + bdlcount_0c_div4;
-         } /*  ddr_md */
-
-         if (dqsgd_0c > lcdl_judge1) {
-            if (dqsgd_0c <= lcdl_judge2) {
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-               RegVal = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFF00);
-                WriteReg_32(DBSC_E3_DBPDRGD0, ((dqsgd_0c - bdlcount_0c_div8) | RegVal));
-             } else {
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B0 + i * 0x20);
-               RegVal = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFF00);
-               WriteReg_32(DBSC_E3_DBPDRGD0, RegVal);
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-               gatesl_0c = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0x00000007);
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000B2 + i * 0x20);
-               RegVal = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xFFFFFFF8);
-                WriteReg_32(DBSC_E3_DBPDRGD0, (RegVal | (gatesl_0c + 1)));
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000AF + i * 0x20);
-               RegVal = (ReadReg_32(DBSC_E3_DBPDRGD0));
-               rdqsd_0c = (RegVal & 0x0000FF00) >> 8;
-               rdqsnd_0c = (RegVal & 0x00FF0000) >> 16;
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000AF + i * 0x20);
-                WriteReg_32(DBSC_E3_DBPDRGD0, ((RegVal & 0xFF0000FF) | ((rdqsd_0c + bdlcount_0c_div4) << 8) | ((rdqsnd_0c + bdlcount_0c_div4) << 16)));
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000AA + i * 0x20);
-               RegVal = (ReadReg_32(DBSC_E3_DBPDRGD0));
-                rbd_0c[0] = (RegVal) &0x0000001f;
-               rbd_0c[1] = (RegVal >>  8) & 0x0000001f;
-               rbd_0c[2] = (RegVal >> 16) & 0x0000001f;
-               rbd_0c[3] = (RegVal >> 24) & 0x0000001f;
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000AA + i * 0x20);
-               RegVal = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xE0E0E0E0);
-                for (j = 0; j < 4; j++) {
-                   rbd_0c[j] = (rbd_0c[j] + bdlcount_0c_div4);
-                   if (rbd_0c[j] > 0x1F) rbd_0c[j] = 0x1F;
-                    RegVal = RegVal | (rbd_0c[j] << 8 * j);
+       mmio_write_32(DBSC_DBPHYCONF0, 0x00000001);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0) {      /* 1584Mbps */
+               mmio_write_32(DBSC_DBTR0, 0x0000000B);
+               mmio_write_32(DBSC_DBTR1, 0x00000008);
+       } else {                /* 1856Mbps */
+               mmio_write_32(DBSC_DBTR0, 0x0000000D);
+               mmio_write_32(DBSC_DBTR1, 0x00000009);
+       }
+
+       mmio_write_32(DBSC_DBTR2, 0x00000000);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0) {      /* 1584Mbps */
+               mmio_write_32(DBSC_DBTR3, 0x0000000B);
+               mmio_write_32(DBSC_DBTR4, 0x000B000B);
+               mmio_write_32(DBSC_DBTR5, 0x00000027);
+               mmio_write_32(DBSC_DBTR6, 0x0000001C);
+       } else {                /* 1856Mbps */
+               mmio_write_32(DBSC_DBTR3, 0x0000000D);
+               mmio_write_32(DBSC_DBTR4, 0x000D000D);
+               mmio_write_32(DBSC_DBTR5, 0x0000002D);
+               mmio_write_32(DBSC_DBTR6, 0x00000020);
+       }
+
+       mmio_write_32(DBSC_DBTR7, 0x00060006);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0) {      /* 1584Mbps */
+               mmio_write_32(DBSC_DBTR8, 0x00000020);
+               mmio_write_32(DBSC_DBTR9, 0x00000006);
+               mmio_write_32(DBSC_DBTR10, 0x0000000C);
+               mmio_write_32(DBSC_DBTR11, 0x0000000A);
+               mmio_write_32(DBSC_DBTR12, 0x00120012);
+               mmio_write_32(DBSC_DBTR13, 0x000000CE);
+               mmio_write_32(DBSC_DBTR14, 0x00140005);
+               mmio_write_32(DBSC_DBTR15, 0x00050004);
+               mmio_write_32(DBSC_DBTR16, 0x071F0305);
+               mmio_write_32(DBSC_DBTR17, 0x040C0000);
+       } else {                /* 1856Mbps */
+               mmio_write_32(DBSC_DBTR8, 0x00000021);
+               mmio_write_32(DBSC_DBTR9, 0x00000007);
+               mmio_write_32(DBSC_DBTR10, 0x0000000E);
+               mmio_write_32(DBSC_DBTR11, 0x0000000C);
+               mmio_write_32(DBSC_DBTR12, 0x00140014);
+               mmio_write_32(DBSC_DBTR13, 0x000000F2);
+               mmio_write_32(DBSC_DBTR14, 0x00170006);
+               mmio_write_32(DBSC_DBTR15, 0x00060005);
+               mmio_write_32(DBSC_DBTR16, 0x09210507);
+               mmio_write_32(DBSC_DBTR17, 0x040E0000);
+       }
+
+       mmio_write_32(DBSC_DBTR18, 0x00000200);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0) {      /* 1584Mbps */
+               mmio_write_32(DBSC_DBTR19, 0x01000040);
+               mmio_write_32(DBSC_DBTR20, 0x020000D6);
+       } else {                /* 1856Mbps */
+               mmio_write_32(DBSC_DBTR19, 0x0129004B);
+               mmio_write_32(DBSC_DBTR20, 0x020000FB);
+       }
+
+       mmio_write_32(DBSC_DBTR21, 0x00040004);
+       mmio_write_32(DBSC_DBBL, 0x00000000);
+       mmio_write_32(DBSC_DBODT0, 0x00000001);
+       mmio_write_32(DBSC_DBADJ0, 0x00000001);
+       mmio_write_32(DBSC_DBSYSCONF1, 0x00000002);
+       mmio_write_32(DBSC_DBDFICNT0, 0x00000010);
+       mmio_write_32(DBSC_DBBCAMDIS, 0x00000001);
+       mmio_write_32(DBSC_DBSCHRW1, 0x00000046);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0) {      /* 1584Mbps */
+               mmio_write_32(DBSC_SCFCTST0, 0x0D050B03);
+               mmio_write_32(DBSC_SCFCTST1, 0x0306030C);
+       } else {                /* 1856Mbps */
+               mmio_write_32(DBSC_SCFCTST0, 0x0C050B03);
+               mmio_write_32(DBSC_SCFCTST1, 0x0305030C);
+       }
+
+       /*
+        * recovery_Step1(PHY setting 1)
+        */
+       mmio_write_32(DBSC_DBPDLK0, 0x0000A55A);
+       mmio_write_32(DBSC_DBCMD, 0x01840001);
+       mmio_write_32(DBSC_DBCMD, 0x0A840000);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000008);       /* DDR_PLLCR */
+       mmio_write_32(DBSC_DBPDRGD0, 0x000B8000);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000003);       /* DDR_PGCR1 */
+       if (byp_ctl == 1)
+               mmio_write_32(DBSC_DBPDRGD0, 0x0780C720);
+       else
+               mmio_write_32(DBSC_DBPDRGD0, 0x0780C700);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000020);       /* DDR_DXCCR */
+       mmio_write_32(DBSC_DBPDRGD0, 0x00181884);
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000001A);       /* DDR_ACIOCR0 */
+       mmio_write_32(DBSC_DBPDRGD0, 0x33C03C10);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000007);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(30)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000004);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0) {      /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, (REFRESH_RATE * 792 / 125) -
+                                            400 + 0x08B00000);
+       } else {                /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, (REFRESH_RATE * 928 / 125) -
+                                            400 + 0x0A300000);
+       }
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000022);
+       mmio_write_32(DBSC_DBPDRGD0, 0x1000040B);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000023);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0)        /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x2D9C0B66);
+       else                    /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x35A00D77);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000024);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0)        /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x2A88B400);
+       else                    /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x2A8A2C28);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000025);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0)        /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x30005200);
+       else                    /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x30005E00);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000026);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0)        /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x0014A9C9);
+       else                    /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x0014CB49);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000027);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0)        /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000D70);
+       else                    /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000F14);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000028);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00000046);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000029);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0) {      /* 1584Mbps */
+               if (REFRESH_RATE > 3900)
+                       mmio_write_32(DBSC_DBPDRGD0, 0x18);     /* [7]SRT=0 */
+               else
+                       mmio_write_32(DBSC_DBPDRGD0, 0x98);     /* [7]SRT=1 */
+       } else {        /* 1856Mbps */
+               if (REFRESH_RATE > 3900)
+                       mmio_write_32(DBSC_DBPDRGD0, 0x20);     /* [7]SRT=0 */
+               else
+                       mmio_write_32(DBSC_DBPDRGD0, 0xA0);     /* [7]SRT=1 */
+       }
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000002C);
+       mmio_write_32(DBSC_DBPDRGD0, 0x81003047);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000091);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0007BB6B);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000095);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0007BBAD);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000099);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0007BB6B);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000021);       /* DDR_DSGCR */
+       mmio_write_32(DBSC_DBPDRGD0, 0x0024641E);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);       /* DDR_PGSR0 */
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);       /* DDR_PIR */
+       mmio_write_32(DBSC_DBPDRGD0, 0x40010000);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);       /* DDR_PGSR0 */
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000092);       /* DDR_ZQ0DR */
+       mmio_write_32(DBSC_DBPDRGD0, 0xC2C59AB5);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000096);       /* DDR_ZQ1DR */
+       mmio_write_32(DBSC_DBPDRGD0, 0xC4285FBF);
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000009A);       /* DDR_ZQ2DR */
+       mmio_write_32(DBSC_DBPDRGD0, 0xC2C59AB5);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);       /* DDR_ZQCR */
+
+       /* Select setting value in bps */
+       if (ddr_md == 0)        /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x0C058900);
+       else                    /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x0C058A00);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);       /* DDR_ZQCR */
+
+       /* Select setting value in bps */
+       if (ddr_md == 0)        /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x04058900);
+       else                    /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x04058A00);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);       /* DDR_PIR */
+       mmio_write_32(DBSC_DBPDRGD0, 0x00050001);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);       /* DDR_PGSR0 */
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       /* ddr backupmode end */
+       if (ddr_backup)
+               NOTICE("BL2: [WARM_BOOT]\n");
+       else
+               NOTICE("BL2: [COLD_BOOT]\n");
+
+       err = rcar_dram_update_boot_status(ddr_backup);
+       if (err) {
+               NOTICE("BL2: [BOOT_STATUS_UPDATE_ERROR]\n");
+               return INITDRAM_ERR_I;
+       }
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000092);       /* DDR_ZQ0DR */
+       mmio_write_32(DBSC_DBPDRGD0, 0x02C59AB5);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000096);       /* DDR_ZQ1DR */
+       mmio_write_32(DBSC_DBPDRGD0, 0x04285FBF);
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000009A);       /* DDR_ZQ2DR */
+       mmio_write_32(DBSC_DBPDRGD0, 0x02C59AB5);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);       /* DDR_PIR */
+       mmio_write_32(DBSC_DBPDRGD0, 0x08000000);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);       /* DDR_PIR */
+       mmio_write_32(DBSC_DBPDRGD0, 0x00000003);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);       /* DDR_PGSR0 */
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);       /* DDR_PIR */
+       mmio_write_32(DBSC_DBPDRGD0, 0x80010000);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);       /* DDR_PGSR0 */
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);       /* DDR_PIR */
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010073);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);       /* DDR_PGSR0 */
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);       /* DDR_ZQCR */
+
+       /* Select setting value in bps */
+       if (ddr_md == 0)        /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x0C058900);
+       else                    /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x0C058A00);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);       /* DDR_ZQCR */
+
+       /* Select setting value in bps */
+       if (ddr_md == 0)        /* 1584Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x04058900);
+       else                    /* 1856Mbps */
+               mmio_write_32(DBSC_DBPDRGD0, 0x04058A00);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000000C);
+       mmio_write_32(DBSC_DBPDRGD0, 0x18000040);
+
+       /*
+        * recovery_Step2(PHY setting 2)
+        */
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A7);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A8);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A9);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C7);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C8);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C9);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000E7);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000E8);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000E9);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000107);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000108);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000109);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000D0D0D);
+
+       mmio_write_32(DBSC_DBCALCNF, (64000000 / REFRESH_RATE) + 0x01000000);
+       mmio_write_32(DBSC_DBBUS0CNF1, 0x00000010);
+
+       /* Select setting value in bps */
+       if (ddr_md == 0) {      /* 1584Mbps */
+               mmio_write_32(DBSC_DBRFCNF1,
+                             (REFRESH_RATE * 99 / 125) + 0x00080000);
+       } else {                        /* 1856Mbps */
+               mmio_write_32(DBSC_DBRFCNF1,
+                             (REFRESH_RATE * 116 / 125) + 0x00080000);
+       }
+
+       mmio_write_32(DBSC_DBRFCNF2, 0x00010000);
+       mmio_write_32(DBSC_DBRFEN, 0x00000001);
+       mmio_write_32(DBSC_DBCMD, 0x0A840001);
+       while (mmio_read_32(DBSC_DBWAIT) & BIT(0))
+               ;
+
+       mmio_write_32(DBSC_DBCMD, 0x00000000);
+
+       mmio_write_32(DBSC_DBCMD, 0x04840010);
+       while (mmio_read_32(DBSC_DBWAIT) & BIT(0))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);       /* DDR_PGSR0 */
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);       /* DDR_PIR */
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010701);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);       /* DDR_PGSR0 */
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       for (i = 0; i < 4; i++) {
+               mmio_write_32(DBSC_DBPDRGA0, 0xB1 + i * 0x20);
+               r5 = (mmio_read_32(DBSC_DBPDRGD0) & 0xFF00) >> 0x8;
+               mmio_write_32(DBSC_DBPDRGA0, 0xB4 + i * 0x20);
+               r6 = mmio_read_32(DBSC_DBPDRGD0) & 0xFF;
+               mmio_write_32(DBSC_DBPDRGA0, 0xB3 + i * 0x20);
+               r7 = mmio_read_32(DBSC_DBPDRGD0) & 0x7;
+
+               if (r6 > 0) {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | ((r7 + 0x1) & 0x7));
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | r6);
+               } else {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | r7);
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0,
+                                     r2 | ((r6 + (r5 << 1)) & 0xFF));
                }
-               WriteReg_32(DBSC_E3_DBPDRGD0, RegVal);
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000AB + i * 0x20);
-               RegVal = (ReadReg_32(DBSC_E3_DBPDRGD0));
-                rbd_0c[0] = (RegVal) &0x0000001f;
-               rbd_0c[1] = (RegVal >>  8) & 0x0000001f;
-               rbd_0c[2] = (RegVal >> 16) & 0x0000001f;
-               rbd_0c[3] = (RegVal >> 24) & 0x0000001f;
-               WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000AB + i * 0x20);
-               RegVal = (ReadReg_32(DBSC_E3_DBPDRGD0) & 0xE0E0E0E0);
-                for (j = 0; j < 4; j++) {
-                   rbd_0c[j] = (rbd_0c[j] + bdlcount_0c_div4);
-                   if (rbd_0c[j] > 0x1F) rbd_0c[j] = 0x1F;
-                    RegVal = RegVal | (rbd_0c[j] << 8 * j);
+       }
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000005);
+       mmio_write_32(DBSC_DBPDRGD0, 0xC1AA00C0);
+
+       if (pdqsr_ctl == 0) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000100);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       }
+
+       /* PDR always off */
+       if (pdr_ctl == 1) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000103);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+       }
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010801);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000005);
+       mmio_write_32(DBSC_DBPDRGD0, 0xC1AA00D8);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00011001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       if (pdqsr_ctl == 1) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000100);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       }
+
+       /* PDR dynamic */
+       if (pdr_ctl == 1) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000103);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+       }
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00012001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       if (pdqsr_ctl == 1) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000100);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+       }
+
+       /* PDR always off */
+       if (pdr_ctl == 1) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000103);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+       }
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00014001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       if (pdqsr_ctl == 1) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000100);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       }
+
+       /* PDR dynamic */
+       if (pdr_ctl == 1) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000103);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+       }
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00018001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000E0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000100);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000002C);
+       mmio_write_32(DBSC_DBPDRGD0, 0x81003087);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010401);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       for (i = 0; i < 4; i++) {
+               mmio_write_32(DBSC_DBPDRGA0, 0xB1 + i * 0x20);
+               r5 = ((mmio_read_32(DBSC_DBPDRGD0) & 0xFF00) >> 0x8);
+               mmio_write_32(DBSC_DBPDRGA0, 0xB4 + i * 0x20);
+               r6 = mmio_read_32(DBSC_DBPDRGD0) & 0xFF;
+               mmio_write_32(DBSC_DBPDRGA0, 0xB3 + i * 0x20);
+               r7 = mmio_read_32(DBSC_DBPDRGD0) & 0x7;
+               r12 = r5 >> 0x2;
+
+               if (r12 < r6) {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | ((r7 + 0x1) & 0x7));
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | ((r6 - r12) & 0xFF));
+               } else {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | (r7 & 0x7));
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00;
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0,
+                                     r2 |
+                                     ((r6 + r5 + (r5 >> 1) + r12) & 0xFF));
                }
-               WriteReg_32(DBSC_E3_DBPDRGD0, RegVal);
-            }
-         }
-       }
-       WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000002);
-       WriteReg_32(DBSC_E3_DBPDRGD0, 0x07D81E37);
-   }
-
-
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000003);
-   if (byp_ctl == 1) {
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x0380C720);
-   } else {
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x0380C700);
-   }
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000007);
-   while ((BIT30 & ReadReg_32(DBSC_E3_DBPDRGD0)) != 0);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000021);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x0024643E);
-
-   /****************************************************************************
-    *  recovery_Step3(DBSC Setting 2)
-    ***************************************************************************/
-   WriteReg_32(DBSC_E3_DBDFICUPDCNF, 0x40100001);
-   WriteReg_32(DBSC_E3_DBACEN, 0x00000001);
-
-/* rev.0.08 */
-   if (pdqsr_ctl == 1) {
-   WriteReg_32(0xE67F0018, 0x00000001);
-   RegVal = ReadReg_32(0x40000000);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000000);
-   WriteReg_32(DBSC_E3_DBPDRGD0, RegVal);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E0);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000100);
-   WriteReg_32(DBSC_E3_DBPDRGD0, 0x7C0002C5);
-   }
-
-   /* PDR dynamic */   /* rev.0.10 */
-   if (pdr_ctl == 1) {
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000A3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000C3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x000000E3);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-      WriteReg_32(DBSC_E3_DBPDRGA0, 0x00000103);
-      WriteReg_32(DBSC_E3_DBPDRGD0, 0x00000000);
-   }
-
-   WriteReg_32(DBSC_E3_DBPDLK0, 0x00000000);
-   WriteReg_32(DBSC_E3_DBSYSCNT0, 0x00000000);
-
-#ifdef ddr_qos_init_setting /*  only for non qos_init */
-   WriteReg_32(DBSC_E3_DBSYSCNT0, 0x00001234);
-   WriteReg_32(DBSC_E3_DBCAM0CNF1, 0x00043218);
-   WriteReg_32(DBSC_E3_DBCAM0CNF2, 0x000000F4);
-   WriteReg_32(DBSC_E3_DBSCHCNT0, 0x000f0037);
-   WriteReg_32(DBSC_E3_DBSCHSZ0, 0x00000001);
-   WriteReg_32(DBSC_E3_DBSCHRW0, 0x22421111);
-   WriteReg_32(DBSC_E3_SCFCTST2, 0x012F1123);
-   WriteReg_32(DBSC_E3_DBSCHQOS00, 0x00000F00);
-   WriteReg_32(DBSC_E3_DBSCHQOS01, 0x00000B00);
-   WriteReg_32(DBSC_E3_DBSCHQOS02, 0x00000000);
-   WriteReg_32(DBSC_E3_DBSCHQOS03, 0x00000000);
-   WriteReg_32(DBSC_E3_DBSCHQOS40, 0x00000300);
-   WriteReg_32(DBSC_E3_DBSCHQOS41, 0x000002F0);
-   WriteReg_32(DBSC_E3_DBSCHQOS42, 0x00000200);
-   WriteReg_32(DBSC_E3_DBSCHQOS43, 0x00000100);
-   WriteReg_32(DBSC_E3_DBSCHQOS90, 0x00000100);
-   WriteReg_32(DBSC_E3_DBSCHQOS91, 0x000000F0);
-   WriteReg_32(DBSC_E3_DBSCHQOS92, 0x000000A0);
-   WriteReg_32(DBSC_E3_DBSCHQOS93, 0x00000040);
-   WriteReg_32(DBSC_E3_DBSCHQOS130, 0x00000100);
-   WriteReg_32(DBSC_E3_DBSCHQOS131, 0x000000F0);
-   WriteReg_32(DBSC_E3_DBSCHQOS132, 0x000000A0);
-   WriteReg_32(DBSC_E3_DBSCHQOS133, 0x00000040);
-   WriteReg_32(DBSC_E3_DBSCHQOS140, 0x000000C0);
-   WriteReg_32(DBSC_E3_DBSCHQOS141, 0x000000B0);
-   WriteReg_32(DBSC_E3_DBSCHQOS142, 0x00000080);
-   WriteReg_32(DBSC_E3_DBSCHQOS143, 0x00000040);
-   WriteReg_32(DBSC_E3_DBSCHQOS150, 0x00000040);
-   WriteReg_32(DBSC_E3_DBSCHQOS151, 0x00000030);
-   WriteReg_32(DBSC_E3_DBSCHQOS152, 0x00000020);
-   WriteReg_32(DBSC_E3_DBSCHQOS153, 0x00000010);
-
-/* rev.0.08 */
-   if (pdqsr_ctl == 1){} else {
-   WriteReg_32(0xE67F0018, 0x00000001);
-   }
-
-   WriteReg_32(DBSC_E3_DBSYSCNT0, 0x00000000);
+       }
+
+       if (pdqsr_ctl == 0) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000100);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       }
+
+       /* PDR always off */
+       if (pdr_ctl == 1) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000103);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000008);
+       }
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00015001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
+
+       if (lcdl_ctl == 1) {
+               for (i = 0; i < 4; i++) {
+                       mmio_write_32(DBSC_DBPDRGA0, 0x000000B0 + i * 0x20);
+                       dqsgd_0c = mmio_read_32(DBSC_DBPDRGD0) & 0x000000FF;
+                       mmio_write_32(DBSC_DBPDRGA0, 0x000000B1 + i * 0x20);
+                       bdlcount_0c = (mmio_read_32(DBSC_DBPDRGD0) &
+                                       0x0000FF00) >> 8;
+                       bdlcount_0c_div2 = (bdlcount_0c >> 1);
+                       bdlcount_0c_div4 = (bdlcount_0c >> 2);
+                       bdlcount_0c_div8 = (bdlcount_0c >> 3);
+                       bdlcount_0c_div16 = (bdlcount_0c >> 4);
+
+                       if (ddr_md == 0) {      /* 1584Mbps */
+                               lcdl_judge1 = bdlcount_0c_div2 +
+                                             bdlcount_0c_div4 +
+                                             bdlcount_0c_div8;
+                               lcdl_judge2 = bdlcount_0c +
+                                             bdlcount_0c_div4 +
+                                             bdlcount_0c_div16;
+                       } else {        /* 1856Mbps */
+                               lcdl_judge1 = bdlcount_0c_div2 +
+                                             bdlcount_0c_div4;
+                               lcdl_judge2 = bdlcount_0c +
+                                             bdlcount_0c_div4;
+                       }
+
+                       if (dqsgd_0c <= lcdl_judge1)
+                               continue;
+
+                       if (dqsgd_0c <= lcdl_judge2) {
+                               mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                               regval = mmio_read_32(DBSC_DBPDRGD0) &
+                                               0xFFFFFF00;
+                               mmio_write_32(DBSC_DBPDRGD0,
+                                             (dqsgd_0c - bdlcount_0c_div8) |
+                                             regval);
+                       } else {
+                               mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                               regval = mmio_read_32(DBSC_DBPDRGD0) &
+                                               0xFFFFFF00;
+                               mmio_write_32(DBSC_DBPDRGD0, regval);
+                               mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                               gatesl_0c = mmio_read_32(DBSC_DBPDRGD0) & 0x7;
+                               mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                               regval = mmio_read_32(DBSC_DBPDRGD0) &
+                                               0xFFFFFFF8;
+                               mmio_write_32(DBSC_DBPDRGD0,
+                                             regval | (gatesl_0c + 1));
+                               mmio_write_32(DBSC_DBPDRGA0, 0xAF + i * 0x20);
+                               regval = mmio_read_32(DBSC_DBPDRGD0);
+                               rdqsd_0c = (regval & 0xFF00) >> 8;
+                               rdqsnd_0c = (regval & 0xFF0000) >> 16;
+                               mmio_write_32(DBSC_DBPDRGA0, 0xAF + i * 0x20);
+                               mmio_write_32(DBSC_DBPDRGD0,
+                                             (regval & 0xFF0000FF) |
+                                             ((rdqsd_0c +
+                                               bdlcount_0c_div4) << 8) |
+                                             ((rdqsnd_0c +
+                                               bdlcount_0c_div4) << 16));
+                               mmio_write_32(DBSC_DBPDRGA0, 0xAA + i * 0x20);
+                               regval = (mmio_read_32(DBSC_DBPDRGD0));
+                               rbd_0c[0] = (regval) & 0x1f;
+                               rbd_0c[1] = (regval >>  8) & 0x1f;
+                               rbd_0c[2] = (regval >> 16) & 0x1f;
+                               rbd_0c[3] = (regval >> 24) & 0x1f;
+                               mmio_write_32(DBSC_DBPDRGA0, 0xAA + i * 0x20);
+                               regval = mmio_read_32(DBSC_DBPDRGD0) &
+                                               0xE0E0E0E0;
+                               for (j = 0; j < 4; j++) {
+                                       rbd_0c[j] = rbd_0c[j] +
+                                                   bdlcount_0c_div4;
+                                       if (rbd_0c[j] > 0x1F)
+                                               rbd_0c[j] = 0x1F;
+                                       regval = regval | (rbd_0c[j] << 8 * j);
+                               }
+                               mmio_write_32(DBSC_DBPDRGD0, regval);
+                               mmio_write_32(DBSC_DBPDRGA0, 0xAB + i * 0x20);
+                               regval = (mmio_read_32(DBSC_DBPDRGD0));
+                               rbd_0c[0] = regval & 0x1f;
+                               rbd_0c[1] = (regval >> 8) & 0x1f;
+                               rbd_0c[2] = (regval >> 16) & 0x1f;
+                               rbd_0c[3] = (regval >> 24) & 0x1f;
+                               mmio_write_32(DBSC_DBPDRGA0, 0xAB + i * 0x20);
+                               regval = mmio_read_32(DBSC_DBPDRGD0) &
+                                               0xE0E0E0E0;
+                               for (j = 0; j < 4; j++) {
+                                       rbd_0c[j] = rbd_0c[j] +
+                                                   bdlcount_0c_div4;
+                                       if (rbd_0c[j] > 0x1F)
+                                               rbd_0c[j] = 0x1F;
+                                       regval = regval | (rbd_0c[j] << 8 * j);
+                               }
+                               mmio_write_32(DBSC_DBPDRGD0, regval);
+                       }
+               }
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000002);
+               mmio_write_32(DBSC_DBPDRGD0, 0x07D81E37);
+       }
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000003);
+       if (byp_ctl == 1)
+               mmio_write_32(DBSC_DBPDRGD0, 0x0380C720);
+       else
+               mmio_write_32(DBSC_DBPDRGD0, 0x0380C700);
+
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000007);
+       while (mmio_read_32(DBSC_DBPDRGD0) & BIT(30))
+               ;
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000021);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0024643E);
+
+       /*
+        * recovery_Step3(DBSC Setting 2)
+        */
+       mmio_write_32(DBSC_DBDFICUPDCNF, 0x40100001);
+       mmio_write_32(DBSC_DBACEN, 0x00000001);
+
+       if (pdqsr_ctl == 1) {
+               mmio_write_32(0xE67F0018, 0x00000001);
+               regval = mmio_read_32(0x40000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGD0, regval);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E0);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000100);
+               mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       }
+
+       /* PDR dynamic */
+       if (pdr_ctl == 1) {
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000A3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000C3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x000000E3);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+               mmio_write_32(DBSC_DBPDRGA0, 0x00000103);
+               mmio_write_32(DBSC_DBPDRGD0, 0x00000000);
+       }
+
+       mmio_write_32(DBSC_DBPDLK0, 0x00000000);
+       mmio_write_32(DBSC_DBSYSCNT0, 0x00000000);
+
+#ifdef ddr_qos_init_setting /* only for non qos_init */
+       mmio_write_32(DBSC_DBSYSCNT0, 0x00001234);
+       mmio_write_32(DBSC_DBCAM0CNF1, 0x00043218);
+       mmio_write_32(DBSC_DBCAM0CNF2, 0x000000F4);
+       mmio_write_32(DBSC_DBSCHCNT0, 0x000f0037);
+       mmio_write_32(DBSC_DBSCHSZ0, 0x00000001);
+       mmio_write_32(DBSC_DBSCHRW0, 0x22421111);
+       mmio_write_32(DBSC_SCFCTST2, 0x012F1123);
+       mmio_write_32(DBSC_DBSCHQOS00, 0x00000F00);
+       mmio_write_32(DBSC_DBSCHQOS01, 0x00000B00);
+       mmio_write_32(DBSC_DBSCHQOS02, 0x00000000);
+       mmio_write_32(DBSC_DBSCHQOS03, 0x00000000);
+       mmio_write_32(DBSC_DBSCHQOS40, 0x00000300);
+       mmio_write_32(DBSC_DBSCHQOS41, 0x000002F0);
+       mmio_write_32(DBSC_DBSCHQOS42, 0x00000200);
+       mmio_write_32(DBSC_DBSCHQOS43, 0x00000100);
+       mmio_write_32(DBSC_DBSCHQOS90, 0x00000100);
+       mmio_write_32(DBSC_DBSCHQOS91, 0x000000F0);
+       mmio_write_32(DBSC_DBSCHQOS92, 0x000000A0);
+       mmio_write_32(DBSC_DBSCHQOS93, 0x00000040);
+       mmio_write_32(DBSC_DBSCHQOS130, 0x00000100);
+       mmio_write_32(DBSC_DBSCHQOS131, 0x000000F0);
+       mmio_write_32(DBSC_DBSCHQOS132, 0x000000A0);
+       mmio_write_32(DBSC_DBSCHQOS133, 0x00000040);
+       mmio_write_32(DBSC_DBSCHQOS140, 0x000000C0);
+       mmio_write_32(DBSC_DBSCHQOS141, 0x000000B0);
+       mmio_write_32(DBSC_DBSCHQOS142, 0x00000080);
+       mmio_write_32(DBSC_DBSCHQOS143, 0x00000040);
+       mmio_write_32(DBSC_DBSCHQOS150, 0x00000040);
+       mmio_write_32(DBSC_DBSCHQOS151, 0x00000030);
+       mmio_write_32(DBSC_DBSCHQOS152, 0x00000020);
+       mmio_write_32(DBSC_DBSCHQOS153, 0x00000010);
+
+       if (pdqsr_ctl == 0)
+               mmio_write_32(0xE67F0018, 0x00000001);
+
+       mmio_write_32(DBSC_DBSYSCNT0, 0x00000000);
 #endif
 
-   return 1;
+       return 1;
 
-} /*  recovery_from_backup_mode */
+} /* recovery_from_backup_mode */
 
-/*******************************************************************************
- *      init_ddr : MD19=0,DDR3L,1584Mbps / MD19=1,DDR3L,1856Mbps
- ******************************************************************************/
+/*
+ * init_ddr : MD19=0,DDR3L,1584Mbps / MD19=1,DDR3L,1856Mbps
+ */
 
-/*******************************************************************************
- *  DDR Initialize entry for IPL
- ******************************************************************************/
+/*
+ * DDR Initialize entry for IPL
+ */
 int32_t rcar_dram_init(void)
 {
-    uint32_t dataL;
-    uint32_t failcount;
-    uint32_t md = 0;
-    uint32_t ddr = 0;
-
-    md = *((volatile uint32_t*)RST_MODEMR);
-    ddr = (md & 0x00080000) >> 19;
-    if (ddr == 0x0) {
-       NOTICE("BL2: DDR1584(%s)\n", RCAR_E3_DDR_VERSION);
-    } else if(ddr == 0x1){
-       NOTICE("BL2: DDR1856(%s)\n", RCAR_E3_DDR_VERSION);
-    } /*  ddr */
-
-    rcar_dram_get_boot_status(&ddrBackup);
-
-    if (ddrBackup == DRAM_BOOT_STATUS_WARM) {
-        dataL = recovery_from_backup_mode(); /*  WARM boot */
-    } else {
-        dataL = init_ddr();                  /*  COLD boot */
-    } /*  ddrBackup */
-
-    if (dataL == 1) {
-        failcount = 0;
-    } else {
-        failcount = 1;
-    } /*  dataL */
-
-    if (failcount == 0) {
-       return INITDRAM_OK;
-    } else {
-       return INITDRAM_NG;
-    } /*  failcount */
-} /*  InitDram */
-
-/*******************************************************************************
- *  END
- ******************************************************************************/
+       uint32_t dataL;
+       uint32_t failcount;
+       uint32_t md = 0;
+       uint32_t ddr = 0;
+       uint32_t ddr_backup;
+
+       md = *((volatile uint32_t*)RST_MODEMR);
+       ddr = (md & 0x00080000) >> 19;
+       if (ddr == 0x0)
+               NOTICE("BL2: DDR1584(%s)\n", RCAR_E3_DDR_VERSION);
+       else if (ddr == 0x1)
+               NOTICE("BL2: DDR1856(%s)\n", RCAR_E3_DDR_VERSION);
+
+       rcar_dram_get_boot_status(&ddr_backup);
+
+       if (ddr_backup == DRAM_BOOT_STATUS_WARM)
+               dataL = recovery_from_backup_mode(ddr_backup);  /* WARM boot */
+       else
+               dataL = init_ddr();                             /* COLD boot */
+
+       if (dataL == 1)
+               failcount = 0;
+       else
+               failcount = 1;
+
+       if (failcount == 0)
+               return INITDRAM_OK;
+       else
+               return INITDRAM_NG;
+
+}
diff --git a/drivers/staging/renesas/rcar/ddr/ddr_a/ddr_init_e3.h b/drivers/staging/renesas/rcar/ddr/ddr_a/ddr_init_e3.h
deleted file mode 100644 (file)
index 2e9a5bf..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2015-2018, Renesas Electronics Corporation. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef DDR_INIT_E3_H
-#define DDR_INIT_E3_H
-
-#include <stdint.h>
-
-#define RCAR_E3_DDR_VERSION    "rev.0.11"
-
-#ifdef ddr_qos_init_setting
-   #define REFRESH_RATE  3900               /*  Average periodic refresh interval[ns]. Support 3900,7800 */
-#else
-   #if RCAR_REF_INT == 0
-      #define REFRESH_RATE  3900
-   #elif RCAR_REF_INT == 1
-      #define REFRESH_RATE  7800
-   #else
-      #define REFRESH_RATE  3900
-   #endif
-#endif
-
-extern int32_t rcar_dram_init(void);
-#define INITDRAM_OK (0)
-#define INITDRAM_NG (0xffffffff)
-#define INITDRAM_ERR_I (0xffffffff)
-#define INITDRAM_ERR_O (0xfffffffe)
-#define INITDRAM_ERR_T (0xfffffff0)
-
-#endif /* DDR_INIT_E3_H */
index 7e933286046f27a6e8c9e71b3d3a47fb441c66c3..00e1903ce1a9eb1345c7f7058d719c8a21bc2e9b 100644 (file)
 /*
- * Copyright (c) 2015-2016, Renesas Electronics Corporation
+ * Copyright (c) 2015-2019, Renesas Electronics Corporation
  * All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
+#include <lib/mmio.h>
+#include <lib/utils_def.h>
 #include <stdint.h>
 #include "boot_init_dram.h"
-#include "boot_init_dram_regdef_v3m.h"
-
-static void WriteReg_32(uintptr_t a, uint32_t v)
-{
-       *(volatile uint32_t*)a = v;
-}
-
-static uint32_t ReadReg_32(uintptr_t a)
-{
-       uint32_t w = *(volatile uint32_t*)a;
-       return w;
-}
+#include "boot_init_dram_regdef.h"
 
 static uint32_t init_ddr_v3m_1600(void)
 {
-       // last modified 2016.12.16
+       uint32_t i, r2, r5, r6, r7, r12;
 
-       uint32_t RegVal_R2, RegVal_R5, RegVal_R6, RegVal_R7, RegVal_R12;
-
-   WriteReg_32(DBSC_V3M_DBSYSCNT0,0x00001234);
-   WriteReg_32(DBSC_V3M_DBKIND,0x00000007);
+       mmio_write_32(DBSC_DBSYSCNT0, 0x00001234);
+       mmio_write_32(DBSC_DBKIND, 0x00000007);
 #if RCAR_DRAM_DDR3L_MEMCONF == 0
-   WriteReg_32(DBSC_V3M_DBMEMCONF00,0x0f030a02); // 1GB: Eagle
+       mmio_write_32(DBSC_DBMEMCONF00, 0x0f030a02); // 1GB: Eagle
 #else
-   WriteReg_32(DBSC_V3M_DBMEMCONF00,0x10030a02); // 2GB: V3MSK
+       mmio_write_32(DBSC_DBMEMCONF00, 0x10030a02); // 2GB: V3MSK
 #endif
-   WriteReg_32(DBSC_V3M_DBPHYCONF0,0x00000001);
-   WriteReg_32(DBSC_V3M_DBTR0,0x0000000B);
-   WriteReg_32(DBSC_V3M_DBTR1,0x00000008);
-   WriteReg_32(DBSC_V3M_DBTR3,0x0000000B);
-   WriteReg_32(DBSC_V3M_DBTR4,0x000B000B);
-   WriteReg_32(DBSC_V3M_DBTR5,0x00000027);
-   WriteReg_32(DBSC_V3M_DBTR6,0x0000001C);
-   WriteReg_32(DBSC_V3M_DBTR7,0x00060006);
-   WriteReg_32(DBSC_V3M_DBTR8,0x00000020);
-   WriteReg_32(DBSC_V3M_DBTR9,0x00000006);
-   WriteReg_32(DBSC_V3M_DBTR10,0x0000000C);
-   WriteReg_32(DBSC_V3M_DBTR11,0x0000000B);
-   WriteReg_32(DBSC_V3M_DBTR12,0x00120012);
-   WriteReg_32(DBSC_V3M_DBTR13,0x01180118);
-   WriteReg_32(DBSC_V3M_DBTR14,0x00140005);
-   WriteReg_32(DBSC_V3M_DBTR15,0x00050004);
-   WriteReg_32(DBSC_V3M_DBTR16,0x071D0305);
-   WriteReg_32(DBSC_V3M_DBTR17,0x040C0010);
-   WriteReg_32(DBSC_V3M_DBTR18,0x00000200);
-   WriteReg_32(DBSC_V3M_DBTR19,0x01000040);
-   WriteReg_32(DBSC_V3M_DBTR20,0x02000120);
-   WriteReg_32(DBSC_V3M_DBTR21,0x00040004);
-   WriteReg_32(DBSC_V3M_DBBL,0x00000000);
-   WriteReg_32(DBSC_V3M_DBODT0,0x00000001);
-   WriteReg_32(DBSC_V3M_DBADJ0,0x00000001);
-   WriteReg_32(DBSC_V3M_DBCAM0CNF1,0x00082010);
-   WriteReg_32(DBSC_V3M_DBCAM0CNF2,0x00002000);
-   WriteReg_32(DBSC_V3M_DBSCHCNT0,0x080f003f);
-   WriteReg_32(DBSC_V3M_DBSCHCNT1,0x00001010);
-   WriteReg_32(DBSC_V3M_DBSCHSZ0,0x00000001);
-   WriteReg_32(DBSC_V3M_DBSCHRW0,0x00000200);
-   WriteReg_32(DBSC_V3M_DBSCHRW1,0x00000040);
-   WriteReg_32(DBSC_V3M_DBSCHQOS40,0x00000600);
-   WriteReg_32(DBSC_V3M_DBSCHQOS41,0x00000480);
-   WriteReg_32(DBSC_V3M_DBSCHQOS42,0x00000300);
-   WriteReg_32(DBSC_V3M_DBSCHQOS43,0x00000180);
-   WriteReg_32(DBSC_V3M_DBSCHQOS90,0x00000400);
-   WriteReg_32(DBSC_V3M_DBSCHQOS91,0x00000300);
-   WriteReg_32(DBSC_V3M_DBSCHQOS92,0x00000200);
-   WriteReg_32(DBSC_V3M_DBSCHQOS93,0x00000100);
-   WriteReg_32(DBSC_V3M_DBSCHQOS130,0x00000300);
-   WriteReg_32(DBSC_V3M_DBSCHQOS131,0x00000240);
-   WriteReg_32(DBSC_V3M_DBSCHQOS132,0x00000180);
-   WriteReg_32(DBSC_V3M_DBSCHQOS133,0x000000c0);
-   WriteReg_32(DBSC_V3M_DBSCHQOS140,0x00000200);
-   WriteReg_32(DBSC_V3M_DBSCHQOS141,0x00000180);
-   WriteReg_32(DBSC_V3M_DBSCHQOS142,0x00000100);
-   WriteReg_32(DBSC_V3M_DBSCHQOS143,0x00000080);
-   WriteReg_32(DBSC_V3M_DBSCHQOS150,0x00000100);
-   WriteReg_32(DBSC_V3M_DBSCHQOS151,0x000000c0);
-   WriteReg_32(DBSC_V3M_DBSCHQOS152,0x00000080);
-   WriteReg_32(DBSC_V3M_DBSCHQOS153,0x00000040);
-   WriteReg_32(DBSC_V3M_DBSYSCONF1,0x00000002);
-   WriteReg_32(DBSC_V3M_DBCAM0CNF1,0x00040C04);
-   WriteReg_32(DBSC_V3M_DBCAM0CNF2,0x000001c4);
-   WriteReg_32(DBSC_V3M_DBSCHSZ0,0x00000003);
-   WriteReg_32(DBSC_V3M_DBSCHRW1,0x001a0080);
-   WriteReg_32(DBSC_V3M_DBDFICNT0,0x00000010);
+       mmio_write_32(DBSC_DBPHYCONF0, 0x00000001);
+       mmio_write_32(DBSC_DBTR0, 0x0000000B);
+       mmio_write_32(DBSC_DBTR1, 0x00000008);
+       mmio_write_32(DBSC_DBTR3, 0x0000000B);
+       mmio_write_32(DBSC_DBTR4, 0x000B000B);
+       mmio_write_32(DBSC_DBTR5, 0x00000027);
+       mmio_write_32(DBSC_DBTR6, 0x0000001C);
+       mmio_write_32(DBSC_DBTR7, 0x00060006);
+       mmio_write_32(DBSC_DBTR8, 0x00000020);
+       mmio_write_32(DBSC_DBTR9, 0x00000006);
+       mmio_write_32(DBSC_DBTR10, 0x0000000C);
+       mmio_write_32(DBSC_DBTR11, 0x0000000B);
+       mmio_write_32(DBSC_DBTR12, 0x00120012);
+       mmio_write_32(DBSC_DBTR13, 0x01180118);
+       mmio_write_32(DBSC_DBTR14, 0x00140005);
+       mmio_write_32(DBSC_DBTR15, 0x00050004);
+       mmio_write_32(DBSC_DBTR16, 0x071D0305);
+       mmio_write_32(DBSC_DBTR17, 0x040C0010);
+       mmio_write_32(DBSC_DBTR18, 0x00000200);
+       mmio_write_32(DBSC_DBTR19, 0x01000040);
+       mmio_write_32(DBSC_DBTR20, 0x02000120);
+       mmio_write_32(DBSC_DBTR21, 0x00040004);
+       mmio_write_32(DBSC_DBBL, 0x00000000);
+       mmio_write_32(DBSC_DBODT0, 0x00000001);
+       mmio_write_32(DBSC_DBADJ0, 0x00000001);
+       mmio_write_32(DBSC_DBCAM0CNF1, 0x00082010);
+       mmio_write_32(DBSC_DBCAM0CNF2, 0x00002000);
+       mmio_write_32(DBSC_DBSCHCNT0, 0x080f003f);
+       mmio_write_32(DBSC_DBSCHCNT1, 0x00001010);
+       mmio_write_32(DBSC_DBSCHSZ0, 0x00000001);
+       mmio_write_32(DBSC_DBSCHRW0, 0x00000200);
+       mmio_write_32(DBSC_DBSCHRW1, 0x00000040);
+       mmio_write_32(DBSC_DBSCHQOS40, 0x00000600);
+       mmio_write_32(DBSC_DBSCHQOS41, 0x00000480);
+       mmio_write_32(DBSC_DBSCHQOS42, 0x00000300);
+       mmio_write_32(DBSC_DBSCHQOS43, 0x00000180);
+       mmio_write_32(DBSC_DBSCHQOS90, 0x00000400);
+       mmio_write_32(DBSC_DBSCHQOS91, 0x00000300);
+       mmio_write_32(DBSC_DBSCHQOS92, 0x00000200);
+       mmio_write_32(DBSC_DBSCHQOS93, 0x00000100);
+       mmio_write_32(DBSC_DBSCHQOS130, 0x00000300);
+       mmio_write_32(DBSC_DBSCHQOS131, 0x00000240);
+       mmio_write_32(DBSC_DBSCHQOS132, 0x00000180);
+       mmio_write_32(DBSC_DBSCHQOS133, 0x000000c0);
+       mmio_write_32(DBSC_DBSCHQOS140, 0x00000200);
+       mmio_write_32(DBSC_DBSCHQOS141, 0x00000180);
+       mmio_write_32(DBSC_DBSCHQOS142, 0x00000100);
+       mmio_write_32(DBSC_DBSCHQOS143, 0x00000080);
+       mmio_write_32(DBSC_DBSCHQOS150, 0x00000100);
+       mmio_write_32(DBSC_DBSCHQOS151, 0x000000c0);
+       mmio_write_32(DBSC_DBSCHQOS152, 0x00000080);
+       mmio_write_32(DBSC_DBSCHQOS153, 0x00000040);
+       mmio_write_32(DBSC_DBSYSCONF1, 0x00000002);
+       mmio_write_32(DBSC_DBCAM0CNF1, 0x00040C04);
+       mmio_write_32(DBSC_DBCAM0CNF2, 0x000001c4);
+       mmio_write_32(DBSC_DBSCHSZ0, 0x00000003);
+       mmio_write_32(DBSC_DBSCHRW1, 0x001a0080);
+       mmio_write_32(DBSC_DBDFICNT0, 0x00000010);
+
+       mmio_write_32(DBSC_DBPDLK0, 0x0000A55A);
+       mmio_write_32(DBSC_DBCMD, 0x01000001);
+       mmio_write_32(DBSC_DBCMD, 0x08000000);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x80010000);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
 
-   WriteReg_32(DBSC_V3M_DBPDLK0,0X0000A55A);
-   WriteReg_32(DBSC_V3M_DBCMD,0x01000001);
-   WriteReg_32(DBSC_V3M_DBCMD,0x08000000);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000001);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X80010000);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_V3M_DBPDRGD0)) == 0 );
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000008);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000B8000);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);
+       mmio_write_32(DBSC_DBPDRGD0, 0x04058904);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000091);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0007BB6D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000095);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0007BB6B);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000099);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0007BB6D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);
+       mmio_write_32(DBSC_DBPDRGD0, 0x04058900);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000021);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0024641E);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010073);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
 
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000008);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X000B8000);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000090);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X04058904);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000091);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X0007BB6D);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000095);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X0007BB6B);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000099);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X0007BB6D);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000090);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X04058900);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000021);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X0024641E);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000001);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X00010073);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_V3M_DBPDRGD0)) == 0 );
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0C058900);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000090);
+       mmio_write_32(DBSC_DBPDRGD0, 0x04058900);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
 
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000090);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X0C058900);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000090);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X04058900);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_V3M_DBPDRGD0)) == 0 );
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000003);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0780C700);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000007);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(30)))
+               ;
 
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000003);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X0780C700);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000007);
-   while ( (BIT30& ReadReg_32(DBSC_V3M_DBPDRGD0)) == 0 );
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000004);
+       mmio_write_32(DBSC_DBPDRGD0, 0x08C0C170);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000022);
+       mmio_write_32(DBSC_DBPDRGD0, 0x1000040B);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000023);
+       mmio_write_32(DBSC_DBPDRGD0, 0x2D9C0B66);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000024);
+       mmio_write_32(DBSC_DBPDRGD0, 0x2A88C400);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000025);
+       mmio_write_32(DBSC_DBPDRGD0, 0x30005200);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000026);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0014A9C9);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000027);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00000D70);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000028);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00000004);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000029);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00000018);
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000002C);
+       mmio_write_32(DBSC_DBPDRGD0, 0x81003047);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000020);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00181884);
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000001A);
+       mmio_write_32(DBSC_DBPDRGD0, 0x13C03C10);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
 
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000004);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X08C0C170);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000022);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X1000040B);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000023);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X2D9C0B66);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000024);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X2A88C400);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000025);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X30005200);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000026);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X0014A9C9);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000027);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X00000D70);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000028);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X00000004);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000029);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X00000018);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X0000002C);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X81003047);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000020);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X00181884);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X0000001A);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X13C03C10);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_V3M_DBPDRGD0)) == 0 );
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A7);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A8);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A9);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C7);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C8);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C9);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000E7);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000E8);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000E9);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000107);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000108);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0D0D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000109);
+       mmio_write_32(DBSC_DBPDRGD0, 0x000D0D0D);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010181);
+       mmio_write_32(DBSC_DBCMD, 0x08000001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
 
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000A7);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X0D0D0D0D);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000A8);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X0D0D0D0D);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000A9);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X000D0D0D);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000C7);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X0D0D0D0D);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000C8);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X0D0D0D0D);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000C9);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X000D0D0D);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000E7);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X0D0D0D0D);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000E8);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X0D0D0D0D);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000E9);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X000D0D0D);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000107);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X0D0D0D0D);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000108);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X0D0D0D0D);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000109);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X000D0D0D);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000001);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X00010181);
-   WriteReg_32(DBSC_V3M_DBCMD,0x08000001);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_V3M_DBPDRGD0)) == 0 );
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010601);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
 
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000001);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X00010601);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_V3M_DBPDRGD0)) == 0 );
+       for (i = 0; i < 4; i++) {
+               mmio_write_32(DBSC_DBPDRGA0, 0xB1 + i * 0x20);
+               r5 = (mmio_read_32(DBSC_DBPDRGD0) & 0xFF00) >> 8;
+               mmio_write_32(DBSC_DBPDRGA0, 0xB4 + i * 0x20);
+               r6 = mmio_read_32(DBSC_DBPDRGD0) & 0xFF;
+               mmio_write_32(DBSC_DBPDRGA0, 0xB3 + i * 0x20);
+               r7 = mmio_read_32(DBSC_DBPDRGD0) & 0x7;
 
-   for (uint32_t i = 0; i<4; i++)
-   {
-      WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000B1 + i*0x20);
-      RegVal_R5 = (ReadReg_32(DBSC_V3M_DBPDRGD0) & 0x0000FF00 ) >> 8;
-      WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000B4 + i*0x20);
-      RegVal_R6 = (ReadReg_32(DBSC_V3M_DBPDRGD0) & 0x000000FF ) ;
-      WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000B3 + i*0x20);
-      RegVal_R7 = (ReadReg_32(DBSC_V3M_DBPDRGD0) & 0x00000007 ) ;
-      if ( RegVal_R6 > 0 )
-      {
-         WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000B2 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_V3M_DBPDRGD0) & 0XFFFFFFF8 ) ;
+               if (r6 > 0) {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = (mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8);
 
-         WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000B2 + i*0x20);
-         WriteReg_32(DBSC_V3M_DBPDRGD0,((RegVal_R7+1)&0X00000007) | RegVal_R2);
-         WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000B0 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_V3M_DBPDRGD0) & 0XFFFFFF00 ) ;
-         WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000B0 + i*0x20);
-         WriteReg_32(DBSC_V3M_DBPDRGD0,RegVal_R2 | RegVal_R6);
-      } else {
-         WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000B2 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_V3M_DBPDRGD0) & 0XFFFFFFF8 ) ;
-         WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000B2 + i*0x20);
-         WriteReg_32(DBSC_V3M_DBPDRGD0,RegVal_R2 | RegVal_R7);
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, ((r7 + 1) & 0x7) | r2);
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = (mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00);
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | r6);
+               } else {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = (mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8);
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 | r7);
 
-         WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000B0 + i*0x20);
-         RegVal_R2 = (ReadReg_32(DBSC_V3M_DBPDRGD0) & 0XFFFFFF00 ) ;
-         WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000B0 + i*0x20);
-         WriteReg_32(DBSC_V3M_DBPDRGD0,(((RegVal_R5<<1) + RegVal_R6 ) & 0X000000FF )| RegVal_R2);
-      }
-   }
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = (mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00);
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 |
+                                                    (((r5 << 1) + r6) & 0xFF));
+               }
+       }
 
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000005);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0XC1AA00A0);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000A0);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X7C0002C5);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000C0);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X7C0002C5);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000E0);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X7C0002C5);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000100);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X7C0002C5);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000001);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X00010801);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_V3M_DBPDRGD0)) == 0 );
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000005);
+       mmio_write_32(DBSC_DBPDRGD0, 0xC1AA00A0);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000E0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000100);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010801);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
 
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000005);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0XC1AA00B8);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000001);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X0001F001);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_V3M_DBPDRGD0)) == 0 );
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000005);
+       mmio_write_32(DBSC_DBPDRGD0, 0xC1AA00B8);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0001F001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
 
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000A0);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X7C000285);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000C0);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X7C000285);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000E0);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X7C000285);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000100);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X7C000285);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X0000002C);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X81003087);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000001);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X00010401);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_V3M_DBPDRGD0)) == 0 );
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000E0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000100);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C000285);
+       mmio_write_32(DBSC_DBPDRGA0, 0x0000002C);
+       mmio_write_32(DBSC_DBPDRGD0, 0x81003087);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00010401);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
 
-   for (uint32_t i = 0; i < 4; i++)
-   {
-          WriteReg_32(DBSC_V3M_DBPDRGA0, 0X000000B1 + i * 0x20);
-          RegVal_R5 = (ReadReg_32(DBSC_V3M_DBPDRGD0) & 0x0000FF00) >> 8;
-          WriteReg_32(DBSC_V3M_DBPDRGA0, 0X000000B4 + i * 0x20);
-          RegVal_R6 = (ReadReg_32(DBSC_V3M_DBPDRGD0) & 0x000000FF);
+       for (i = 0; i < 4; i++) {
+               mmio_write_32(DBSC_DBPDRGA0, 0xB1 + i * 0x20);
+               r5 = (mmio_read_32(DBSC_DBPDRGD0) & 0xFF00) >> 8;
+               mmio_write_32(DBSC_DBPDRGA0, 0xB4 + i * 0x20);
+               r6 = (mmio_read_32(DBSC_DBPDRGD0) & 0xFF);
 
-          WriteReg_32(DBSC_V3M_DBPDRGA0, 0X000000B3 + i * 0x20);
-          RegVal_R7 = (ReadReg_32(DBSC_V3M_DBPDRGD0) & 0x00000007);
-          RegVal_R12 = (RegVal_R5 >> 2);
-          if (RegVal_R6 - RegVal_R12 > 0)
-          {
-                  WriteReg_32(DBSC_V3M_DBPDRGA0, 0X000000B2 + i * 0x20);
-                  RegVal_R2 = (ReadReg_32(DBSC_V3M_DBPDRGD0) & 0XFFFFFFF8);
+               mmio_write_32(DBSC_DBPDRGA0, 0xB3 + i * 0x20);
+               r7 = (mmio_read_32(DBSC_DBPDRGD0) & 0x7);
+               r12 = (r5 >> 2);
+               if (r6 - r12 > 0) {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = (mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8);
 
-                  WriteReg_32(DBSC_V3M_DBPDRGA0, 0X000000B2 + i * 0x20);
-                  WriteReg_32(DBSC_V3M_DBPDRGD0, ((RegVal_R7 + 1) & 0X00000007) | RegVal_R2);
-                  WriteReg_32(DBSC_V3M_DBPDRGA0, 0X000000B0 + i * 0x20);
-                  RegVal_R2 = (ReadReg_32(DBSC_V3M_DBPDRGD0) & 0XFFFFFF00);
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, ((r7 + 1) & 0x7) | r2);
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = (mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00);
 
-                  WriteReg_32(DBSC_V3M_DBPDRGA0, 0X000000B0 + i * 0x20);
-                  WriteReg_32(DBSC_V3M_DBPDRGD0, ((RegVal_R6 - RegVal_R12) & 0X000000FF) | RegVal_R2);
-          }
-          else
-          {
-                  WriteReg_32(DBSC_V3M_DBPDRGA0, 0X000000B2 + i * 0x20);
-                  RegVal_R2 = (ReadReg_32(DBSC_V3M_DBPDRGD0) & 0XFFFFFFF8);
-                  WriteReg_32(DBSC_V3M_DBPDRGA0, 0X000000B2 + i * 0x20);
-                  WriteReg_32(DBSC_V3M_DBPDRGD0, (RegVal_R7 & 0X00000007) | RegVal_R2);
-                  WriteReg_32(DBSC_V3M_DBPDRGA0, 0X000000B0 + i * 0x20);
-                  RegVal_R2 = (ReadReg_32(DBSC_V3M_DBPDRGD0) & 0XFFFFFF00);
-                  WriteReg_32(DBSC_V3M_DBPDRGA0, 0X000000B0 + i * 0x20);
-                  WriteReg_32(DBSC_V3M_DBPDRGD0, ((RegVal_R6 + RegVal_R5 + (RegVal_R5 >> 1) + RegVal_R12) & 0X000000FF) | RegVal_R2);
-          }
-   }
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, ((r6 - r12) & 0xFF) | r2);
+               } else {
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       r2 = (mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFFF8);
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB2 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, (r7 & 0x7) | r2);
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       r2 = (mmio_read_32(DBSC_DBPDRGD0) & 0xFFFFFF00);
+                       mmio_write_32(DBSC_DBPDRGA0, 0xB0 + i * 0x20);
+                       mmio_write_32(DBSC_DBPDRGD0, r2 |
+                                                    ((r6 + r5 +
+                                                     (r5 >> 1) + r12) & 0xFF));
+               }
+       }
 
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000A0);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X7C0002C5);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000C0);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X7C0002C5);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X000000E0);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X7C0002C5);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000100);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X7C0002C5);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000001);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X00015001);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000006);
-   while ( (BIT0 & ReadReg_32(DBSC_V3M_DBPDRGD0)) == 0 );
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000A0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000C0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       mmio_write_32(DBSC_DBPDRGA0, 0x000000E0);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000100);
+       mmio_write_32(DBSC_DBPDRGD0, 0x7C0002C5);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000001);
+       mmio_write_32(DBSC_DBPDRGD0, 0x00015001);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000006);
+       while (!(mmio_read_32(DBSC_DBPDRGD0) & BIT(0)))
+               ;
 
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000003);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X0380C700);
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000007);
-   while ( (BIT30& ReadReg_32(DBSC_V3M_DBPDRGD0)) != 0 );
-   WriteReg_32(DBSC_V3M_DBPDRGA0,0X00000021);
-   WriteReg_32(DBSC_V3M_DBPDRGD0,0X0024643E);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000003);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0380C700);
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000007);
+       while (mmio_read_32(DBSC_DBPDRGD0) & BIT(30))
+               ;
+       mmio_write_32(DBSC_DBPDRGA0, 0x00000021);
+       mmio_write_32(DBSC_DBPDRGD0, 0x0024643E);
 
-   WriteReg_32(DBSC_V3M_DBBUS0CNF1,0x00000000);
-   WriteReg_32(DBSC_V3M_DBBUS0CNF0,0x00010001);
-   WriteReg_32(DBSC_V3M_DBCALCNF,0x0100200E);
-   WriteReg_32(DBSC_V3M_DBRFCNF1,0x00081860);
-   WriteReg_32(DBSC_V3M_DBRFCNF2,0x00010000);
-   WriteReg_32(DBSC_V3M_DBDFICUPDCNF,0x40100001);
-   WriteReg_32(DBSC_V3M_DBRFEN,0x00000001);
-   WriteReg_32(DBSC_V3M_DBACEN,0x00000001);
-   WriteReg_32(DBSC_V3M_DBPDLK0,0X00000000);
-   WriteReg_32(0xE67F0024, 0x00000001);
-   WriteReg_32(DBSC_V3M_DBSYSCNT0,0x00000000);
+       mmio_write_32(DBSC_DBBUS0CNF1, 0x00000000);
+       mmio_write_32(DBSC_DBBUS0CNF0, 0x00010001);
+       mmio_write_32(DBSC_DBCALCNF, 0x0100200E);
+       mmio_write_32(DBSC_DBRFCNF1, 0x00081860);
+       mmio_write_32(DBSC_DBRFCNF2, 0x00010000);
+       mmio_write_32(DBSC_DBDFICUPDCNF, 0x40100001);
+       mmio_write_32(DBSC_DBRFEN, 0x00000001);
+       mmio_write_32(DBSC_DBACEN, 0x00000001);
+       mmio_write_32(DBSC_DBPDLK0, 0x00000000);
+       mmio_write_32(0xE67F0024, 0x00000001);
+       mmio_write_32(DBSC_DBSYSCNT0, 0x00000000);
 
-   return 1;
+       return INITDRAM_OK;
 }
 
 int32_t rcar_dram_init(void)
 {
-       return init_ddr_v3m_1600() ? INITDRAM_OK : INITDRAM_NG;
+       return init_ddr_v3m_1600();
 }
index 16581bdc6d11c2716eebaa7838f4e95adc108286..89d666ce6d7c88b153d0145fcdb1ab94e2443f66 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2018, Renesas Electronics Corporation. All rights reserved.
+ * Copyright (c) 2015-2019, Renesas Electronics Corporation. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -79,18 +79,18 @@ static uint32_t Prr_Cut;
 
 char *pRCAR_DDR_VERSION;
 uint32_t _cnf_BOARDTYPE;
-static uint32_t *pDDR_REGDEF_TBL;
+static const uint32_t *pDDR_REGDEF_TBL;
 static uint32_t brd_clk;
 static uint32_t brd_clkdiv;
 static uint32_t brd_clkdiva;
 static uint32_t ddr_mbps;
 static uint32_t ddr_mbpsdiv;
 static uint32_t ddr_tccd;
-static struct _boardcnf *Boardcnf;
-static uint32_t ddr_phyvalid;
 static uint32_t ddr_phycaslice;
-static volatile uint32_t ddr_density[DRAM_CH_CNT][CS_CNT];
-static uint32_t ch_have_this_cs[CS_CNT];
+static const struct _boardcnf *Boardcnf;
+static uint32_t ddr_phyvalid;
+static uint32_t ddr_density[DRAM_CH_CNT][CS_CNT];
+static uint32_t ch_have_this_cs[CS_CNT] __attribute__ ((aligned(64)));
 static uint32_t rdqdm_dly[DRAM_CH_CNT][CS_CNT][SLICE_CNT * 2][9];
 static uint32_t max_density;
 static uint32_t ddr0800_mul;
@@ -228,7 +228,7 @@ static const uint32_t
 /*******************************************************************************
  *     Prototypes
  ******************************************************************************/
-static inline int32_t vch_nxt(int32_t pos);
+static inline uint32_t vch_nxt(uint32_t pos);
 static void cpg_write_32(uint32_t a, uint32_t v);
 static void pll3_control(uint32_t high);
 static inline void dsb_sev(void);
@@ -328,9 +328,9 @@ static uint32_t wdqdm_ana1(uint32_t ch, uint32_t ddr_csn);
 /*******************************************************************************
  *     macro for channel selection loop
  ******************************************************************************/
-static inline int32_t vch_nxt(int32_t pos)
+static inline uint32_t vch_nxt(uint32_t pos)
 {
-       int32_t posn;
+       uint32_t posn;
 
        for (posn = pos; posn < DRAM_CH_CNT; posn++) {
                if (ddr_phyvalid & (1U << posn))
@@ -364,26 +364,34 @@ static void pll3_control(uint32_t high)
        uint32_t dataL, dataDIV, dataMUL, tmpDIV;
 
        if (high) {
-               tmpDIV =
-                   (1000 * ddr_mbpsdiv * brd_clkdiv * (brd_clkdiva + 1)) /
-                   (ddr_mul * brd_clk * ddr_mbpsdiv + 1);
-               dataMUL =
-                   (ddr_mul * (tmpDIV + 1) - 1) << 24;
+               tmpDIV = 3999 * brd_clkdiv * (brd_clkdiva + 1) /
+                       (brd_clk * ddr_mul) / 2;
+               dataMUL = (((ddr_mul * tmpDIV) - 1) << 24) |
+                       (brd_clkdiva << 7);
                Pll3Mode = 1;
                loop_max = 2;
        } else {
-               tmpDIV =
-                   (1000 * ddr_mbpsdiv * brd_clkdiv * (brd_clkdiva + 1)) /
-                   (ddr0800_mul * brd_clk * ddr_mbpsdiv + 1);
-               dataMUL =
-                   (ddr0800_mul * (tmpDIV + 1) - 1) << 24;
+               tmpDIV = 3999 * brd_clkdiv * (brd_clkdiva + 1) /
+                       (brd_clk * ddr0800_mul) / 2;
+               dataMUL = (((ddr0800_mul * tmpDIV) - 1) << 24) |
+                       (brd_clkdiva << 7);
                Pll3Mode = 0;
                loop_max = 8;
        }
-       if (tmpDIV) {
-               dataDIV = tmpDIV + 1;
-       } else {
+
+       switch (tmpDIV) {
+       case 1:
                dataDIV = 0;
+               break;
+       case 2:
+       case 3:
+       case 4:
+               dataDIV = tmpDIV;
+               break;
+       default:
+               dataDIV = 6;
+               dataMUL = (dataMUL * tmpDIV) / 3;
+               break;
        }
        dataMUL = dataMUL | (brd_clkdiva << 7);
 
@@ -478,8 +486,6 @@ static void pll3_control(uint32_t high)
                } while ((dataL & CPG_PLLECR_PLL3ST_BIT) == 0);
                dsb_sev();
        }
-
-       return;
 }
 
 /*******************************************************************************
@@ -891,17 +897,14 @@ struct _jedec_spec1 {
 #define JS1_MR1(f) (0x04 | ((f)<<4))
 #define JS1_MR2(f) (0x00 | ((f)<<3) | (f))
 const struct _jedec_spec1 js1[JS1_FREQ_TBL_NUM] = {
-/*A    {  800,  6,  6,  4,  6 , 8, JS1_MR1(0), JS1_MR2(0) },   533.333Mbps*/
-/*A    { 1600, 10, 12,  6, 10 , 8, JS1_MR1(1), JS1_MR2(1) },  1066.666Mbps*/
-/*A    { 2400, 14, 16,  8, 16 , 8, JS1_MR1(2), JS1_MR2(2) },  1600.000Mbps*/
-        /*B*/ {800, 6, 6, 4, 6, 8, JS1_MR1(0), JS1_MR2(0) | 0x40},     /*  533.333Mbps */
-        /*B*/ {1600, 10, 12, 8, 10, 8, JS1_MR1(1), JS1_MR2(1) | 0x40}, /* 1066.666Mbps */
-        /*B*/ {2400, 14, 16, 12, 16, 8, JS1_MR1(2), JS1_MR2(2) | 0x40},        /* 1600.000Mbps */
-        /*A*/ {3200, 20, 22, 10, 20, 8, JS1_MR1(3), JS1_MR2(3)},       /* 2133.333Mbps */
-        /*A*/ {4000, 24, 28, 12, 24, 10, JS1_MR1(4), JS1_MR2(4)},      /* 2666.666Mbps */
-        /*A*/ {4800, 28, 32, 14, 30, 12, JS1_MR1(5), JS1_MR2(5)},      /* 3200.000Mbps */
-        /*A*/ {5600, 32, 36, 16, 34, 14, JS1_MR1(6), JS1_MR2(6)},      /* 3733.333Mbps */
-        /*A*/ {6400, 36, 40, 18, 40, 16, JS1_MR1(7), JS1_MR2(7)}       /* 4266.666Mbps */
+       {  800,  6,  6,  4,  6,  8, JS1_MR1(0), JS1_MR2(0)|0x40 }, /*  533.333Mbps */
+       { 1600, 10, 12,  8, 10,  8, JS1_MR1(1), JS1_MR2(1)|0x40 }, /* 1066.666Mbps */
+       { 2400, 14, 16, 12, 16,  8, JS1_MR1(2), JS1_MR2(2)|0x40 }, /* 1600.000Mbps */
+       { 3200, 20, 22, 10, 20,  8, JS1_MR1(3), JS1_MR2(3) },      /* 2133.333Mbps */
+       { 4000, 24, 28, 12, 24, 10, JS1_MR1(4), JS1_MR2(4) },      /* 2666.666Mbps */
+       { 4800, 28, 32, 14, 30, 12, JS1_MR1(5), JS1_MR2(5) },      /* 3200.000Mbps */
+       { 5600, 32, 36, 16, 34, 14, JS1_MR1(6), JS1_MR2(6) },      /* 3733.333Mbps */
+       { 6400, 36, 40, 18, 40, 16, JS1_MR1(7), JS1_MR2(7) }       /* 4266.666Mbps */
 };
 
 struct _jedec_spec2 {
@@ -1225,7 +1228,7 @@ static void regif_pll_wa(void)
  ******************************************************************************/
 static void ddrtbl_load(void)
 {
-       int i;
+       uint32_t i;
        uint32_t slice;
        uint32_t csab;
        uint32_t adr;
@@ -1238,7 +1241,7 @@ static void ddrtbl_load(void)
        ***********************************************************************/
        /* search jedec_spec1 index */
        for (i = JS1_USABLEC_SPEC_LO; i < JS1_FREQ_TBL_NUM - 1; i++) {
-               if (js1[i].fx3 * 2 * ddr_mbpsdiv >= ddr_mbps * 3)
+               if (js1[i].fx3 * 2U * ddr_mbpsdiv >= ddr_mbps * 3U)
                        break;
        }
        if (JS1_USABLEC_SPEC_HI < i)
@@ -1441,12 +1444,12 @@ static void ddrtbl_load(void)
 #endif /* _def_LPDDR4_VREFCA */
        if ((Prr_Product == PRR_PRODUCT_M3N)
            || (Prr_Product == PRR_PRODUCT_V3H)) {
-               js2[JS2_tIEdly] = _f_scale(ddr_mbps, ddr_mbpsdiv, 7000, 0) + 7;
+               js2[JS2_tIEdly] = _f_scale(ddr_mbps, ddr_mbpsdiv, 7000, 0) + 7U;
                if (js2[JS2_tIEdly] > (RL))
                        js2[JS2_tIEdly] = RL;
        } else if ((Prr_Product == PRR_PRODUCT_H3)
                   && (Prr_Cut > PRR_PRODUCT_11)) {
-               js2[JS2_tIEdly] = _f_scale(ddr_mbps, ddr_mbpsdiv, 9000, 0) + 4;
+               js2[JS2_tIEdly] = _f_scale(ddr_mbps, ddr_mbpsdiv, 9000, 0) + 4U;
        } else if ((Prr_Product == PRR_PRODUCT_H3)
                   && (Prr_Cut <= PRR_PRODUCT_11)) {
                js2[JS2_tIEdly] = _f_scale(ddr_mbps, ddr_mbpsdiv, 10000, 0);
@@ -1528,7 +1531,8 @@ static void ddrtbl_load(void)
        /***********************************************************************
        FREQ_SEL_MULTICAST & PER_CS_TRAINING_MULTICAST SET (for safety)
        ***********************************************************************/
-       ddr_setval_ach(_reg_PHY_FREQ_SEL_MULTICAST_EN, 0x01);
+       reg_ddrphy_write_a(ddr_regdef_adr(_reg_PHY_FREQ_SEL_MULTICAST_EN),
+               (0x01U << ddr_regdef_lsb(_reg_PHY_FREQ_SEL_MULTICAST_EN)));
        ddr_setval_ach_as(_reg_PHY_PER_CS_TRAINING_MULTICAST_EN, 0x01);
 
        /***********************************************************************
@@ -1613,11 +1617,12 @@ static void ddrtbl_load(void)
  ******************************************************************************/
 static void ddr_config_sub(void)
 {
-       int32_t i;
+       uint32_t i;
        uint32_t ch, slice;
        uint32_t dataL;
        uint32_t tmp;
        uint8_t high_byte[SLICE_CNT];
+       const uint32_t _par_CALVL_DEVICE_MAP = 1;
        foreach_vch(ch) {
        /***********************************************************************
        BOARD SETTINGS (DQ,DM,VREF_DRIVING)
@@ -1645,8 +1650,6 @@ static void ddr_config_sub(void)
        /***********************************************************************
                BOARD SETTINGS (CA,ADDR_SEL)
        ***********************************************************************/
-               const uint32_t _par_CALVL_DEVICE_MAP = 1;
-
                dataL = (0x00ffffff & (uint32_t)(Boardcnf->ch[ch].ca_swap)) |
                        0x00888888;
 
@@ -1771,11 +1774,20 @@ static void ddr_config_sub_h3v1x(void)
        uint32_t dataL;
        uint32_t tmp;
        uint8_t high_byte[SLICE_CNT];
+       uint32_t ca_swizzle;
+       uint32_t ca;
+       uint32_t csmap;
+       uint32_t o_inv;
+       uint32_t inv;
+       uint32_t bit_soc;
+       uint32_t bit_mem;
+       uint32_t j;
+
+       const uint8_t o_mr15 = 0x55;
+       const uint8_t o_mr20 = 0x55;
+       const uint16_t o_mr32_mr40 = 0x5a3c;
 
        foreach_vch(ch) {
-               uint32_t ca_swizzle;
-               uint32_t ca;
-               uint32_t csmap;
        /***********************************************************************
                BOARD SETTINGS (DQ,DM,VREF_DRIVING)
        ***********************************************************************/
@@ -1817,15 +1829,6 @@ static void ddr_config_sub_h3v1x(void)
                ddr_setval(ch, _reg_PHY_ADR_CALVL_DEVICE_MAP, 0x01);
 
                for (slice = 0; slice < SLICE_CNT; slice++) {
-                       const uint8_t o_mr15 = 0x55;
-                       const uint8_t o_mr20 = 0x55;
-                       const uint16_t o_mr32_mr40 = 0x5a3c;
-                       uint32_t o_inv;
-                       uint32_t inv;
-                       uint32_t bit_soc;
-                       uint32_t bit_mem;
-                       uint32_t j;
-
                        ddr_setval_s(ch, slice, _reg_PI_RDLVL_PATTERN_NUM,
                                     0x01);
                        ddr_setval_s(ch, slice, _reg_PI_RDLVL_PATTERN_START,
@@ -1862,6 +1865,14 @@ static void ddr_config(void)
        uint32_t ch, slice;
        uint32_t dataL;
        uint32_t tmp;
+       int8_t _adj;
+       int16_t adj;
+       uint32_t dq;
+       union {
+               uint32_t ui32[4];
+               uint8_t ui8[16];
+       } patt;
+       uint16_t patm;
 
        /***********************************************************************
        configure ddrphy registers
@@ -1876,11 +1887,6 @@ static void ddr_config(void)
        WDQ_USER_PATT
        ***********************************************************************/
        foreach_vch(ch) {
-               union {
-                       uint32_t ui32[4];
-                       uint8_t ui8[16];
-               } patt;
-               uint16_t patm;
                for (slice = 0; slice < SLICE_CNT; slice++) {
                        patm = 0;
                        for (i = 0; i < 16; i++) {
@@ -1905,48 +1911,65 @@ static void ddr_config(void)
        CACS DLY
        ***********************************************************************/
        dataL = Boardcnf->cacs_dly + _f_scale_adj(Boardcnf->cacs_dly_adj);
-
-       if ((Prr_Product == PRR_PRODUCT_H3) && (Prr_Cut <= PRR_PRODUCT_11)) {
-               set_dfifrequency(0x1f);
-       } else {
-               ddr_setval_ach(_reg_PHY_FREQ_SEL_MULTICAST_EN, 0x00);
-               ddr_setval_ach(_reg_PHY_FREQ_SEL_INDEX, 0x01);
-       }
-
+       reg_ddrphy_write_a(ddr_regdef_adr(_reg_PHY_FREQ_SEL_MULTICAST_EN), 0x00U);
        foreach_vch(ch) {
-               int16_t adj;
-               for (i = 0; i < _reg_PHY_CLK_CACS_SLAVE_DELAY_X_NUM; i++) {
+               for (i = 0; i < (_reg_PHY_CLK_CACS_SLAVE_DELAY_X_NUM - 4); i++) {
                        adj = _f_scale_adj(Boardcnf->ch[ch].cacs_adj[i]);
-                       ddr_setval(ch, _reg_PHY_CLK_CACS_SLAVE_DELAY_X[i],
-                                  dataL + adj);
+                       ddrtbl_setval(_cnf_DDR_PHY_ADR_V_REGSET,
+                                     _reg_PHY_CLK_CACS_SLAVE_DELAY_X[i],
+                                     dataL + adj);
+                       reg_ddrphy_write(ch,
+                                       ddr_regdef_adr(
+                                       _reg_PHY_CLK_CACS_SLAVE_DELAY_X[i]),
+                                       _cnf_DDR_PHY_ADR_V_REGSET[
+                                       ddr_regdef_adr(
+                                       _reg_PHY_CLK_CACS_SLAVE_DELAY_X[i]) -
+                                       DDR_PHY_ADR_V_REGSET_OFS]);
+               }
+
+               for (i = (_reg_PHY_CLK_CACS_SLAVE_DELAY_X_NUM - 4);
+                    i < _reg_PHY_CLK_CACS_SLAVE_DELAY_X_NUM; i++) {
+                       adj = _f_scale_adj(Boardcnf->ch[ch].cacs_adj[i]);
+                       ddrtbl_setval(_cnf_DDR_PHY_ADR_G_REGSET,
+                                     _reg_PHY_CLK_CACS_SLAVE_DELAY_X[i],
+                                     dataL + adj);
+                       reg_ddrphy_write(ch,
+                                       ddr_regdef_adr(
+                                       _reg_PHY_CLK_CACS_SLAVE_DELAY_X[i]),
+                                       _cnf_DDR_PHY_ADR_G_REGSET[
+                                       ddr_regdef_adr(
+                                       _reg_PHY_CLK_CACS_SLAVE_DELAY_X[i]) -
+                                       DDR_PHY_ADR_G_REGSET_OFS]);
                }
+
                if (ddr_phycaslice == 1) {
                        for (i = 0; i < 6; i++) {
-                               adj =
-                                   _f_scale_adj(Boardcnf->ch[ch].cacs_adj[i +
-                                   _reg_PHY_CLK_CACS_SLAVE_DELAY_X_NUM]);
-                               ddr_setval_s(ch, 2,
-                                            _reg_PHY_CLK_CACS_SLAVE_DELAY_X[i],
-                                            dataL + adj);
+                               adj = _f_scale_adj(
+                                       Boardcnf->ch[ch].cacs_adj[
+                                       i + _reg_PHY_CLK_CACS_SLAVE_DELAY_X_NUM]);
+                               ddrtbl_setval(_cnf_DDR_PHY_ADR_V_REGSET,
+                                             _reg_PHY_CLK_CACS_SLAVE_DELAY_X[i],
+                                             dataL + adj);
+                               reg_ddrphy_write(ch,
+                                       ddr_regdef_adr(
+                                       _reg_PHY_CLK_CACS_SLAVE_DELAY_X[i]) +
+                                       0x0100,
+                                       _cnf_DDR_PHY_ADR_V_REGSET[
+                                       ddr_regdef_adr(
+                                       _reg_PHY_CLK_CACS_SLAVE_DELAY_X[i]) -
+                                       DDR_PHY_ADR_V_REGSET_OFS]);
                        }
                }
        }
 
-       if ((Prr_Product == PRR_PRODUCT_H3) && (Prr_Cut <= PRR_PRODUCT_11)) {
-               set_dfifrequency(0x00);
-       } else {
-               ddr_setval_ach(_reg_PHY_FREQ_SEL_MULTICAST_EN, 0x01);
-               ddr_setval_ach(_reg_PHY_FREQ_SEL_INDEX, 0x00);
-       }
+       reg_ddrphy_write_a(ddr_regdef_adr(_reg_PHY_FREQ_SEL_MULTICAST_EN),
+               (0x01U << ddr_regdef_lsb(_reg_PHY_FREQ_SEL_MULTICAST_EN)));
 
        /***********************************************************************
        WDQDM DLY
        ***********************************************************************/
        dataL = Boardcnf->dqdm_dly_w;
        foreach_vch(ch) {
-               int8_t _adj;
-               int16_t adj;
-               uint32_t dq;
                for (slice = 0; slice < SLICE_CNT; slice++) {
                        for (i = 0; i <= 8; i++) {
                                dq = slice * 8 + i;
@@ -1967,9 +1990,6 @@ static void ddr_config(void)
        ***********************************************************************/
        dataL = Boardcnf->dqdm_dly_r;
        foreach_vch(ch) {
-               int8_t _adj;
-               int16_t adj;
-               uint32_t dq;
                for (slice = 0; slice < SLICE_CNT; slice++) {
                        for (i = 0; i <= 8; i++) {
                                dq = slice * 8 + i;
@@ -2041,6 +2061,7 @@ static void dbsc_regset(void)
        int32_t i;
        uint32_t ch;
        uint32_t dataL;
+       uint32_t dataL2;
        uint32_t tmp[4];
 
        /* RFC */
@@ -2193,7 +2214,6 @@ static void dbsc_regset(void)
 #define _par_DBRNK_VAL         (0x7007)
 
        for (i = 0; i < 4; i++) {
-               uint32_t dataL2;
                dataL = (_par_DBRNK_VAL >> (i * 4)) & 0x0f;
                if ((Prr_Product == PRR_PRODUCT_H3)
                    && (Prr_Cut > PRR_PRODUCT_11) && (i == 0)) {
@@ -2559,7 +2579,7 @@ static uint32_t dfi_init_start(void)
        retry = 0;
        while (retry++ < RETRY_MAX) {
                foreach_vch(ch) {
-                       dataL = mmio_read_32(DBSC_INITCOMP(ch));
+                       dataL = mmio_read_32(DBSC_DBDFISTAT(ch));
                        if (dataL & 0x00000001)
                                phytrainingok |= (1U << ch);
                }
@@ -2627,6 +2647,9 @@ static uint32_t set_term_code(void)
        uint32_t chip_id[2];
        uint32_t term_code;
        uint32_t override;
+       uint32_t pvtr;
+       uint32_t pvtp;
+       uint32_t pvtn;
        term_code = ddrtbl_getval(_cnf_DDR_PHY_ADR_G_REGSET,
                                  _reg_PHY_PAD_DATA_TERM);
        override = 0;
@@ -2652,7 +2675,7 @@ static uint32_t set_term_code(void)
                        dataL =
                            ddrtbl_getval(_cnf_DDR_PHY_ADR_G_REGSET,
                                          _reg_PHY_PAD_TERM_X[index]);
-                       dataL = (dataL & ~0x0001ffff) | term_code;
+                       dataL = (dataL & 0xfffe0000) | term_code;
                        ddr_setval_ach(_reg_PHY_PAD_TERM_X[index], dataL);
                }
        } else if ((Prr_Product == PRR_PRODUCT_M3)
@@ -2674,9 +2697,6 @@ static uint32_t set_term_code(void)
                if ((Prr_Product == PRR_PRODUCT_H3)
                    && (Prr_Cut <= PRR_PRODUCT_11)) {
                        foreach_vch(ch) {
-                               uint32_t pvtr;
-                               uint32_t pvtp;
-                               uint32_t pvtn;
                                dataL = ddr_getval(ch, _reg_PHY_PAD_TERM_X[0]);
                                pvtr = (dataL >> 12) & 0x1f;
                                pvtr += 8;
@@ -2693,7 +2713,7 @@ static uint32_t set_term_code(void)
                                            ddrtbl_getval
                                            (_cnf_DDR_PHY_ADR_G_REGSET,
                                             _reg_PHY_PAD_TERM_X[index]);
-                                       dataL = (dataL & ~0x0001ffff)
+                                       dataL = (dataL & 0xfffe0000)
                                            | (pvtr << 12)
                                            | (pvtn << 6)
                                            | (pvtp);
@@ -2969,6 +2989,7 @@ static uint32_t init_ddr(void)
        uint32_t phytrainingok;
        uint32_t ch, slice;
        uint32_t err;
+       int16_t adj;
 
        MSG_LF("init_ddr:0\n");
 
@@ -3130,7 +3151,8 @@ static uint32_t init_ddr(void)
        /***********************************************************************
        exec pi_training
        ***********************************************************************/
-       ddr_setval_ach(_reg_PHY_FREQ_SEL_MULTICAST_EN, 0x00);
+       reg_ddrphy_write_a(ddr_regdef_adr(_reg_PHY_FREQ_SEL_MULTICAST_EN),
+                          BIT(ddr_regdef_lsb(_reg_PHY_FREQ_SEL_MULTICAST_EN)));
        ddr_setval_ach_as(_reg_PHY_PER_CS_TRAINING_MULTICAST_EN, 0x00);
 
        if ((Prr_Product == PRR_PRODUCT_H3) && (Prr_Cut <= PRR_PRODUCT_11)) {
@@ -3159,7 +3181,6 @@ static uint32_t init_ddr(void)
        ***********************************************************************/
        dataL = Boardcnf->cacs_dly + _f_scale_adj(Boardcnf->cacs_dly_adj);
        foreach_vch(ch) {
-               int16_t adj;
                for (i = 0; i < _reg_PHY_CLK_CACS_SLAVE_DELAY_X_NUM; i++) {
                        adj = _f_scale_adj(Boardcnf->ch[ch].cacs_adj[i]);
                        ddr_setval(ch, _reg_PHY_CLK_CACS_SLAVE_DELAY_X[i],
@@ -3563,6 +3584,7 @@ static uint32_t wdqdm_man(void)
 {
        uint32_t err, retry_cnt;
        const uint32_t retry_max = 0x10;
+       uint32_t ch, ddr_csn, mr14_bkup[4][4];
 
        ddr_setval_ach(_reg_PI_TDFI_WDQLVL_RW, (DBSC_DBTR(11) & 0xFF) + 12);
        if (((Prr_Product == PRR_PRODUCT_H3) && (Prr_Cut > PRR_PRODUCT_11))
@@ -3577,13 +3599,12 @@ static uint32_t wdqdm_man(void)
        ddr_setval_ach(_reg_PI_TRFC_F1, (DBSC_DBTR(13) & 0x1FF));
 
        retry_cnt = 0;
+       err = 0;
        do {
                if ((Prr_Product == PRR_PRODUCT_H3)
                    && (Prr_Cut <= PRR_PRODUCT_11)) {
                        err = wdqdm_man1();
                } else {
-                       uint32_t ch, ddr_csn, mr14_bkup[4][4];
-
                        ddr_setval_ach(_reg_PI_WDQLVL_VREF_EN, 0x01);
                        ddr_setval_ach(_reg_PI_WDQLVL_VREF_NORMAL_STEPSIZE,
                                       0x01);
@@ -3720,15 +3741,15 @@ static uint32_t rdqdm_ana1(uint32_t ch, uint32_t ddr_csn)
        int8_t _adj;
        int16_t adj;
        uint32_t dq;
+       int32_t min_win;
+       int32_t win;
+       uint32_t rdq_status_obs_select;
 
        /***********************************************************************
        analysis of training results
        ***********************************************************************/
        err = 0;
        for (slice = 0; slice < SLICE_CNT; slice++) {
-               int32_t min_win;
-               int32_t win;
-               uint32_t rdq_status_obs_select;
                k = (Boardcnf->ch[ch].dqs_swap >> (4 * slice)) & 0x0f;
                if (((k >= 2) && (ddr_csn < 2)) || ((k < 2) && (ddr_csn >= 2)))
                        continue;
@@ -3828,6 +3849,7 @@ static uint32_t rdqdm_man1(void)
        uint32_t ddr_csn;
 #ifdef DDR_FAST_INIT
        uint32_t slice;
+       uint32_t i, adj, dataL;
 #endif/* DDR_FAST_INIT */
        uint32_t err;
 
@@ -3836,7 +3858,7 @@ static uint32_t rdqdm_man1(void)
        ***********************************************************************/
        err = 0;
 
-       for (ddr_csn = 0; ddr_csn < CS_CNT; ddr_csn++) {
+       for (ddr_csn = 0; ddr_csn < CSAB_CNT; ddr_csn++) {
                /* KICK RDQLVL */
                err = swlvl1(ddr_csn, _reg_PI_RDLVL_CS, _reg_PI_RDLVL_REQ);
                if (err)
@@ -3870,8 +3892,6 @@ static uint32_t rdqdm_man1(void)
                            && (Prr_Cut <= PRR_PRODUCT_11))
                            || ((Prr_Product == PRR_PRODUCT_M3)
                            && (Prr_Cut <= PRR_PRODUCT_10))) {
-                               uint32_t i, adj, dataL;
-
                                for (slice = 0; slice < SLICE_CNT; slice++) {
                                        for (i = 0; i <= 8; i++) {
                                                if (i == 8)
@@ -3948,7 +3968,7 @@ static int32_t _find_change(uint64_t val, uint32_t dir)
        int32_t i;
        uint32_t startval;
        uint32_t curval;
-       const uint32_t VAL_END = 0x3f;
+       const int32_t VAL_END = 0x3f;
 
        if (dir == 0) {
                startval = (val & 0x01);
@@ -4004,6 +4024,8 @@ static uint32_t rx_offset_cal(void)
        uint32_t tmp;
        uint32_t tmp_ach_as[DRAM_CH_CNT][SLICE_CNT];
        uint64_t val[DRAM_CH_CNT][SLICE_CNT][_reg_PHY_RX_CAL_X_NUM];
+       uint64_t tmpval;
+       int32_t lsb, msb;
 
        ddr_setval_ach_as(_reg_PHY_RX_CAL_OVERRIDE, 0x01);
        foreach_vch(ch) {
@@ -4041,8 +4063,6 @@ static uint32_t rx_offset_cal(void)
        foreach_vch(ch) {
                for (slice = 0; slice < SLICE_CNT; slice++) {
                        for (index = 0; index < _reg_PHY_RX_CAL_X_NUM; index++) {
-                               uint64_t tmpval;
-                               int32_t lsb, msb;
                                tmpval = val[ch][slice][index];
                                lsb = _find_change(tmpval, 0);
                                msb =
@@ -4201,10 +4221,10 @@ int32_t rcar_dram_init(void)
        Thermal sensor setting
        ***********************************************************************/
        dataL = mmio_read_32(CPG_MSTPSR5);
-       if (dataL & BIT22) {    /*  case THS/TSC Standby */
-               dataL &= ~(BIT22);
+       if (dataL & BIT(22)) {  /*  case THS/TSC Standby */
+               dataL &= ~(BIT(22));
                cpg_write_32(CPG_SMSTPCR5, dataL);
-               while ((BIT22) & mmio_read_32(CPG_MSTPSR5));  /*  wait bit=0 */
+               while ((BIT(22)) & mmio_read_32(CPG_MSTPSR5));  /*  wait bit=0 */
        }
 
        /* THCTR Bit6: PONM=0 , Bit0: THSST=0   */
@@ -4230,15 +4250,15 @@ int32_t rcar_dram_init(void)
 
        if (Prr_Product == PRR_PRODUCT_H3) {
                if (Prr_Cut <= PRR_PRODUCT_11) {
-                       pDDR_REGDEF_TBL = (uint32_t *) & DDR_REGDEF_TBL[0][0];
+                       pDDR_REGDEF_TBL = (const uint32_t *)&DDR_REGDEF_TBL[0][0];
                } else {
-                       pDDR_REGDEF_TBL = (uint32_t *) & DDR_REGDEF_TBL[2][0];
+                       pDDR_REGDEF_TBL = (const uint32_t *)&DDR_REGDEF_TBL[2][0];
                }
        } else if (Prr_Product == PRR_PRODUCT_M3) {
-               pDDR_REGDEF_TBL = (uint32_t *) & DDR_REGDEF_TBL[1][0];
+               pDDR_REGDEF_TBL = (const uint32_t *)&DDR_REGDEF_TBL[1][0];
        } else if ((Prr_Product == PRR_PRODUCT_M3N)
                   || (Prr_Product == PRR_PRODUCT_V3H)) {
-               pDDR_REGDEF_TBL = (uint32_t *) & DDR_REGDEF_TBL[3][0];
+               pDDR_REGDEF_TBL = (const uint32_t *)&DDR_REGDEF_TBL[3][0];
        } else {
                FATAL_MSG("BL2: DDR:Unknown Product\n");
                return 0xff;
@@ -4259,7 +4279,7 @@ int32_t rcar_dram_init(void)
                FATAL_MSG("BL2: DDR:Unknown Board\n");
                return 0xff;
        }
-       Boardcnf = (struct _boardcnf *)&boardcnfs[_cnf_BOARDTYPE];
+       Boardcnf = (const struct _boardcnf *)&boardcnfs[_cnf_BOARDTYPE];
 
 /* RCAR_DRAM_SPLIT_2CH           (2U) */
 #if RCAR_DRAM_SPLIT == 2
@@ -4327,6 +4347,8 @@ int32_t rcar_dram_init(void)
        Adjust tccd
        ***********************************************************************/
        dataL = (0x00006000 & mmio_read_32(RST_MODEMR)) >> 13;
+       bus_mbps = 0;
+       bus_mbpsdiv = 0;
        switch (dataL) {
        case 0:
                bus_mbps = brd_clk * 0x60 * 2;
index 513bb035757b372ab5df341454eef1abf6427445..5d1b078c9b483c1e67805864e068a35b5b662bde 100644 (file)
@@ -1,10 +1,10 @@
 /*
- * Copyright (c) 2015-2018, Renesas Electronics Corporation. All rights reserved.
+ * Copyright (c) 2015-2019, Renesas Electronics Corporation. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
-#define BOARDNUM 20
+#define BOARDNUM 22
 #define BOARD_JUDGE_AUTO
 
 #ifdef BOARD_JUDGE_AUTO
@@ -1425,6 +1425,108 @@ static const struct _boardcnf boardcnfs[BOARDNUM] = {
          }
         }
        },
+/* boardcnf[20] RENESAS KRIEK 16Gbit/2rank/2ch board with M3-W/SoC */
+        {
+         0x03,
+         0x01,
+         0x02c0,
+         0,
+         0x0300,
+         0x00a0,
+         {
+          {
+           {0x04, 0x04},
+            0x00345201,
+            0x3201,
+           {0x01672543, 0x45361207, 0x45632107, 0x60715234},
+           {0x08, 0x08, 0x08, 0x08},
+            WDQLVL_PAT,
+           {0, 0, 0, 0, 0, 0, 0, 0,
+           0, 0},
+           {0, 0, 0, 0},
+           {0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0},
+           {0, 0, 0, 0},
+           {0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0}
+           },
+          {
+          {0x04, 0x04},
+            0x00302154,
+            0x2310,
+           {0x01672543, 0x45361207, 0x45632107, 0x60715234},
+           {0x08, 0x08, 0x08, 0x08},
+           WDQLVL_PAT,
+           {0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0},
+           {0, 0, 0, 0},
+           {0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0},
+           {0, 0, 0, 0},
+           {0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0}
+          }
+         }
+        },
+/* boardcnf[21] RENESAS KRIEK 16Gbit/1rank/2ch board with M3-W/SoC */
+        {
+         0x03,
+         0x01,
+         0x02c0,
+         0,
+         0x0300,
+         0x00a0,
+         {
+          {
+           {0x04, 0xff},
+            0x00345201,
+            0x3201,
+           {0x01672543, 0x45361207, 0x45632107, 0x60715234},
+           {0x08, 0x08, 0x08, 0x08},
+           WDQLVL_PAT,
+           {0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0},
+           {0, 0, 0, 0},
+           {0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0},
+           {0, 0, 0, 0},
+           {0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0}
+           },
+          {
+           {0x04, 0xff},
+            0x00302154,
+            0x2310,
+           {0x01672543, 0x45361207, 0x45632107, 0x60715234},
+           {0x08, 0x08, 0x08, 0x08},
+           WDQLVL_PAT,
+           {0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0},
+           {0, 0, 0, 0},
+           {0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0},
+           {0, 0, 0, 0},
+           {0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0,
+            0, 0, 0, 0, 0, 0, 0, 0}
+           }
+          }
+         }
 };
 
 void boardcnf_get_brd_clk(uint32_t brd, uint32_t * clk, uint32_t * div)
@@ -1521,12 +1623,7 @@ static const uint32_t TermcodeBySample[20][3] = {
 #define PFC_PUD6       0xE6060458U
 #define GPIO_INDT5     0xE605500CU
 #define GPIO_INDT6     0xE605540CU
-
-#define BIT25          (1<<25)
-#define BIT22          (1<<22)
-#define BIT15          (1<<15)
-#define BIT0           (1)
-#define GPIO_GPSR6     (0xE6060118U)
+#define GPIO_GPSR6     0xE6060118U
 
 #if (RCAR_GEN3_ULCB == 0)
 static void pfc_write_and_poll(uint32_t a, uint32_t v)
@@ -1557,17 +1654,17 @@ static uint32_t opencheck_SSI_WS6(void)
        pud5_bak = mmio_read_32(PFC_PUD5);
        dsb_sev();
 
-       dataL = (gpsr6_bak & ~BIT15);
+       dataL = (gpsr6_bak & ~BIT(15));
        pfc_write_and_poll(GPIO_GPSR6, dataL);
 
        /* Pull-Up/Down Enable (PUEN5[22]=1) */
        dataL = puen5_bak;
-       dataL |= (BIT22);
+       dataL |= (BIT(22));
        pfc_write_and_poll(PFC_PUEN5, dataL);
 
        /* Pull-Down-Enable (PUD5[22]=0, PUEN5[22]=1) */
        dataL = pud5_bak;
-       dataL &= ~(BIT22);
+       dataL &= ~(BIT(22));
        pfc_write_and_poll(PFC_PUD5, dataL);
        /* GPSR6[15]=SSI_WS6 */
        rcar_micro_delay(10);
@@ -1576,7 +1673,7 @@ static uint32_t opencheck_SSI_WS6(void)
 
        /* Pull-Up-Enable (PUD5[22]=1, PUEN5[22]=1) */
        dataL = pud5_bak;
-       dataL |= (BIT22);
+       dataL |= (BIT(22));
        pfc_write_and_poll(PFC_PUD5, dataL);
 
        /* GPSR6[15]=SSI_WS6 */
@@ -1673,7 +1770,7 @@ static uint32_t _board_judge(void)
                        /* RENESAS SALVATOR-X (M3-W/SIP) */
                        brd = 0;
                } else if ((Prr_Product == PRR_PRODUCT_M3) && (Prr_Cut < PRR_PRODUCT_30)) {
-                       /* RENESAS SALVATOR-X (M3-W Ver.1.3/SIP) */
+                       /* RENESAS SALVATOR-X (M3-W Ver.1.x/SIP) */
                        brd = 19;
                } else if ((Prr_Product == PRR_PRODUCT_M3) && (Prr_Cut >= PRR_PRODUCT_30)) {
                        /* RENESAS SALVATOR-X (M3-W ver.3.0/SIP) */
index 24ff83395c2aae632f9a53c0ac05b3183dfbd5b6..a1cbfbf9c3a4ab9042221056805f50d62dcacd87 100644 (file)
@@ -4,7 +4,7 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
-#define RCAR_DDR_VERSION       "rev.0.35"
+#define RCAR_DDR_VERSION       "rev.0.36"
 #define DRAM_CH_CNT            (0x04)
 #define SLICE_CNT              (0x04)
 #define CS_CNT                 (0x02)
 #define DBSC_DBDFIPMSTRCNF     0xE6790520U
 #define DBSC_DBDFICUPDCNF      0xE679052CU
 
-#define DBSC_INITCOMP(ch)      (0xE6790600U + 0x40U * (ch))
-#define DBSC_INITCOMP_0                0xE6790600U
-#define DBSC_INITCOMP_1                0xE6790640U
-#define DBSC_INITCOMP_2                0xE6790680U
-#define DBSC_INITCOMP_3                0xE67906C0U
+#define DBSC_DBDFISTAT(ch)     (0xE6790600U + 0x40U * (ch))
+#define DBSC_DBDFISTAT_0               0xE6790600U
+#define DBSC_DBDFISTAT_1               0xE6790640U
+#define DBSC_DBDFISTAT_2               0xE6790680U
+#define DBSC_DBDFISTAT_3               0xE67906C0U
 
 #define DBSC_DBDFICNT(ch)      (0xE6790604U + 0x40U * (ch))
 #define DBSC_DBDFICNT_0                0xE6790604U
index b29c77388d00718bb32ea33fbfb4570c71467903..bad1de90f7d86d27ff26ac59ad708e56efeacd66 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Renesas Electronics Corporation. All rights reserved.
+ * Copyright (c) 2018-2019, Renesas Electronics Corporation. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
 #define DDR_REGDEF_LEN(regdef) (((regdef)>>16)&0xff)
 #define DDR_REGDEF_LSB(regdef) (((regdef)>>24)&0xff)
 
-const static uint32_t DDR_REGDEF_TBL[4][1173] = {
+static const uint32_t DDR_REGDEF_TBL[4][1173] = {
        {
 /*0000*/ 0xffffffffU,
 /*0001*/ 0xffffffffU,
index 39fc8a6336f6f121df5d4b242b28f6433d9ea00f..6fa9ab99db7d2a6eb151027f75f73de7447f71b5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2018, Renesas Electronics Corporation. All rights reserved.
+ * Copyright (c) 2015-2019, Renesas Electronics Corporation. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
index b0dcaa73907b45c67d355455c279737bb4003962..04f467327bf91c5ee49bf988c472a6607456f7ab 100644 (file)
@@ -14,6 +14,7 @@
 #include <drivers/delay_timer.h>
 #include <drivers/mmc.h>
 #include <drivers/synopsys/dw_mmc.h>
+#include <lib/utils_def.h>
 #include <lib/mmio.h>
 
 #define DWMMC_CTRL                     (0x00)
@@ -55,7 +56,7 @@
 
 #define DWMMC_CMDARG                   (0x28)
 #define DWMMC_CMD                      (0x2c)
-#define CMD_START                      (1 << 31)
+#define CMD_START                      (U(1) << 31)
 #define CMD_USE_HOLD_REG               (1 << 29)       /* 0 if SDR50/100 */
 #define CMD_UPDATE_CLK_ONLY            (1 << 21)
 #define CMD_SEND_INIT                  (1 << 15)
 #define IDMAC_DES0_CH                  (1 << 4)
 #define IDMAC_DES0_ER                  (1 << 5)
 #define IDMAC_DES0_CES                 (1 << 30)
-#define IDMAC_DES0_OWN                 (1 << 31)
+#define IDMAC_DES0_OWN                 (U(1) << 31)
 #define IDMAC_DES1_BS1(x)              ((x) & 0x1fff)
 #define IDMAC_DES2_BS2(x)              (((x) & 0x1fff) << 13)
 
@@ -425,7 +426,6 @@ void dw_mmc_init(dw_mmc_params_t *params, struct mmc_device_info *info)
                (params->bus_width == MMC_BUS_WIDTH_8)));
 
        memcpy(&dw_params, params, sizeof(dw_mmc_params_t));
-       mmio_write_32(dw_params.reg_base + DWMMC_FIFOTH, 0x103ff);
        dw_params.mmc_dev_type = info->mmc_dev_type;
        mmc_init(&dw_mmc_ops, params->clk_rate, params->bus_width,
                 params->flags, info);
diff --git a/fdts/a5ds.dts b/fdts/a5ds.dts
new file mode 100644 (file)
index 0000000..8bc4adf
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/dts-v1/;
+
+/ {
+       model = "A5DS";
+       compatible = "arm,A5DS";
+       interrupt-parent = <&gic>;
+       #address-cells = <1>;
+       #size-cells = <1>;
+       cpus {
+               #address-cells = <1>;
+               #size-cells = <0>;
+               cpu@0 {
+                       device_type = "cpu";
+                       compatible = "arm,cortex-a5";
+                       reg = <0>;
+               };
+       };
+
+       memory@80000000 {
+               device_type = "memory";
+               reg = <0x80000000 0x7F000000>;
+       };
+
+       refclk100mhz: refclk100mhz {
+               compatible = "fixed-clock";
+               #clock-cells = <0>;
+               clock-frequency = <100000000>;
+               clock-output-names = "apb_pclk";
+       };
+
+       smbclk: refclk24mhzx2 {
+               compatible = "fixed-clock";
+               #clock-cells = <0>;
+               clock-frequency = <48000000>;
+               clock-output-names = "smclk";
+       };
+
+
+       rtc@1a220000 {
+               compatible = "arm,pl031", "arm,primecell";
+               reg = <0x1a220000 0x1000>;
+               clocks = <&refclk100mhz>;
+               interrupts = <0 6 0xf04>;
+               clock-names = "apb_pclk";
+       };
+
+       gic: interrupt-controller@1c001000 {
+               compatible = "arm,cortex-a9-gic";
+               #interrupt-cells = <3>;
+               #address-cells = <0>;
+               interrupt-controller;
+               reg = <0x1c001000 0x1000>,
+                         <0x1c000100 0x100>;
+               interrupts = <1 9 0xf04>;
+       };
+
+       serial0: uart@1a200000 {
+               compatible = "arm,pl011", "arm,primecell";
+               reg = <0x1a200000 0x1000>;
+               interrupt-parent = <&gic>;
+               interrupts = <0 8 0xf04>;
+               clocks = <&refclk100mhz>;
+               clock-names = "apb_pclk";
+       };
+
+       serial1: uart@1a210000 {
+               compatible = "arm,pl011", "arm,primecell";
+               reg = <0x1a210000 0x1000>;
+               interrupt-parent = <&gic>;
+               interrupts = <0 9 0xf04>;
+               clocks = <&refclk100mhz>;
+               clock-names = "apb_pclk";
+       };
+
+       timer0: timer@1a040000 {
+               compatible = "arm,armv7-timer-mem";
+               #address-cells = <1>;
+               #size-cells = <1>;
+               ranges;
+               reg = <0x1a040000 0x1000>;
+               clock-frequency = <50000000>;
+
+               frame@1a050000 {
+                       frame-number = <0>;
+                       interrupts = <0 2 0xf04>;
+                       reg = <0x1a050000 0x1000>;
+               };
+       };
+};
index 070be849de95fa8111685037ae0bb7cfd9bbc987..996cb327f3f2fcd07e6d07736bf3dc933d9c2c2e 100644 (file)
@@ -15,7 +15,7 @@
  * default consoles are enabled for the "boot" and "crash" states, this can be
  * changed after registration with the console_set_scope() function). It ends
  * with a tail call that will include return to the caller.
- * REQUIRES console_t pointer in x0 and a valid return address in x30.
+ * REQUIRES console_t pointer in r0 and a valid return address in lr.
  */
        .macro  finish_console_register _driver, putc=0, getc=0, flush=0
        /*
index 502b86813957440dc09b7848acbf8602c9169ae2..e4147d7e97ab6ed32807c04e155fb59b8f0d3db3 100644 (file)
 
 #define BTI_IMPLEMENTED                ULL(1)  /* The BTI mechanism is implemented */
 
+#define ID_AA64PFR1_EL1_MTE_SHIFT      U(8)
+#define ID_AA64PFR1_EL1_MTE_MASK       ULL(0xf)
+
+#define MTE_UNIMPLEMENTED      ULL(0)
+#define MTE_IMPLEMENTED_EL0    ULL(1)  /* MTE is only implemented at EL0 */
+#define MTE_IMPLEMENTED_ELX    ULL(2)  /* MTE is implemented at all ELs */
+
 /* ID_PFR1_EL1 definitions */
 #define ID_PFR1_VIRTEXT_SHIFT  U(12)
 #define ID_PFR1_VIRTEXT_MASK   U(0xf)
 #define SCTLR_SED_BIT          (ULL(1) << 8)
 #define SCTLR_UMA_BIT          (ULL(1) << 9)
 #define SCTLR_I_BIT            (ULL(1) << 12)
-#define SCTLR_V_BIT            (ULL(1) << 13)
+#define SCTLR_EnDB_BIT         (ULL(1) << 13)
 #define SCTLR_DZE_BIT          (ULL(1) << 14)
 #define SCTLR_UCT_BIT          (ULL(1) << 15)
 #define SCTLR_NTWI_BIT         (ULL(1) << 16)
 #define SCTLR_E0E_BIT          (ULL(1) << 24)
 #define SCTLR_EE_BIT           (ULL(1) << 25)
 #define SCTLR_UCI_BIT          (ULL(1) << 26)
+#define SCTLR_EnDA_BIT         (ULL(1) << 27)
+#define SCTLR_EnIB_BIT         (ULL(1) << 30)
 #define SCTLR_EnIA_BIT         (ULL(1) << 31)
 #define SCTLR_BT0_BIT          (ULL(1) << 35)
 #define SCTLR_BT1_BIT          (ULL(1) << 36)
 
 /* SCR definitions */
 #define SCR_RES1_BITS          ((U(1) << 4) | (U(1) << 5))
+#define SCR_ATA_BIT            (U(1) << 26)
 #define SCR_FIEN_BIT           (U(1) << 21)
 #define SCR_API_BIT            (U(1) << 17)
 #define SCR_APK_BIT            (U(1) << 16)
index 1129b8e432995ab175223dc4ac63e69aa3d58ba6..2f29f4873e09e575e388a1bb0eaa796049c32e46 100644 (file)
@@ -54,4 +54,10 @@ static inline bool is_armv8_5_bti_present(void)
                ID_AA64PFR1_EL1_BT_MASK) == BTI_IMPLEMENTED;
 }
 
+static inline unsigned int get_armv8_5_mte_support(void)
+{
+       return ((read_id_aa64pfr1_el1() >> ID_AA64PFR1_EL1_MTE_SHIFT) &
+               ID_AA64PFR1_EL1_MTE_MASK);
+}
+
 #endif /* ARCH_FEATURES_H */
index a10cd8034122ad82be6fd3f901d90ec6de915927..574c4ea0a5b1680452344f3c2ccbd8e686a3f8a9 100644 (file)
@@ -82,7 +82,7 @@
 #define UECDME                         0x48
 /* UTP Transfer Request Interrupt Aggregation Control Register */
 #define UTRIACR                                0x4C
-#define UTRIACR_IAEN                   (1 << 31)
+#define UTRIACR_IAEN                   (1U << 31)
 #define UTRIACR_IAPWEN                 (1 << 24)
 #define UTRIACR_IASB                   (1 << 20)
 #define UTRIACR_CTR                    (1 << 16)
diff --git a/include/lib/cpus/aarch64/cortex_a77.h b/include/lib/cpus/aarch64/cortex_a77.h
new file mode 100644 (file)
index 0000000..0467ef3
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef CORTEX_A77_H
+#define CORTEX_A77_H
+
+#include <lib/utils_def.h>
+
+/* Cortex-A77 MIDR */
+#define CORTEX_A77_MIDR                                        U(0x410FD0D0)
+
+/*******************************************************************************
+ * CPU Extended Control register specific definitions.
+ ******************************************************************************/
+#define CORTEX_A77_CPUECTLR_EL1                                S3_0_C15_C1_4
+
+/*******************************************************************************
+ * CPU Power Control register specific definitions.
+ ******************************************************************************/
+#define CORTEX_A77_CPUPWRCTLR_EL1                      S3_0_C15_C2_7
+#define CORTEX_A77_CPUPWRCTLR_EL1_CORE_PWRDN_BIT       (U(1) << 0)
+
+#endif /* CORTEX_A77_H */
diff --git a/include/lib/cpus/aarch64/cortex_deimos.h b/include/lib/cpus/aarch64/cortex_deimos.h
deleted file mode 100644 (file)
index 9d024b6..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef CORTEX_DEIMOS_H
-#define CORTEX_DEIMOS_H
-
-#include <lib/utils_def.h>
-
-#define CORTEX_DEIMOS_MIDR                                     U(0x410FD0D0)
-
-/*******************************************************************************
- * CPU Extended Control register specific definitions.
- ******************************************************************************/
-#define CORTEX_DEIMOS_CPUECTLR_EL1                             S3_0_C15_C1_4
-
-/*******************************************************************************
- * CPU Power Control register specific definitions.
- ******************************************************************************/
-#define CORTEX_DEIMOS_CPUPWRCTLR_EL1                           S3_0_C15_C2_7
-#define CORTEX_DEIMOS_CPUPWRCTLR_EL1_CORE_PWRDN_BIT            (U(1) << 0)
-
-#endif /* CORTEX_DEIMOS_H */
diff --git a/include/lib/cpus/aarch64/cortex_hercules.h b/include/lib/cpus/aarch64/cortex_hercules.h
new file mode 100644 (file)
index 0000000..86e8af0
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2019, ARM Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef CORTEX_HERCULES_H
+#define CORTEX_HERCULES_H
+
+#include <lib/utils_def.h>
+
+#define CORTEX_HERCULES_MIDR                                   U(0x410FD410)
+
+/*******************************************************************************
+ * CPU Extended Control register specific definitions.
+ ******************************************************************************/
+#define CORTEX_HERCULES_CPUECTLR_EL1                           S3_0_C15_C1_4
+
+/*******************************************************************************
+ * CPU Power Control register specific definitions
+ ******************************************************************************/
+#define CORTEX_HERCULES_CPUPWRCTLR_EL1                         S3_0_C15_C2_7
+#define CORTEX_HERCULES_CPUPWRCTLR_EL1_CORE_PWRDN_EN_BIT       U(1)
+
+#endif /* CORTEX_HERCULES_H */
index b99be304d583e55c08383373948d7bab8e1276ea..b17a435b08b196b323663784d93ef841532b3b21 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -116,3 +116,6 @@ typedef unsigned long uintmax_t;
 
 typedef long register_t;
 typedef unsigned long u_register_t;
+
+typedef __int128 int128_t;
+typedef unsigned __int128 uint128_t;
index 97e67225285123b31248bb983179fc4c23cf8ead..c8260e88abdaff8c66ee7bd5f2d13dcfbd5ac6c6 100644 (file)
@@ -252,7 +252,7 @@ void plat_arm_interconnect_enter_coherency(void);
 void plat_arm_interconnect_exit_coherency(void);
 void plat_arm_program_trusted_mailbox(uintptr_t address);
 int plat_arm_bl1_fwu_needed(void);
-void plat_arm_error_handler(int err);
+__dead2 void plat_arm_error_handler(int err);
 
 #if ARM_PLAT_MT
 unsigned int plat_arm_get_cpu_pe_count(u_register_t mpidr);
diff --git a/lib/cpus/aarch64/cortex_a77.S b/lib/cpus/aarch64/cortex_a77.S
new file mode 100644 (file)
index 0000000..f3fd5e1
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <arch.h>
+#include <asm_macros.S>
+#include <common/bl_common.h>
+#include <cortex_a77.h>
+#include <cpu_macros.S>
+#include <plat_macros.S>
+
+/* Hardware handled coherency */
+#if HW_ASSISTED_COHERENCY == 0
+#error "Cortex-A77 must be compiled with HW_ASSISTED_COHERENCY enabled"
+#endif
+
+/* 64-bit only core */
+#if CTX_INCLUDE_AARCH32_REGS == 1
+#error "Cortex-A77 supports only AArch64. Compile with CTX_INCLUDE_AARCH32_REGS=0"
+#endif
+
+       /* ---------------------------------------------
+        * HW will do the cache maintenance while powering down
+        * ---------------------------------------------
+        */
+func cortex_a77_core_pwr_dwn
+       /* ---------------------------------------------
+        * Enable CPU power down bit in power control register
+        * ---------------------------------------------
+        */
+       mrs     x0, CORTEX_A77_CPUPWRCTLR_EL1
+       orr     x0, x0, #CORTEX_A77_CPUPWRCTLR_EL1_CORE_PWRDN_BIT
+       msr     CORTEX_A77_CPUPWRCTLR_EL1, x0
+       isb
+       ret
+endfunc cortex_a77_core_pwr_dwn
+
+#if REPORT_ERRATA
+/*
+ * Errata printing function for Cortex-A77. Must follow AAPCS.
+ */
+func cortex_a77_errata_report
+       ret
+endfunc cortex_a77_errata_report
+#endif
+
+
+       /* ---------------------------------------------
+        * This function provides Cortex-A77 specific
+        * register information for crash reporting.
+        * It needs to return with x6 pointing to
+        * a list of register names in ascii and
+        * x8 - x15 having values of registers to be
+        * reported.
+        * ---------------------------------------------
+        */
+.section .rodata.cortex_a77_regs, "aS"
+cortex_a77_regs:  /* The ascii list of register names to be reported */
+       .asciz  "cpuectlr_el1", ""
+
+func cortex_a77_cpu_reg_dump
+       adr     x6, cortex_a77_regs
+       mrs     x8, CORTEX_A77_CPUECTLR_EL1
+       ret
+endfunc cortex_a77_cpu_reg_dump
+
+declare_cpu_ops cortex_a77, CORTEX_A77_MIDR, \
+       CPU_NO_RESET_FUNC, \
+       cortex_a77_core_pwr_dwn
diff --git a/lib/cpus/aarch64/cortex_deimos.S b/lib/cpus/aarch64/cortex_deimos.S
deleted file mode 100644 (file)
index df4c128..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include <arch.h>
-#include <asm_macros.S>
-#include <common/bl_common.h>
-#include <cortex_deimos.h>
-#include <cpu_macros.S>
-#include <plat_macros.S>
-
-/* Hardware handled coherency */
-#if HW_ASSISTED_COHERENCY == 0
-#error "Deimos must be compiled with HW_ASSISTED_COHERENCY enabled"
-#endif
-
-/* 64-bit only core */
-#if CTX_INCLUDE_AARCH32_REGS == 1
-#error "Cortex-Deimos supports only AArch64. Compile with CTX_INCLUDE_AARCH32_REGS=0"
-#endif
-
-       /* ---------------------------------------------
-        * HW will do the cache maintenance while powering down
-        * ---------------------------------------------
-        */
-func cortex_deimos_core_pwr_dwn
-       /* ---------------------------------------------
-        * Enable CPU power down bit in power control register
-        * ---------------------------------------------
-        */
-       mrs     x0, CORTEX_DEIMOS_CPUPWRCTLR_EL1
-       orr     x0, x0, #CORTEX_DEIMOS_CPUPWRCTLR_EL1_CORE_PWRDN_BIT
-       msr     CORTEX_DEIMOS_CPUPWRCTLR_EL1, x0
-       isb
-       ret
-endfunc cortex_deimos_core_pwr_dwn
-
-#if REPORT_ERRATA
-/*
- * Errata printing function for Cortex Deimos. Must follow AAPCS.
- */
-func cortex_deimos_errata_report
-       ret
-endfunc cortex_deimos_errata_report
-#endif
-
-
-       /* ---------------------------------------------
-        * This function provides Cortex-Deimos specific
-        * register information for crash reporting.
-        * It needs to return with x6 pointing to
-        * a list of register names in ascii and
-        * x8 - x15 having values of registers to be
-        * reported.
-        * ---------------------------------------------
-        */
-.section .rodata.cortex_deimos_regs, "aS"
-cortex_deimos_regs:  /* The ascii list of register names to be reported */
-       .asciz  "cpuectlr_el1", ""
-
-func cortex_deimos_cpu_reg_dump
-       adr     x6, cortex_deimos_regs
-       mrs     x8, CORTEX_DEIMOS_CPUECTLR_EL1
-       ret
-endfunc cortex_deimos_cpu_reg_dump
-
-declare_cpu_ops cortex_deimos, CORTEX_DEIMOS_MIDR, \
-       CPU_NO_RESET_FUNC, \
-       cortex_deimos_core_pwr_dwn
diff --git a/lib/cpus/aarch64/cortex_hercules.S b/lib/cpus/aarch64/cortex_hercules.S
new file mode 100644 (file)
index 0000000..25287de
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2019, ARM Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <arch.h>
+#include <asm_macros.S>
+#include <common/bl_common.h>
+#include <cortex_hercules.h>
+#include <cpu_macros.S>
+#include <plat_macros.S>
+
+/* Hardware handled coherency */
+#if HW_ASSISTED_COHERENCY == 0
+#error "cortex_hercules must be compiled with HW_ASSISTED_COHERENCY enabled"
+#endif
+
+       /* ---------------------------------------------
+        * HW will do the cache maintenance while powering down
+        * ---------------------------------------------
+        */
+func cortex_hercules_core_pwr_dwn
+       /* ---------------------------------------------
+        * Enable CPU power down bit in power control register
+        * ---------------------------------------------
+        */
+       mrs     x0, CORTEX_HERCULES_CPUPWRCTLR_EL1
+       orr     x0, x0, #CORTEX_HERCULES_CPUPWRCTLR_EL1_CORE_PWRDN_EN_BIT
+       msr     CORTEX_HERCULES_CPUPWRCTLR_EL1, x0
+       isb
+       ret
+endfunc cortex_hercules_core_pwr_dwn
+
+       /*
+        * Errata printing function for cortex_hercules. Must follow AAPCS.
+        */
+#if REPORT_ERRATA
+func cortex_hercules_errata_report
+       ret
+endfunc cortex_hercules_errata_report
+#endif
+
+       /* ---------------------------------------------
+        * This function provides cortex_hercules specific
+        * register information for crash reporting.
+        * It needs to return with x6 pointing to
+        * a list of register names in ascii and
+        * x8 - x15 having values of registers to be
+        * reported.
+        * ---------------------------------------------
+        */
+.section .rodata.cortex_hercules_regs, "aS"
+cortex_hercules_regs:  /* The ascii list of register names to be reported */
+       .asciz  "cpuectlr_el1", ""
+
+func cortex_hercules_cpu_reg_dump
+       adr     x6, cortex_hercules_regs
+       mrs     x8, CORTEX_HERCULES_CPUECTLR_EL1
+       ret
+endfunc cortex_hercules_cpu_reg_dump
+
+declare_cpu_ops cortex_hercules, CORTEX_HERCULES_MIDR, \
+       CPU_NO_RESET_FUNC, \
+       cortex_hercules_core_pwr_dwn
index 89d7ed682dc9a410ce15d5baaa147cebb190919b..05ba5ed6c31549ff4a33bcbaea8baa995eea1124 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <arch.h>
 #include <arch_helpers.h>
+#include <arch_features.h>
 #include <bl31/interrupt_mgmt.h>
 #include <common/bl_common.h>
 #include <context.h>
@@ -136,6 +137,18 @@ void cm_setup_context(cpu_context_t *ctx, const entry_point_info_t *ep)
                scr_el3 |= SCR_API_BIT | SCR_APK_BIT;
 #endif /* !CTX_INCLUDE_PAUTH_REGS */
 
+       unsigned int mte = get_armv8_5_mte_support();
+
+       /*
+        * Enable MTE support unilaterally for normal world if the CPU supports
+        * it.
+        */
+       if (mte != MTE_UNIMPLEMENTED) {
+               if (security_state == NON_SECURE) {
+                       scr_el3 |= SCR_ATA_BIT;
+               }
+       }
+
 #ifdef IMAGE_BL31
        /*
         * SCR_EL3.IRQ, SCR_EL3.FIQ: Enable the physical FIQ and IRQ routing as
index eca3be3fc7a496220764af3baecc79cbd0f87444..e31f9d8404cf11b5c9ee4e0b468e496c0bf94a50 100644 (file)
@@ -122,8 +122,8 @@ CASSERT(PLAT_PHY_ADDR_SPACE_SIZE == (1ULL << 32), invalid_paddr_space_size);
 #define DACR_DOMAIN_PERM_CLIENT                0x1
 #define DACR_DOMAIN_PERM_MANAGER       0x3
 
-#define NUM_1MB_IN_4GB         (1 << 12)
-#define NUM_4K_IN_1MB          (1 << 8)
+#define NUM_1MB_IN_4GB         (1U << 12)
+#define NUM_4K_IN_1MB          (1U << 8)
 
 #define ONE_MB_SHIFT           20
 
diff --git a/plat/arm/board/a5ds/a5ds_bl1_setup.c b/plat/arm/board/a5ds/a5ds_bl1_setup.c
new file mode 100644 (file)
index 0000000..629c928
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <plat/arm/common/plat_arm.h>
+
+/*******************************************************************************
+ * Perform any BL1 specific platform actions.
+ ******************************************************************************/
+void bl1_early_platform_setup(void)
+{
+       arm_bl1_early_platform_setup();
+}
+
+void bl1_platform_setup(void)
+{
+       arm_bl1_platform_setup();
+}
diff --git a/plat/arm/board/a5ds/a5ds_bl2_setup.c b/plat/arm/board/a5ds/a5ds_bl2_setup.c
new file mode 100644 (file)
index 0000000..1979c50
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+#include <plat/arm/common/plat_arm.h>
+#include <plat/common/platform.h>
+
+void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1,
+       u_register_t arg2, u_register_t arg3)
+{
+       arm_bl2_early_platform_setup((uintptr_t)arg0, (meminfo_t *)arg1);
+}
+
+void bl2_platform_setup(void)
+{
+       arm_bl2_platform_setup();
+}
diff --git a/plat/arm/board/a5ds/a5ds_common.c b/plat/arm/board/a5ds/a5ds_common.c
new file mode 100644 (file)
index 0000000..e462fa1
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <assert.h>
+
+#include <common/debug.h>
+#include <lib/mmio.h>
+#include <platform_def.h>
+#include <plat/arm/common/arm_config.h>
+#include <plat/arm/common/plat_arm.h>
+
+#define MAP_PERIPHBASE MAP_REGION_FLAT(PERIPHBASE,\
+                                       PERIPH_SIZE,\
+                                       MT_DEVICE | MT_RW | MT_SECURE)
+
+#define MAP_A5_PERIPHERALS     MAP_REGION_FLAT(A5_PERIPHERALS_BASE,\
+                                       A5_PERIPHERALS_SIZE,\
+                                       MT_DEVICE | MT_RW | MT_SECURE)
+
+#ifdef IMAGE_BL1
+const mmap_region_t plat_arm_mmap[] = {
+       ARM_MAP_SHARED_RAM,
+       MAP_FLASH1_RW,
+       MAP_PERIPHBASE,
+       MAP_A5_PERIPHERALS,
+       {0}
+};
+#endif
+#ifdef IMAGE_BL2
+const mmap_region_t plat_arm_mmap[] = {
+       ARM_MAP_SHARED_RAM,
+       MAP_FLASH1_RW,
+       MAP_PERIPHBASE,
+       MAP_A5_PERIPHERALS,
+       ARM_MAP_NS_DRAM1,
+       {0}
+};
+#endif
+#ifdef IMAGE_BL32
+const mmap_region_t plat_arm_mmap[] = {
+       ARM_MAP_SHARED_RAM,
+       MAP_PERIPHBASE,
+       MAP_A5_PERIPHERALS,
+       {0}
+};
+#endif
+
+ARM_CASSERT_MMAP
+
+unsigned int plat_get_syscnt_freq2(void)
+{
+       return A5DS_TIMER_BASE_FREQUENCY;
+}
diff --git a/plat/arm/board/a5ds/a5ds_err.c b/plat/arm/board/a5ds/a5ds_err.c
new file mode 100644 (file)
index 0000000..65b41dd
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <plat/arm/common/plat_arm.h>
+
+/*
+ * a5ds error handler
+ */
+void __dead2 plat_arm_error_handler(int err)
+{
+       while (1) {
+               wfi();
+       }
+}
diff --git a/plat/arm/board/a5ds/a5ds_pm.c b/plat/arm/board/a5ds/a5ds_pm.c
new file mode 100644 (file)
index 0000000..5fd443b
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <lib/psci/psci.h>
+#include <plat/arm/common/plat_arm.h>
+
+/*******************************************************************************
+ * Export the platform handlers via a5ds_psci_pm_ops. The ARM Standard
+ * platform layer will take care of registering the handlers with PSCI.
+ ******************************************************************************/
+plat_psci_ops_t a5ds_psci_pm_ops = {
+       /* dummy struct */
+       .validate_ns_entrypoint = NULL,
+};
+
+int __init plat_setup_psci_ops(uintptr_t sec_entrypoint,
+                               const plat_psci_ops_t **psci_ops)
+{
+       *psci_ops = &a5ds_psci_pm_ops;
+
+       return 0;
+}
diff --git a/plat/arm/board/a5ds/a5ds_private.h b/plat/arm/board/a5ds/a5ds_private.h
new file mode 100644 (file)
index 0000000..f577249
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef A5DS_PRIVATE_H
+#define A5DS_PRIVATE_H
+
+/*******************************************************************************
+ * Function and variable prototypes
+ ******************************************************************************/
+void a5ds_config_setup(void);
+
+#endif /* A5DS_PRIVATE_H */
diff --git a/plat/arm/board/a5ds/a5ds_security.c b/plat/arm/board/a5ds/a5ds_security.c
new file mode 100644 (file)
index 0000000..5593ae0
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <plat/arm/common/plat_arm.h>
+
+/*
+ * We assume that all security programming is done by the primary core.
+ */
+void plat_arm_security_setup(void)
+{
+       /*
+        * The platform currently does not have any security setup.
+        */
+}
diff --git a/plat/arm/board/a5ds/a5ds_topology.c b/plat/arm/board/a5ds/a5ds_topology.c
new file mode 100644 (file)
index 0000000..94fa71f
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <platform_def.h>
+
+/* The A5DS power domain tree descriptor */
+static const unsigned char a5ds_power_domain_tree_desc[] = {
+       1,
+       /* No of children for the root node */
+       A5DS_CLUSTER_COUNT,
+       /* No of children for the first cluster node */
+       A5DS_CORE_COUNT,
+};
+
+/*******************************************************************************
+ * This function returns the topology according to A5DS_CLUSTER_COUNT.
+ ******************************************************************************/
+const unsigned char *plat_get_power_domain_tree_desc(void)
+{
+       return a5ds_power_domain_tree_desc;
+}
+
+/*******************************************************************************
+ * Get core position using mpidr
+ ******************************************************************************/
+int plat_core_pos_by_mpidr(u_register_t mpidr)
+{
+       unsigned int cluster_id, cpu_id;
+
+       mpidr &= MPIDR_AFFINITY_MASK;
+
+       if (mpidr & ~(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK))
+               return -1;
+
+       cluster_id = (mpidr >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK;
+       cpu_id = (mpidr >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK;
+
+       if (cluster_id >= A5DS_CLUSTER_COUNT)
+               return -1;
+
+       /*
+        * Validate cpu_id by checking whether it represents a CPU in
+        * one of the two clusters present on the platform.
+        */
+       if (cpu_id >= A5DS_MAX_CPUS_PER_CLUSTER)
+               return -1;
+
+       return (cpu_id + (cluster_id * 4));
+
+}
diff --git a/plat/arm/board/a5ds/aarch32/a5ds_helpers.S b/plat/arm/board/a5ds/aarch32/a5ds_helpers.S
new file mode 100644 (file)
index 0000000..23a22d9
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <arch.h>
+#include <asm_macros.S>
+#include <platform_def.h>
+
+       .globl  plat_secondary_cold_boot_setup
+       .globl  plat_get_my_entrypoint
+       .globl  plat_is_my_cpu_primary
+
+       /* --------------------------------------------------------------------
+        * void plat_secondary_cold_boot_setup (void);
+        *
+        * For AArch32, cold-booting secondary CPUs is not yet
+        * implemented and they panic.
+        * --------------------------------------------------------------------
+        */
+func plat_secondary_cold_boot_setup
+cb_panic:
+       wfi
+       b       cb_panic
+endfunc plat_secondary_cold_boot_setup
+
+       /* ---------------------------------------------------------------------
+        * unsigned long plat_get_my_entrypoint (void);
+        *
+        * Main job of this routine is to distinguish between a cold and warm
+        * boot.
+        * ---------------------------------------------------------------------
+        */
+func plat_get_my_entrypoint
+       /* TODO support warm boot */
+       /* Cold reset */
+       mov     r0, #0
+       bx      lr
+
+endfunc plat_get_my_entrypoint
+
+       /* -----------------------------------------------------
+        * unsigned int plat_is_my_cpu_primary (void);
+        *
+        * Find out whether the current cpu is the primary
+        * cpu.
+        * -----------------------------------------------------
+        */
+func plat_is_my_cpu_primary
+       ldcopr  r0, MPIDR
+       ldr     r1, =MPIDR_AFFINITY_MASK
+       and     r0, r1
+       cmp     r0, #0
+       moveq   r0, #1
+       movne   r0, #0
+       bx      lr
+endfunc plat_is_my_cpu_primary
diff --git a/plat/arm/board/a5ds/fdts/a5ds_tb_fw_config.dts b/plat/arm/board/a5ds/fdts/a5ds_tb_fw_config.dts
new file mode 100644 (file)
index 0000000..9ab2d96
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/dts-v1/;
+
+/ {
+       /* Platform Config */
+       plat_arm_bl2 {
+               compatible = "arm,tb_fw";
+               hw_config_addr = <0x0 0x82000000>;
+               hw_config_max_size = <0x01000000>;
+               /* Disable authentication for development */
+               disable_auth = <0x0>;
+       };
+};
diff --git a/plat/arm/board/a5ds/include/platform_def.h b/plat/arm/board/a5ds/include/platform_def.h
new file mode 100644 (file)
index 0000000..db65c37
--- /dev/null
@@ -0,0 +1,350 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PLATFORM_DEF_H
+#define PLATFORM_DEF_H
+
+#include <common/tbbr/tbbr_img_def.h>
+#include <lib/utils_def.h>
+#include <lib/xlat_tables/xlat_tables_defs.h>
+#include <plat/arm/board/common/v2m_def.h>
+#include <plat/common/common_def.h>
+
+/* Memory location options for TSP */
+#define ARM_DRAM_ID                    2
+
+#define ARM_DRAM1_BASE                 UL(0x80000000)
+#define ARM_DRAM1_SIZE                 UL(0x80000000)
+#define ARM_DRAM1_END                  (ARM_DRAM1_BASE +               \
+                                        ARM_DRAM1_SIZE - 1)
+
+#define ARM_NS_DRAM1_BASE              ARM_DRAM1_BASE
+/*
+ * The last 2MB is meant to be NOLOAD and will not be zero
+ * initialized.
+ */
+#define ARM_NS_DRAM1_SIZE              (ARM_DRAM1_SIZE -               \
+                                        0x00200000)
+
+#define SRAM_BASE      0x2000000
+#define SRAM_SIZE      0x200000
+
+/* The first 4KB of NS DRAM1 are used as shared memory */
+#define A5DS_SHARED_RAM_BASE           SRAM_BASE
+#define A5DS_SHARED_RAM_SIZE           UL(0x00001000)  /* 4 KB */
+
+/* The next 252 kB of NS DRAM is used to load the BL images */
+#define ARM_BL_RAM_BASE        (A5DS_SHARED_RAM_BASE + \
+                                        A5DS_SHARED_RAM_SIZE)
+#define ARM_BL_RAM_SIZE        (PLAT_ARM_BL_PLUS_SHARED_RAM_SIZE -     \
+                                        A5DS_SHARED_RAM_SIZE)
+
+#define PERIPHBASE 0x1a000000
+#define PERIPH_SIZE  0x00240000
+#define A5_PERIPHERALS_BASE 0x1c000000
+#define A5_PERIPHERALS_SIZE  0x10000
+
+#define ARM_CACHE_WRITEBACK_SHIFT      6
+
+#define ARM_IRQ_SEC_PHY_TIMER          29
+
+#define ARM_IRQ_SEC_SGI_0              8
+#define ARM_IRQ_SEC_SGI_1              9
+#define ARM_IRQ_SEC_SGI_2              10
+#define ARM_IRQ_SEC_SGI_3              11
+#define ARM_IRQ_SEC_SGI_4              12
+#define ARM_IRQ_SEC_SGI_5              13
+#define ARM_IRQ_SEC_SGI_6              14
+#define ARM_IRQ_SEC_SGI_7              15
+
+/*
+ * Define a list of Group 1 Secure and Group 0 interrupt properties as per GICv3
+ * terminology. On a GICv2 system or mode, the lists will be merged and treated
+ * as Group 0 interrupts.
+ */
+#define ARM_G1S_IRQ_PROPS(grp) \
+       INTR_PROP_DESC(ARM_IRQ_SEC_PHY_TIMER, GIC_HIGHEST_SEC_PRIORITY, (grp), \
+                       GIC_INTR_CFG_LEVEL), \
+       INTR_PROP_DESC(ARM_IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY, (grp), \
+                       GIC_INTR_CFG_EDGE), \
+       INTR_PROP_DESC(ARM_IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY, (grp), \
+                       GIC_INTR_CFG_EDGE), \
+       INTR_PROP_DESC(ARM_IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY, (grp), \
+                       GIC_INTR_CFG_EDGE), \
+       INTR_PROP_DESC(ARM_IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY, (grp), \
+                       GIC_INTR_CFG_EDGE), \
+       INTR_PROP_DESC(ARM_IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY, (grp), \
+                       GIC_INTR_CFG_EDGE), \
+       INTR_PROP_DESC(ARM_IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY, (grp), \
+                       GIC_INTR_CFG_EDGE)
+
+#define ARM_G0_IRQ_PROPS(grp) \
+       INTR_PROP_DESC(ARM_IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY, (grp), \
+                       GIC_INTR_CFG_EDGE)
+
+#define A5DS_IRQ_TZ_WDOG                       56
+#define A5DS_IRQ_SEC_SYS_TIMER         57
+
+/* Default cluster count for A5DS */
+#define A5DS_CLUSTER_COUNT     1
+
+/* Default number of CPUs per cluster on A5DS */
+#define A5DS_MAX_CPUS_PER_CLUSTER      4
+
+/* Default number of threads per CPU on A5DS */
+#define A5DS_MAX_PE_PER_CPU    1
+
+#define A5DS_CORE_COUNT 1
+
+#define A5DS_PRIMARY_CPU                       0x0
+
+#define FLASH1_BASE                    UL(0x8000000)
+#define FLASH1_SIZE                    UL(0x2800000)
+
+#define MAP_FLASH1_RW          MAP_REGION_FLAT(FLASH1_BASE,\
+                                               FLASH1_SIZE,    \
+                                               MT_DEVICE | MT_RW | MT_SECURE)
+
+#define MAP_FLASH1_RO          MAP_REGION_FLAT(FLASH1_BASE,\
+                                               FLASH1_SIZE,    \
+                                               MT_RO_DATA | MT_SECURE)
+
+#define ARM_MAP_SHARED_RAM             MAP_REGION_FLAT(                \
+                                               A5DS_SHARED_RAM_BASE,   \
+                                               A5DS_SHARED_RAM_SIZE,   \
+                                               MT_MEMORY | MT_RW | MT_SECURE)
+
+#define ARM_MAP_NS_DRAM1               MAP_REGION_FLAT(                \
+                                               ARM_NS_DRAM1_BASE,      \
+                                               ARM_NS_DRAM1_SIZE,      \
+                                               MT_MEMORY | MT_RW | MT_NS)
+
+#define ARM_MAP_SRAM           MAP_REGION_FLAT(                \
+                                               SRAM_BASE,      \
+                                               SRAM_SIZE,      \
+                                               MT_MEMORY | MT_RW | MT_NS)
+
+/*
+ * Mapping for the BL1 RW region. This mapping is needed by BL2 in order to
+ * share the Mbed TLS heap. Since the heap is allocated inside BL1, it resides
+ * in the BL1 RW region. Hence, BL2 needs access to the BL1 RW region in order
+ * to be able to access the heap.
+ */
+
+#define ARM_MAP_BL_RO  MAP_REGION_FLAT(\
+                                               BL_CODE_BASE,\
+                                               BL_CODE_END - BL_CODE_BASE,\
+                                               MT_CODE | MT_SECURE),\
+                                       MAP_REGION_FLAT(\
+                                               BL_RO_DATA_BASE,\
+                                               BL_RO_DATA_END\
+                                               - BL_RO_DATA_BASE,      \
+                                               MT_RO_DATA | MT_SECURE)
+
+#if USE_COHERENT_MEM
+#define ARM_MAP_BL_COHERENT_RAM                MAP_REGION_FLAT(\
+                                               BL_COHERENT_RAM_BASE,\
+                                               BL_COHERENT_RAM_END     \
+                                               - BL_COHERENT_RAM_BASE, \
+                                               MT_DEVICE | MT_RW | MT_SECURE)
+#endif
+
+/*
+ * The max number of regions like RO(code), coherent and data required by
+ * different BL stages which need to be mapped in the MMU.
+ */
+#define ARM_BL_REGIONS                 5
+
+#define MAX_MMAP_REGIONS               (PLAT_ARM_MMAP_ENTRIES +        \
+                                        ARM_BL_REGIONS)
+
+/* Memory mapped Generic timer interfaces  */
+#define A5DS_TIMER_BASE_FREQUENCY              UL(24000000)
+
+#define ARM_CONSOLE_BAUDRATE           115200
+
+#define PLAT_PHY_ADDR_SPACE_SIZE                       (1ULL << 32)
+#define PLAT_VIRT_ADDR_SPACE_SIZE                      (1ULL << 32)
+
+/*
+ * This macro defines the deepest retention state possible. A higher state
+ * id will represent an invalid or a power down state.
+ */
+#define PLAT_MAX_RET_STATE             1
+
+/*
+ * This macro defines the deepest power down states possible. Any state ID
+ * higher than this is invalid.
+ */
+#define PLAT_MAX_OFF_STATE             2
+
+/*
+ * Some data must be aligned on the biggest cache line size in the platform.
+ * This is known only to the platform as it might have a combination of
+ * integrated and external caches.
+ */
+#define CACHE_WRITEBACK_GRANULE                (U(1) << ARM_CACHE_WRITEBACK_SHIFT)
+
+/*
+ * To enable TB_FW_CONFIG to be loaded by BL1, define the corresponding base
+ * and limit. Leave enough space of BL2 meminfo.
+ */
+#define ARM_TB_FW_CONFIG_BASE          (ARM_BL_RAM_BASE + sizeof(meminfo_t))
+#define ARM_TB_FW_CONFIG_LIMIT         (ARM_BL_RAM_BASE + PAGE_SIZE)
+
+/*******************************************************************************
+ * BL1 specific defines.
+ * BL1 RW data is relocated from ROM to RAM at runtime so we need 2 sets of
+ * addresses.
+ ******************************************************************************/
+#define BL1_RO_BASE                    0x00000000
+#define BL1_RO_LIMIT                   PLAT_ARM_TRUSTED_ROM_SIZE
+/*
+ * Put BL1 RW at the top of the memory allocated for BL images in NS DRAM.
+ */
+#define BL1_RW_BASE    (ARM_BL_RAM_BASE + \
+                                               ARM_BL_RAM_SIZE - \
+                                               (PLAT_ARM_MAX_BL1_RW_SIZE))
+#define BL1_RW_LIMIT (ARM_BL_RAM_BASE + \
+                                           (ARM_BL_RAM_SIZE))
+/*******************************************************************************
+ * BL2 specific defines.
+ ******************************************************************************/
+
+/*
+ * Put BL2 just below BL1.
+ */
+#define BL2_BASE                       (BL1_RW_BASE - A5DS_MAX_BL2_SIZE)
+#define BL2_LIMIT                      BL1_RW_BASE
+
+/* Put BL32 below BL2 in NS DRAM.*/
+#define ARM_BL2_MEM_DESC_BASE          ARM_TB_FW_CONFIG_LIMIT
+
+#define BL32_BASE                      ((ARM_BL_RAM_BASE + ARM_BL_RAM_SIZE)\
+                                               - PLAT_ARM_MAX_BL32_SIZE)
+#define BL32_PROGBITS_LIMIT            BL2_BASE
+#define BL32_LIMIT                     (ARM_BL_RAM_BASE + ARM_BL_RAM_SIZE)
+
+/* Required platform porting definitions */
+#define PLATFORM_CORE_COUNT 1
+#define PLAT_NUM_PWR_DOMAINS           (A5DS_CLUSTER_COUNT + \
+                                       PLATFORM_CORE_COUNT) + 1
+
+#define PLAT_MAX_PWR_LVL               2
+
+/*
+ * Other platform porting definitions are provided by included headers
+ */
+
+/*
+ * Required ARM standard platform porting definitions
+ */
+
+#define PLAT_ARM_BL_PLUS_SHARED_RAM_SIZE       0x00040000      /* 256 KB */
+
+#define PLAT_ARM_TRUSTED_ROM_BASE      0x00000000
+#define PLAT_ARM_TRUSTED_ROM_SIZE      0x10000 /* 64KB */
+
+#define PLAT_ARM_DRAM2_SIZE            ULL(0x80000000)
+
+/*
+ * Load address of BL33 for this platform port
+ */
+#define PLAT_ARM_NS_IMAGE_BASE (ARM_DRAM1_BASE + U(0x8000000))
+
+/*
+ * PLAT_ARM_MMAP_ENTRIES depends on the number of entries in the
+ * plat_arm_mmap array defined for each BL stage.
+ */
+#if defined(IMAGE_BL32)
+# define PLAT_ARM_MMAP_ENTRIES         8
+# define MAX_XLAT_TABLES               6
+#else
+# define PLAT_ARM_MMAP_ENTRIES         12
+# define MAX_XLAT_TABLES               6
+#endif
+
+/*
+ * PLAT_ARM_MAX_BL1_RW_SIZE is calculated using the current BL1 RW debug size
+ * plus a little space for growth.
+ */
+#define PLAT_ARM_MAX_BL1_RW_SIZE       0xB000
+
+/*
+ * A5DS_MAX_BL2_SIZE is calculated using the current BL2 debug size plus a
+ * little space for growth.
+ */
+#define A5DS_MAX_BL2_SIZE              0x11000
+
+/*
+ * Since BL32 NOBITS overlays BL2 and BL1-RW, PLAT_ARM_MAX_BL32_SIZE is
+ * calculated using the current SP_MIN PROGBITS debug size plus the sizes of
+ * BL2 and BL1-RW
+ */
+#define PLAT_ARM_MAX_BL32_SIZE         0x3B000
+/*
+ * Size of cacheable stacks
+ */
+#if defined(IMAGE_BL1)
+#  define PLATFORM_STACK_SIZE 0x440
+#elif defined(IMAGE_BL2)
+#  define PLATFORM_STACK_SIZE 0x400
+#elif defined(IMAGE_BL32)
+# define PLATFORM_STACK_SIZE 0x440
+#endif
+
+#define MAX_IO_DEVICES                 3
+#define MAX_IO_HANDLES                 4
+
+/* Reserve the last block of flash for PSCI MEM PROTECT flag */
+#define PLAT_ARM_FIP_BASE              FLASH1_BASE
+#define PLAT_ARM_FIP_MAX_SIZE          (FLASH1_SIZE - V2M_FLASH_BLOCK_SIZE)
+
+#define PLAT_ARM_NVM_BASE              FLASH1_BASE
+#define PLAT_ARM_NVM_SIZE              (FLASH1_SIZE - V2M_FLASH_BLOCK_SIZE)
+
+/*
+ * PL011 related constants
+ */
+#define PLAT_ARM_BOOT_UART_BASE                0x1A200000
+#define PLAT_ARM_BOOT_UART_CLK_IN_HZ   24000000
+
+#define PLAT_ARM_RUN_UART_BASE         0x1A210000
+#define PLAT_ARM_RUN_UART_CLK_IN_HZ    24000000
+
+#define PLAT_ARM_CRASH_UART_BASE       PLAT_ARM_RUN_UART_BASE
+#define PLAT_ARM_CRASH_UART_CLK_IN_HZ  PLAT_ARM_RUN_UART_CLK_IN_HZ
+
+#define A5DS_TIMER_BASE_FREQUENCY      UL(24000000)
+
+/* System timer related constants */
+#define PLAT_ARM_NSTIMER_FRAME_ID              1
+
+/* Mailbox base address */
+#define A5DS_TRUSTED_MAILBOX_BASE      A5DS_SHARED_RAM_BASE
+
+/*
+ * GIC related constants to cater for GICv2
+ */
+#define PLAT_ARM_GICD_BASE             0x1C001000
+#define PLAT_ARM_GICC_BASE             0x1C000100
+
+/*
+ * Define a list of Group 1 Secure and Group 0 interrupts as per GICv3
+ * terminology. On a GICv2 system or mode, the lists will be merged and treated
+ * as Group 0 interrupts.
+ */
+#define PLAT_ARM_G1S_IRQ_PROPS(grp) \
+       ARM_G1S_IRQ_PROPS(grp), \
+       INTR_PROP_DESC(A5DS_IRQ_TZ_WDOG, GIC_HIGHEST_SEC_PRIORITY, (grp), \
+                       GIC_INTR_CFG_LEVEL), \
+       INTR_PROP_DESC(A5DS_IRQ_SEC_SYS_TIMER,\
+                GIC_HIGHEST_SEC_PRIORITY, (grp), \
+                       GIC_INTR_CFG_LEVEL)
+
+#define PLAT_ARM_G0_IRQ_PROPS(grp)     ARM_G0_IRQ_PROPS(grp)
+
+#endif /* PLATFORM_DEF_H */
diff --git a/plat/arm/board/a5ds/platform.mk b/plat/arm/board/a5ds/platform.mk
new file mode 100644 (file)
index 0000000..d42b2bf
--- /dev/null
@@ -0,0 +1,96 @@
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# Add `libfdt` and Arm common helpers required for Dynamic Config
+include lib/libfdt/libfdt.mk
+
+DYN_CFG_SOURCES                +=      plat/arm/common/arm_dyn_cfg.c           \
+                               plat/arm/common/arm_dyn_cfg_helpers.c   \
+                               common/fdt_wrappers.c
+
+A5DS_GIC_SOURCES       :=      drivers/arm/gic/common/gic_common.c     \
+                               drivers/arm/gic/v2/gicv2_main.c         \
+                               drivers/arm/gic/v2/gicv2_helpers.c      \
+                               plat/common/plat_gicv2.c                \
+                               plat/arm/common/arm_gicv2.c
+
+A5DS_SECURITY_SOURCES  :=      plat/arm/board/a5ds/a5ds_security.c
+
+PLAT_INCLUDES          :=      -Iplat/arm/board/a5ds/include
+
+PLAT_BL_COMMON_SOURCES :=      drivers/arm/pl011/${ARCH}/pl011_console.S       \
+                               plat/arm/board/a5ds/a5ds_common.c               \
+                               plat/arm/common/${ARCH}/arm_helpers.S           \
+                               plat/arm/common/arm_common.c                    \
+                               plat/arm/common/arm_console.c                   \
+                               plat/arm/board/common/${ARCH}/board_arm_helpers.S
+
+A5DS_CPU_LIBS          :=      lib/cpus/aarch32/cortex_a5.S
+
+BL1_SOURCES            +=      drivers/io/io_fip.c                             \
+                               drivers/io/io_memmap.c                          \
+                               drivers/io/io_storage.c                         \
+                               drivers/cfi/v2m/v2m_flash.c                     \
+                               plat/arm/common/arm_bl1_setup.c                 \
+                               plat/arm/common/arm_err.c                       \
+                               plat/arm/board/a5ds/a5ds_err.c                  \
+                               plat/arm/common/arm_io_storage.c                \
+                               plat/arm/board/a5ds/${ARCH}/a5ds_helpers.S      \
+                               plat/arm/board/a5ds/a5ds_bl1_setup.c            \
+                               lib/aarch32/arm32_aeabi_divmod.c                \
+                               lib/aarch32/arm32_aeabi_divmod_a32.S            \
+                               ${A5DS_CPU_LIBS}                                \
+                               ${DYN_CFG_SOURCES}
+
+BL2_SOURCES            +=      lib/aarch32/arm32_aeabi_divmod.c                \
+                               lib/aarch32/arm32_aeabi_divmod_a32.S            \
+                               drivers/delay_timer/delay_timer.c               \
+                               drivers/delay_timer/generic_delay_timer.c       \
+                               drivers/cfi/v2m/v2m_flash.c                     \
+                               drivers/io/io_fip.c                             \
+                               drivers/io/io_memmap.c                          \
+                               drivers/io/io_storage.c                         \
+                               plat/arm/board/a5ds/a5ds_bl2_setup.c            \
+                               plat/arm/common/arm_bl2_setup.c                 \
+                               plat/arm/common/arm_err.c                       \
+                               plat/arm/board/a5ds/a5ds_err.c                  \
+                               plat/arm/common/arm_io_storage.c                \
+                               plat/arm/common/${ARCH}/arm_bl2_mem_params_desc.c       \
+                               plat/arm/common/arm_image_load.c                \
+                               common/desc_image_load.c                        \
+                               ${DYN_CFG_SOURCES}                              \
+                               ${A5DS_SECURITY_SOURCES}
+
+# Add the FDT_SOURCES and options for Dynamic Config (only for Unix env)
+ifdef UNIX_MK
+
+FVP_TB_FW_CONFIG       :=      ${BUILD_PLAT}/fdts/a5ds_tb_fw_config.dtb
+
+# Add the TB_FW_CONFIG to FIP and specify the same to certtool
+$(eval $(call TOOL_ADD_PAYLOAD,${FVP_TB_FW_CONFIG},--tb-fw-config))
+
+$(eval FVP_HW_CONFIG   :=      ${BUILD_PLAT}/$(patsubst %.dts,%.dtb, \
+       fdts/$(notdir ${FVP_HW_CONFIG_DTS})))
+# Add the HW_CONFIG to FIP and specify the same to certtool
+$(eval $(call TOOL_ADD_PAYLOAD,${FVP_HW_CONFIG},--hw-config))
+
+FDT_SOURCES            +=      plat/arm/board/a5ds/fdts/a5ds_tb_fw_config.dts \
+                                       ${FVP_HW_CONFIG_DTS}
+endif
+
+NEED_BL32 := yes
+
+MULTI_CONSOLE_API              :=      1
+
+PLAT_BL_COMMON_SOURCES +=      lib/xlat_tables/aarch32/nonlpae_tables.c
+
+# Use translation tables library v1 when using Cortex-A5
+ARM_XLAT_TABLES_LIB_V1         :=      1
+$(eval $(call assert_boolean,ARM_XLAT_TABLES_LIB_V1))
+$(eval $(call add_define,ARM_XLAT_TABLES_LIB_V1))
+
+$(eval $(call assert_boolean,ARM_DISABLE_TRUSTED_WDOG))
+$(eval $(call add_define,ARM_DISABLE_TRUSTED_WDOG))
diff --git a/plat/arm/board/a5ds/sp_min/a5ds_sp_min_setup.c b/plat/arm/board/a5ds/sp_min/a5ds_sp_min_setup.c
new file mode 100644 (file)
index 0000000..8b45af8
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2019, ARM Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <plat/arm/common/plat_arm.h>
+
+void plat_arm_sp_min_early_platform_setup(u_register_t arg0, u_register_t arg1,
+                       u_register_t arg2, u_register_t arg3)
+{
+       arm_sp_min_early_platform_setup((void *)arg0, arg1, arg2, (void *)arg3);
+}
+
+/*
+ * A5DS will only have one always-on power domain and there
+ * is no power control present.
+ */
+void plat_arm_pwrc_setup(void)
+{
+}
+
diff --git a/plat/arm/board/a5ds/sp_min/sp_min-a5ds.mk b/plat/arm/board/a5ds/sp_min/sp_min-a5ds.mk
new file mode 100644 (file)
index 0000000..da1d785
--- /dev/null
@@ -0,0 +1,21 @@
+#
+# Copyright (c) 2019, ARM Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+# SP_MIN source files specific to A5DS platform
+BL32_SOURCES   +=      drivers/cfi/v2m/v2m_flash.c                     \
+                       lib/utils/mem_region.c                          \
+                       lib/aarch32/arm32_aeabi_divmod.c                \
+                       lib/aarch32/arm32_aeabi_divmod_a32.S            \
+                       plat/arm/board/a5ds/aarch32/a5ds_helpers.S      \
+                       plat/arm/board/a5ds/a5ds_pm.c                   \
+                       plat/arm/board/a5ds/a5ds_topology.c             \
+                       plat/arm/board/a5ds/sp_min/a5ds_sp_min_setup.c  \
+                       plat/arm/common/sp_min/arm_sp_min_setup.c       \
+                       plat/common/aarch32/platform_mp_stack.S         \
+                       plat/common/plat_psci_common.c                  \
+                       ${A5DS_CPU_LIBS}                                \
+                       ${A5DS_GIC_SOURCES}                             \
+                       ${A5DS_SECURITY_SOURCES}
index 420df45595b0af6c4cab1f07cc6f303ecba60fe9..b90ddcd330fd6a9cc77fd3307332f265f7ab7615 100644 (file)
@@ -52,3 +52,12 @@ void bl1_platform_setup(void)
        if ((arm_config.flags & ARM_CONFIG_FVP_HAS_SMMUV3) != 0U)
                smmuv3_security_init(PLAT_FVP_SMMUV3_BASE);
 }
+
+__dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved)
+{
+       /* Setup the watchdog to reset the system as soon as possible */
+       sp805_refresh(ARM_SP805_TWDG_BASE, 1U);
+
+       while (1)
+               wfi();
+}
diff --git a/plat/arm/board/fvp/fvp_err.c b/plat/arm/board/fvp/fvp_err.c
new file mode 100644 (file)
index 0000000..2437cd4
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <errno.h>
+
+#include <common/debug.h>
+#include <drivers/arm/sp805.h>
+#include <drivers/cfi/v2m_flash.h>
+#include <plat/arm/common/plat_arm.h>
+#include <plat/common/platform.h>
+#include <platform_def.h>
+
+/*
+ * FVP error handler
+ */
+__dead2 void plat_arm_error_handler(int err)
+{
+       int ret;
+
+       switch (err) {
+       case -ENOENT:
+       case -EAUTH:
+               /* Image load or authentication error. Erase the ToC */
+               INFO("Erasing FIP ToC from flash...\n");
+               (void)nor_unlock(PLAT_ARM_FIP_BASE);
+               ret = nor_word_program(PLAT_ARM_FIP_BASE, 0);
+               if (ret != 0) {
+                       ERROR("Cannot erase ToC\n");
+               } else {
+                       INFO("Done\n");
+               }
+               break;
+       default:
+               /* Unexpected error */
+               break;
+       }
+
+       (void)console_flush();
+
+       /* Setup the watchdog to reset the system as soon as possible */
+       sp805_refresh(ARM_SP805_TWDG_BASE, 1U);
+
+       for (;;)
+               wfi();
+}
index 3cbdfbc4643b384bbc41dd4e661b8de27ac9e0cd..0eb62c44ae1b1983969961ad645c237d15add86d 100644 (file)
@@ -109,10 +109,11 @@ else
        ifeq (${CTX_INCLUDE_AARCH32_REGS}, 0)
                FVP_CPU_LIBS    +=      lib/cpus/aarch64/cortex_a76.S           \
                                        lib/cpus/aarch64/cortex_a76ae.S         \
+                                       lib/cpus/aarch64/cortex_a77.S           \
                                        lib/cpus/aarch64/neoverse_n1.S          \
                                        lib/cpus/aarch64/neoverse_e1.S          \
-                                       lib/cpus/aarch64/cortex_deimos.S        \
-                                       lib/cpus/aarch64/neoverse_zeus.S
+                                       lib/cpus/aarch64/neoverse_zeus.S        \
+                                       lib/cpus/aarch64/cortex_hercules.S
        # AArch64/AArch32
        else
                FVP_CPU_LIBS    +=      lib/cpus/aarch64/cortex_a55.S           \
@@ -131,17 +132,20 @@ BL1_SOURCES               +=      drivers/arm/smmu/smmu_v3.c                      \
                                lib/semihosting/${ARCH}/semihosting_call.S      \
                                plat/arm/board/fvp/${ARCH}/fvp_helpers.S        \
                                plat/arm/board/fvp/fvp_bl1_setup.c              \
+                               plat/arm/board/fvp/fvp_err.c                    \
                                plat/arm/board/fvp/fvp_io_storage.c             \
                                plat/arm/board/fvp/fvp_trusted_boot.c           \
                                ${FVP_CPU_LIBS}                                 \
                                ${FVP_INTERCONNECT_SOURCES}
 
 
-BL2_SOURCES            +=      drivers/io/io_semihosting.c                     \
+BL2_SOURCES            +=      drivers/arm/sp805/sp805.c                       \
+                               drivers/io/io_semihosting.c                     \
                                lib/utils/mem_region.c                          \
                                lib/semihosting/semihosting.c                   \
                                lib/semihosting/${ARCH}/semihosting_call.S      \
                                plat/arm/board/fvp/fvp_bl2_setup.c              \
+                               plat/arm/board/fvp/fvp_err.c                    \
                                plat/arm/board/fvp/fvp_io_storage.c             \
                                plat/arm/board/fvp/fvp_trusted_boot.c           \
                                plat/arm/common/arm_nor_psci_mem_protect.c      \
diff --git a/plat/arm/board/fvp_ve/fvp_ve_err.c b/plat/arm/board/fvp_ve/fvp_ve_err.c
new file mode 100644 (file)
index 0000000..7f9d2f7
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <plat/arm/common/plat_arm.h>
+
+/*
+ * FVP VE error handler
+ */
+void __dead2 plat_arm_error_handler(int err)
+{
+       while (1) {
+               wfi();
+       }
+}
index f85452dac915a0290c980dae5b9498bb52d7278d..4d21f4ba0912ca42709846e504b3a35d3ce7581b 100644 (file)
@@ -40,6 +40,7 @@ BL1_SOURCES           +=      drivers/arm/sp805/sp805.c                       \
                                drivers/io/io_storage.c                         \
                                plat/arm/common/arm_bl1_setup.c                 \
                                plat/arm/common/arm_err.c                       \
+                               plat/arm/board/fvp_ve/fvp_ve_err.c              \
                                plat/arm/common/arm_io_storage.c                \
                                drivers/cfi/v2m/v2m_flash.c                     \
                                plat/arm/board/fvp_ve/${ARCH}/fvp_ve_helpers.S  \
@@ -60,6 +61,7 @@ BL2_SOURCES           +=      plat/arm/board/fvp_ve/fvp_ve_bl2_setup.c                \
                                drivers/io/io_storage.c                         \
                                plat/arm/common/arm_bl2_setup.c                 \
                                plat/arm/common/arm_err.c                       \
+                               plat/arm/board/fvp_ve/fvp_ve_err.c              \
                                plat/arm/common/arm_io_storage.c                \
                                plat/arm/common/${ARCH}/arm_bl2_mem_params_desc.c       \
                                plat/arm/common/arm_image_load.c                \
index 7a3d22dedc827b67bf0bbd484bf27c8b4f6b2ce4..89398d686d02e99722000b900ed88f785b71f844 100644 (file)
@@ -98,6 +98,9 @@ __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved)
        /* Clear the NV flags register. */
        *nv_flags_clr = *nv_flags_ptr;
 
+       /* Setup the watchdog to reset the system as soon as possible */
+       sp805_refresh(ARM_SP805_TWDG_BASE, 1U);
+
        while (1)
                wfi();
 }
index 700b96cb1aa9fe3bc533061554f231df9a053b77..961bfda17a830f55ed902495b0573b1f98bdc1d1 100644 (file)
@@ -7,6 +7,7 @@
 #include <errno.h>
 
 #include <arch_helpers.h>
+#include <drivers/arm/sp805.h>
 #include <plat/arm/common/plat_arm.h>
 #include <plat/common/platform.h>
 #include <platform_def.h>
@@ -21,7 +22,9 @@ void __dead2 plat_arm_error_handler(int err)
        /* Propagate the err code in the NV-flags register */
        *flags_ptr = err;
 
-       /* Loop until the watchdog resets the system */
+       /* Setup the watchdog to reset the system as soon as possible */
+       sp805_refresh(ARM_SP805_TWDG_BASE, 1U);
+
        for (;;)
                wfi();
 }
index 40e62644b078548ffb83ffe621fdcac50f6ab22c..ea7f8517219f70ee010d0798f8ad50ec7df7449a 100644 (file)
@@ -66,7 +66,8 @@ BL1_SOURCES           +=      lib/cpus/aarch64/cortex_a53.S           \
                                ${JUNO_INTERCONNECT_SOURCES}            \
                                ${JUNO_SECURITY_SOURCES}
 
-BL2_SOURCES            +=      lib/utils/mem_region.c                  \
+BL2_SOURCES            +=      drivers/arm/sp805/sp805.c               \
+                               lib/utils/mem_region.c                  \
                                plat/arm/board/juno/juno_err.c          \
                                plat/arm/board/juno/juno_bl2_setup.c    \
                                plat/arm/common/arm_nor_psci_mem_protect.c \
index a831b89f2ca91af1f2fc7d5f77204ae3c3b6378e..632af7b409f223d529d7094af89b41adbb9e8d78 100644 (file)
@@ -80,8 +80,17 @@ void dmc_ecc_setup(uint32_t ddr_size_gb)
        flush_dcache_range(ARM_DRAM2_BASE, dram2_size);
 
        INFO("Enabling ECC on DMCs\n");
+       /* Set DMCs to CONFIG state before writing ERR0CTLR0 register */
+       mmio_write_32(N1SDP_DMC0_MEMC_CMD_REG, N1SDP_DMC_MEMC_CMD_CONFIG);
+       mmio_write_32(N1SDP_DMC1_MEMC_CMD_REG, N1SDP_DMC_MEMC_CMD_CONFIG);
+
+       /* Enable ECC in DMCs */
        mmio_setbits_32(N1SDP_DMC0_ERR0CTLR0_REG, N1SDP_DMC_ERR0CTLR0_ECC_EN);
        mmio_setbits_32(N1SDP_DMC1_ERR0CTLR0_REG, N1SDP_DMC_ERR0CTLR0_ECC_EN);
+
+       /* Set DMCs to READY state */
+       mmio_write_32(N1SDP_DMC0_MEMC_CMD_REG, N1SDP_DMC_MEMC_CMD_READY);
+       mmio_write_32(N1SDP_DMC1_MEMC_CMD_REG, N1SDP_DMC_MEMC_CMD_READY);
 }
 
 void copy_bl33(uint32_t src, uint32_t dst, uint32_t size)
index b7f7213d626d0b5a8e2ac2bc1bb8d797ff4eb84b..d43c5a47b96d887bda2a1f10530405672b1af3b2 100644 (file)
 #define N1SDP_SDS_BL33_INFO_OFFSET             0
 #define N1SDP_SDS_BL33_INFO_SIZE               12
 
+/* DMC memory command registers */
+#define N1SDP_DMC0_MEMC_CMD_REG                        0x4E000008
+#define N1SDP_DMC1_MEMC_CMD_REG                        0x4E100008
+
 /* DMC ERR0CTLR0 registers */
 #define N1SDP_DMC0_ERR0CTLR0_REG               0x4E000708
 #define N1SDP_DMC1_ERR0CTLR0_REG               0x4E100708
 
+/* DMC memory commands */
+#define N1SDP_DMC_MEMC_CMD_CONFIG              0
+#define N1SDP_DMC_MEMC_CMD_READY               3
+
 /* DMC ECC enable bit in ERR0CTLR0 register */
 #define N1SDP_DMC_ERR0CTLR0_ECC_EN             0x1
 
index 833bb821af414692edfa3d0c771e80bbe8abbbda..db41e0eda6802ed40a49dcf097c9427048a2d4da 100644 (file)
@@ -12,10 +12,12 @@ PLAT_INCLUDES               +=      -I${RDE1EDGE_BASE}/include/
 
 SGI_CPU_SOURCES                :=      lib/cpus/aarch64/neoverse_e1.S
 
-BL1_SOURCES            +=      ${SGI_CPU_SOURCES}
+BL1_SOURCES            +=      ${SGI_CPU_SOURCES}                      \
+                               ${RDE1EDGE_BASE}/rde1edge_err.c
 
 BL2_SOURCES            +=      ${RDE1EDGE_BASE}/rde1edge_plat.c        \
                                ${RDE1EDGE_BASE}/rde1edge_security.c    \
+                               ${RDE1EDGE_BASE}/rde1edge_err.c         \
                                drivers/arm/tzc/tzc_dmc620.c            \
                                lib/utils/mem_region.c                  \
                                plat/arm/common/arm_nor_psci_mem_protect.c
diff --git a/plat/arm/board/rde1edge/rde1edge_err.c b/plat/arm/board/rde1edge/rde1edge_err.c
new file mode 100644 (file)
index 0000000..e344d82
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <plat/arm/common/plat_arm.h>
+
+/*
+ * rde1edge error handler
+ */
+void __dead2 plat_arm_error_handler(int err)
+{
+       while (1) {
+               wfi();
+       }
+}
index cacdaa13c26a04509a80f6aef9d50dd056fa95e2..b44c70a3b4339480871067cbf9277be6ef16b436 100644 (file)
@@ -12,10 +12,12 @@ PLAT_INCLUDES               +=      -I${RDN1EDGE_BASE}/include/
 
 SGI_CPU_SOURCES                :=      lib/cpus/aarch64/neoverse_n1.S
 
-BL1_SOURCES            +=      ${SGI_CPU_SOURCES}
+BL1_SOURCES            +=      ${SGI_CPU_SOURCES}                      \
+                               ${RDN1EDGE_BASE}/rdn1edge_err.c
 
 BL2_SOURCES            +=      ${RDN1EDGE_BASE}/rdn1edge_plat.c        \
                                ${RDN1EDGE_BASE}/rdn1edge_security.c    \
+                               ${RDN1EDGE_BASE}/rdn1edge_err.c         \
                                drivers/arm/tzc/tzc_dmc620.c            \
                                lib/utils/mem_region.c                  \
                                plat/arm/common/arm_nor_psci_mem_protect.c
diff --git a/plat/arm/board/rdn1edge/rdn1edge_err.c b/plat/arm/board/rdn1edge/rdn1edge_err.c
new file mode 100644 (file)
index 0000000..cdcbf25
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <plat/arm/common/plat_arm.h>
+
+/*
+ * rdn1edge error handler
+ */
+void __dead2 plat_arm_error_handler(int err)
+{
+       while (1) {
+               wfi();
+       }
+}
index e72225d370d3739c46260ba0a6c62e2df6a149c6..b9fa0995d26c920c57882005468764b04bb2fec4 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
+# Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -12,10 +12,12 @@ PLAT_INCLUDES               +=      -I${SGI575_BASE}/include/
 
 SGI_CPU_SOURCES                :=      lib/cpus/aarch64/cortex_a75.S
 
-BL1_SOURCES            +=      ${SGI_CPU_SOURCES}
+BL1_SOURCES            +=      ${SGI_CPU_SOURCES}                      \
+                               ${SGI575_BASE}/sgi575_err.c
 
 BL2_SOURCES            +=      ${SGI575_BASE}/sgi575_plat.c            \
                                ${SGI575_BASE}/sgi575_security.c        \
+                               ${SGI575_BASE}/sgi575_err.c             \
                                drivers/arm/tzc/tzc_dmc620.c            \
                                lib/utils/mem_region.c                  \
                                plat/arm/common/arm_nor_psci_mem_protect.c
diff --git a/plat/arm/board/sgi575/sgi575_err.c b/plat/arm/board/sgi575/sgi575_err.c
new file mode 100644 (file)
index 0000000..c1cc1a7
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <plat/arm/common/plat_arm.h>
+
+/*
+ * sgi575 error handler
+ */
+void __dead2 plat_arm_error_handler(int err)
+{
+       while (1) {
+               wfi();
+       }
+}
index c8337554ac3a2bc1f6657b07b873e802a300a9ea..7a843c369caf6483277ec75b0a942ee49a9f58ec 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
+# Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -12,7 +12,10 @@ FDT_SOURCES += ${SGM775_BASE}/fdts/sgm775_tb_fw_config.dts
 
 PLAT_INCLUDES +=-I${SGM775_BASE}/include/
 
+BL1_SOURCES            +=      ${SGM775_BASE}/sgm775_err.c
+
 BL2_SOURCES            +=      lib/utils/mem_region.c                  \
+                               ${SGM775_BASE}/sgm775_err.c             \
                                plat/arm/common/arm_nor_psci_mem_protect.c
 
 BL31_SOURCES           +=      drivers/cfi/v2m/v2m_flash.c             \
diff --git a/plat/arm/board/sgm775/sgm775_err.c b/plat/arm/board/sgm775/sgm775_err.c
new file mode 100644 (file)
index 0000000..e1e0586
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <plat/arm/common/plat_arm.h>
+
+/*
+ * sgm775 error handler
+ */
+void __dead2 plat_arm_error_handler(int err)
+{
+       while (1) {
+               wfi();
+       }
+}
index e77f5dc5c8c43a1dd4faa689068e6492c0d3bcee..f80ba78c7327254962b4fad964000a8a1d216978 100644 (file)
@@ -1,55 +1,14 @@
 /*
- * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
 #include <errno.h>
-#include <stdint.h>
 
-#include <platform_def.h>
-
-#include <arch_helpers.h>
-#include <common/debug.h>
-#include <drivers/cfi/v2m_flash.h>
-#include <drivers/console.h>
 #include <plat/arm/common/plat_arm.h>
 #include <plat/common/platform.h>
 
-#pragma weak plat_arm_error_handler
-
-/*
- * ARM common implementation for error handler
- */
-void __dead2 plat_arm_error_handler(int err)
-{
-       int ret;
-
-       switch (err) {
-       case -ENOENT:
-       case -EAUTH:
-               /* Image load or authentication error. Erase the ToC */
-               INFO("Erasing FIP ToC from flash...\n");
-               (void)nor_unlock(PLAT_ARM_FIP_BASE);
-               ret = nor_word_program(PLAT_ARM_FIP_BASE, 0);
-               if (ret != 0) {
-                       ERROR("Cannot erase ToC\n");
-               } else {
-                       INFO("Done\n");
-               }
-               break;
-       default:
-               /* Unexpected error */
-               break;
-       }
-
-       (void)console_flush();
-
-       /* Loop until the watchdog resets the system */
-       for (;;)
-               wfi();
-}
-
 void __dead2 plat_error_handler(int err)
 {
        plat_arm_error_handler(err);
index e688c157b8083114b19334f571a92f69827d430c..cd9e9a297d20443a6d7ea4d5a527e8f25f0b9826 100644 (file)
@@ -138,7 +138,7 @@ static void init_freq(void)
        mmio_write_32((0xf6504000 + 0x06c), data);
 
        data = mmio_read_32((0xf6504000 + 0x06c));
-       data &= ~(0xffffff << 8);
+       data &= ~(0xffffffu << 8);
        data |= 0xc7a << 8;
        mmio_write_32((0xf6504000 + 0x06c), data);
 
index 132f33c61e3266642d835b6ffce4832fcb232e87..614eba2ff0a1566099b11e50e8b6179836434934 100644 (file)
 #define AO_SC_SYS_CTRL1_BUS_DFS_FORE_HD_CFG1_MSK               (1 << 27)
 #define AO_SC_SYS_CTRL1_USIM0_HPD_OE_SFT_MSK                   (1 << 28)
 #define AO_SC_SYS_CTRL1_USIM1_HPD_OE_SFT_MSK                   (1 << 29)
-#define AO_SC_SYS_CTRL1_MCU_CLKEN_HARDCFG_MSK                  (1 << 31)
+#define AO_SC_SYS_CTRL1_MCU_CLKEN_HARDCFG_MSK                  (1U << 31)
 
 #define AO_SC_SYS_CTRL2_MCU_SFT_RST_STAT_CLEAR                 (1 << 26)
 #define AO_SC_SYS_CTRL2_MCU_WDG0_RST_STAT_CLEAR                        (1 << 27)
 #define AO_SC_SYS_CTRL2_TSENSOR_RST_STAT_CLEAR                 (1 << 28)
 #define AO_SC_SYS_CTRL2_ACPU_WDG_RST_STAT_CLEAR                        (1 << 29)
 #define AO_SC_SYS_CTRL2_MCU_WDG1_RST_STAT_CLEAR                        (1 << 30)
-#define AO_SC_SYS_CTRL2_GLB_SRST_STAT_CLEAR                    (1 << 31)
+#define AO_SC_SYS_CTRL2_GLB_SRST_STAT_CLEAR                    (1U << 31)
 
 #define AO_SC_SYS_STAT0_MCU_RST_STAT                           (1 << 25)
 #define AO_SC_SYS_STAT0_MCU_SOFTRST_STAT                       (1 << 26)
 #define AO_SC_SYS_STAT0_TSENSOR_HARDRST_STAT                   (1 << 28)
 #define AO_SC_SYS_STAT0_ACPU_WD_GLB_RST_STAT                   (1 << 29)
 #define AO_SC_SYS_STAT0_CM3_WDG1_RST_STAT                      (1 << 30)
-#define AO_SC_SYS_STAT0_GLB_SRST_STAT                          (1 << 31)
+#define AO_SC_SYS_STAT0_GLB_SRST_STAT                          (1U << 31)
 
 #define AO_SC_SYS_STAT1_MODE_STATUS                            (1 << 0)
 #define AO_SC_SYS_STAT1_BOOT_SEL_LOCK                          (1 << 16)
 #define AO_SC_PERIPH_CLKEN4_CLK_JTAG_AUTH                      (1 << 28)
 #define AO_SC_PERIPH_CLKEN4_CLK_CS_DAPB_ON                     (1 << 29)
 #define AO_SC_PERIPH_CLKEN4_CLK_PDM                            (1 << 30)
-#define AO_SC_PERIPH_CLKEN4_CLK_SSI_PAD                                (1 << 31)
+#define AO_SC_PERIPH_CLKEN4_CLK_SSI_PAD                                (1U << 31)
 
 #define AO_SC_PERIPH_CLKEN5_PCLK_PMUSSI_CCPU                   (1 << 0)
 #define AO_SC_PERIPH_CLKEN5_PCLK_EFUSEC_CCPU                   (1 << 1)
index 8711ae43e310293281c2d41a457460c5238e0dc9..77236e8927b8e79a87536205031808db772688f0 100644 (file)
 #define PERI_CTRL4_OTG_SESSEND                 (1 << 28)
 #define PERI_CTRL4_OTG_BVALID                  (1 << 29)
 #define PERI_CTRL4_OTG_AVALID                  (1 << 30)
-#define PERI_CTRL4_OTG_VBUSVALID               (1 << 31)
+#define PERI_CTRL4_OTG_VBUSVALID               (1U << 31)
 
 /* PERI_SC_PERIPH_CTRL5 */
 #define PERI_CTRL5_USBOTG_RES_SEL              (1 << 3)
index bcf68650cd37cd6e20bdfd2d72c219e197921dfe..91d8033d6982a7fab2a10ef23103f97aeba25745 100644 (file)
@@ -23,7 +23,7 @@
 #define RES2_LOCK_BASE         (SOC_PCTRL_RESOURCE2_LOCK_ADDR(PCTRL_BASE))
 
 #define LOCK_BIT                       (0x1 << 28)
-#define LOCK_ID_MASK                   (0x7 << 29)
+#define LOCK_ID_MASK                   (0x7u << 29)
 #define CPUIDLE_LOCK_ID(core)          (0x6 - (core))
 #define LOCK_UNLOCK_OFFSET             0x4
 #define LOCK_STAT_OFFSET               0x8
index 5b9305acfd3bb3a5a18e382fb6c86e80549ee656..7cc1ee0b83dfdf099f9b02cbd3c072dbc66fc390 100644 (file)
@@ -67,7 +67,7 @@
 #define SCTRL_SCPERDIS1_REG            (SCTRL_REG_BASE + 0x174)
 #define SCTRL_SCPEREN1_REG             (SCTRL_REG_BASE + 0x170)
 #define SCTRL_SCPERDIS1_REG            (SCTRL_REG_BASE + 0x174)
-#define SCPEREN1_WAIT_DDR_SELFREFRESH_DONE_BYPASS      (1 << 31)
+#define SCPEREN1_WAIT_DDR_SELFREFRESH_DONE_BYPASS      (1u << 31)
 #define SCPEREN_GT_PCLK_MMBUFCFG       (1 << 25)
 #define SCPEREN_GT_PCLK_MMBUF          (1 << 23)
 #define SCPEREN_GT_ACLK_MMBUF          (1 << 22)
index ec587aa0db6658f66b93ee13482c88c8757ff2ab..eb5a6c5d1bd4e6c058b407817cf82f6944651d2a 100644 (file)
@@ -11,7 +11,7 @@
 #define CRG_PEREN0_REG                 (CRG_REG_BASE + 0x000)
 #define CRG_PERDIS0_REG                        (CRG_REG_BASE + 0x004)
 #define CRG_PERSTAT0_REG               (CRG_REG_BASE + 0x008)
-#define PEREN0_GT_CLK_AOMM             (1 << 31)
+#define PEREN0_GT_CLK_AOMM             (1U << 31)
 
 #define CRG_PEREN1_REG                 (CRG_REG_BASE + 0x010)
 #define CRG_PERDIS1_REG                        (CRG_REG_BASE + 0x014)
@@ -62,7 +62,7 @@
 #define CRG_PERRSTSTAT5_REG            (CRG_REG_BASE + 0x0A4)
 
 /* bit fields in CRG_PERI */
-#define PERI_PCLK_PCTRL_BIT            (1 << 31)
+#define PERI_PCLK_PCTRL_BIT            (1U << 31)
 #define PERI_TIMER12_BIT               (1 << 25)
 #define PERI_TIMER11_BIT               (1 << 24)
 #define PERI_TIMER10_BIT               (1 << 23)
index 4d2de4a5d87d2e1a730ca97e61ae57c5feb7d83c..dc9e8133cbdce8eb10e1ff299fbeb01f176f4b25 100644 (file)
@@ -13,7 +13,7 @@
 #define HKADC_DSP_START_CLR_REG                        (HKADC_SSI_REG_BASE + 0x01C)
 #define HKADC_WR01_DATA_REG                    (HKADC_SSI_REG_BASE + 0x020)
 
-#define WR1_WRITE_MODE                         (1 << 31)
+#define WR1_WRITE_MODE                         (1U << 31)
 #define WR1_READ_MODE                          (0 << 31)
 #define WR1_ADDR(x)                            (((x) & 0x7F) << 24)
 #define WR1_DATA(x)                            (((x) & 0xFF) << 16)
@@ -47,7 +47,7 @@
 
 #define HKADC_WR01_VALUE                       ((HKADC_START_ADDR << 24) | \
                                                 (0x1 << 16))
-#define HKADC_WR23_VALUE                       ((0x1 << 31) |          \
+#define HKADC_WR23_VALUE                       ((0x1u << 31) |         \
                                                 (HKADC_DATA0_ADDR << 24) | \
                                                 (1 << 15) |            \
                                                 (HKADC_DATA1_ADDR << 8))
index edcac7bf3d0ce29d5f64ab2749428641e0fb6764..7885219b70a161de80a367db7ca591671c52f132 100644 (file)
@@ -13,7 +13,7 @@
 #define MU_TR_COUNT1           4
 #define MU_RR_COUNT1           4
 
-#define MU_CR_GIEn_MASK1       (0xF << 28)
+#define MU_CR_GIEn_MASK1       (0xFu << 28)
 #define MU_CR_RIEn_MASK1       (0xF << 24)
 #define MU_CR_TIEn_MASK1       (0xF << 20)
 #define MU_CR_GIRn_MASK1       (0xF << 16)
@@ -23,7 +23,7 @@
 #define MU_SR_TE0_MASK1                (1 << 23)
 #define MU_SR_RF0_MASK1                (1 << 27)
 #define MU_CR_RIE0_MASK1       (1 << 27)
-#define MU_CR_GIE0_MASK1       (1 << 31)
+#define MU_CR_GIE0_MASK1       (1U << 31)
 
 #define MU_TR_COUNT                    4
 #define MU_RR_COUNT                    4
diff --git a/plat/imx/imx8m/imx8m_caam.c b/plat/imx/imx8m/imx8m_caam.c
new file mode 100644 (file)
index 0000000..478005e
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2019, NXP. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <lib/mmio.h>
+
+#include <imx8m_caam.h>
+
+void imx8m_caam_init(void)
+{
+       uint32_t sm_cmd;
+
+       /* Dealloc part 0 and 2 with current DID */
+       sm_cmd = (0 << SMC_PART_SHIFT | SMC_CMD_DEALLOC_PART);
+       mmio_write_32(SM_CMD, sm_cmd);
+
+       sm_cmd = (2 << SMC_PART_SHIFT | SMC_CMD_DEALLOC_PART);
+       mmio_write_32(SM_CMD, sm_cmd);
+
+       /* config CAAM JRaMID set MID to Cortex A */
+       mmio_write_32(CAAM_JR0MID, CAAM_NS_MID);
+       mmio_write_32(CAAM_JR1MID, CAAM_NS_MID);
+       mmio_write_32(CAAM_JR2MID, CAAM_NS_MID);
+
+       /* Alloc partition 0 writing SMPO and SMAGs */
+       mmio_write_32(SM_P0_PERM, 0xff);
+       mmio_write_32(SM_P0_SMAG2, 0xffffffff);
+       mmio_write_32(SM_P0_SMAG1, 0xffffffff);
+
+       /* Allocate page 0 and 1 to partition 0 with DID set */
+       sm_cmd = (0 << SMC_PAGE_SHIFT | 0 << SMC_PART_SHIFT |
+                       SMC_CMD_ALLOC_PAGE);
+       mmio_write_32(SM_CMD, sm_cmd);
+
+       sm_cmd = (1 << SMC_PAGE_SHIFT | 0 << SMC_PART_SHIFT |
+                       SMC_CMD_ALLOC_PAGE);
+       mmio_write_32(SM_CMD, sm_cmd);
+}
index 8bfb5452a748edba7882a217027cfd5a50bfa0ea..63d9223a2bd0255157bbace24c89f013ed255649 100644 (file)
@@ -24,6 +24,7 @@
 #include <gpc.h>
 #include <imx_aipstz.h>
 #include <imx_uart.h>
+#include <imx8m_caam.h>
 #include <plat_imx8.h>
 
 static const mmap_region_t imx_mmap[] = {
@@ -93,6 +94,8 @@ void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
 
        imx_aipstz_init(aipstz);
 
+       imx8m_caam_init();
+
        console_imx_uart_register(IMX_BOOT_UART_BASE, IMX_BOOT_UART_CLK_IN_HZ,
                IMX_CONSOLE_BAUDRATE, &console);
        /* This console is only used for boot stage */
index a95ab830352cee057c1bb4262be3be3da29f5f9e..de9e3b5c85a04542e2fb6bc3f81f0ae2be33cb48 100644 (file)
@@ -77,6 +77,7 @@
 #define IMX_NOC_BASE                   U(0x32700000)
 #define IMX_TZASC_BASE                 U(0x32F80000)
 #define IMX_IOMUX_GPR_BASE             U(0x30340000)
+#define IMX_CAAM_BASE                  U(0x30900000)
 #define IMX_DDRC_BASE                  U(0x3d400000)
 #define IMX_DDRPHY_BASE                        U(0x3c000000)
 #define IMX_DDR_IPS_BASE               U(0x3d000000)
index a3d249a65a274bef16bc6807861d0dd220736c1f..c28463b7c5fc845f0d68a533c888ed2b27858103 100644 (file)
@@ -20,6 +20,7 @@ IMX_GIC_SOURCES               :=      drivers/arm/gic/v3/gicv3_helpers.c      \
 BL31_SOURCES           +=      plat/imx/common/imx8_helpers.S                  \
                                plat/imx/imx8m/gpc_common.c                     \
                                plat/imx/imx8m/imx_aipstz.c                     \
+                               plat/imx/imx8m/imx8m_caam.c                     \
                                plat/imx/imx8m/imx8m_psci_common.c              \
                                plat/imx/imx8m/imx8mm/imx8mm_bl31_setup.c       \
                                plat/imx/imx8m/imx8mm/imx8mm_psci.c             \
index ce55d7f3134061f0581f824f284976c855010e80..26a3b364e93d4450ec58b067045956a8727f1d72 100644 (file)
@@ -24,6 +24,7 @@
 #include <gpc.h>
 #include <imx_aipstz.h>
 #include <imx_uart.h>
+#include <imx8m_caam.h>
 #include <plat_imx8.h>
 
 static const mmap_region_t imx_mmap[] = {
@@ -129,10 +130,7 @@ void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
 
        imx_aipstz_init(aipstz);
 
-       /* config CAAM JRaMID set MID to Cortex A */
-       mmio_write_32(CAAM_JR0MID, CAAM_NS_MID);
-       mmio_write_32(CAAM_JR1MID, CAAM_NS_MID);
-       mmio_write_32(CAAM_JR2MID, CAAM_NS_MID);
+       imx8m_caam_init();
 
 #if DEBUG_CONSOLE
        static console_uart_t console;
index 959b820c52c1f05e91b41c863fac5d9de2b11f3b..3c212e37829b57cda4709201fed7097226e33c5b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -70,6 +70,7 @@
 #define IMX_SNVS_BASE                  U(0x30370000)
 #define IMX_NOC_BASE                   U(0x32700000)
 #define IMX_TZASC_BASE                 U(0x32F80000)
+#define IMX_CAAM_BASE                  U(0x30900000)
 #define IMX_IOMUX_GPR_BASE             U(0x30340000)
 #define IMX_DDRC_BASE                  U(0x3d400000)
 #define IMX_DDRPHY_BASE                        U(0x3c000000)
 
 #define DEBUG_CONSOLE                  0
 #define IMX_WDOG_B_RESET
-
-#define CAAM_JR0MID                    U(0x30900010)
-#define CAAM_JR1MID                    U(0x30900018)
-#define CAAM_JR2MID                    U(0x30900020)
-#define CAAM_NS_MID                    U(0x1)
index d6879bf74ba5d5d1d7f3a47ef0a4db09c2d11857..44ce555871953d5406f4b1ec1287b21695f9ebeb 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
+# Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -22,6 +22,7 @@ BL31_SOURCES          +=      plat/imx/common/imx8_helpers.S                  \
                                plat/imx/imx8m/imx8mq/imx8mq_psci.c             \
                                plat/imx/imx8m/gpc_common.c                     \
                                plat/imx/imx8m/imx_aipstz.c                     \
+                               plat/imx/imx8m/imx8m_caam.c                     \
                                plat/imx/imx8m/imx8m_psci_common.c              \
                                plat/imx/imx8m/imx8mq/gpc.c                     \
                                plat/imx/common/imx8_topology.c                 \
diff --git a/plat/imx/imx8m/include/imx8m_caam.h b/plat/imx/imx8m/include/imx8m_caam.h
new file mode 100644 (file)
index 0000000..84725b1
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2019, NXP. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef IMX8M_CAAM_H
+#define IMX8M_CAAM_H
+
+#include <lib/utils_def.h>
+
+#include <platform_def.h>
+
+#define CAAM_JR0MID            (IMX_CAAM_BASE + 0x10)
+#define CAAM_JR1MID            (IMX_CAAM_BASE + 0x18)
+#define CAAM_JR2MID            (IMX_CAAM_BASE + 0x20)
+#define CAAM_NS_MID            (0x1)
+
+#define JR0_BASE               (IMX_CAAM_BASE + 0x1000)
+
+#define SM_P0_PERM             (JR0_BASE + 0xa04)
+#define SM_P0_SMAG2            (JR0_BASE + 0xa08)
+#define SM_P0_SMAG1            (JR0_BASE + 0xa0c)
+#define SM_CMD                 (JR0_BASE + 0xbe4)
+
+/* secure memory command */
+#define SMC_PAGE_SHIFT         16
+#define SMC_PART_SHIFT         8
+
+#define SMC_CMD_ALLOC_PAGE     0x01    /* allocate page to this partition */
+#define SMC_CMD_DEALLOC_PART   0x03    /* deallocate partition */
+
+void imx8m_caam_init(void);
+
+#endif /* IMX8M_CAAM_H */
diff --git a/plat/intel/soc/agilex/aarch64/plat_helpers.S b/plat/intel/soc/agilex/aarch64/plat_helpers.S
new file mode 100644 (file)
index 0000000..b3f5a5e
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <arch.h>
+#include <asm_macros.S>
+#include <cpu_macros.S>
+#include <platform_def.h>
+
+       .globl  plat_secondary_cold_boot_setup
+       .globl  platform_is_primary_cpu
+       .globl  plat_is_my_cpu_primary
+       .globl  plat_my_core_pos
+       .globl  plat_crash_console_init
+       .globl  plat_crash_console_putc
+       .globl  plat_crash_console_flush
+       .globl  platform_mem_init
+
+       .globl plat_get_my_entrypoint
+
+       /* -----------------------------------------------------
+        * void plat_secondary_cold_boot_setup (void);
+        *
+        * This function performs any platform specific actions
+        * needed for a secondary cpu after a cold reset e.g
+        * mark the cpu's presence, mechanism to place it in a
+        * holding pen etc.
+        * -----------------------------------------------------
+        */
+func plat_secondary_cold_boot_setup
+       /* Wait until the it gets reset signal from rstmgr gets populated */
+poll_mailbox:
+       wfi
+
+       mov_imm x0, PLAT_AGX_SEC_ENTRY
+       ldr     x1, [x0]
+       mov_imm x2, PLAT_CPUID_RELEASE
+       ldr     x3, [x2]
+       mrs     x4, mpidr_el1
+       and     x4, x4, #0xff
+       cmp     x3, x4
+       b.ne    poll_mailbox
+       br      x1
+endfunc plat_secondary_cold_boot_setup
+
+func platform_is_primary_cpu
+       and     x0, x0, #(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)
+       cmp     x0, #PLAT_PRIMARY_CPU
+       cset    x0, eq
+       ret
+endfunc platform_is_primary_cpu
+
+func plat_is_my_cpu_primary
+       mrs     x0, mpidr_el1
+       b   platform_is_primary_cpu
+endfunc plat_is_my_cpu_primary
+
+func plat_my_core_pos
+       mrs     x0, mpidr_el1
+       and     x1, x0, #MPIDR_CPU_MASK
+       and     x0, x0, #MPIDR_CLUSTER_MASK
+       add     x0, x1, x0, LSR #6
+       ret
+endfunc plat_my_core_pos
+
+func plat_get_my_entrypoint
+       mov_imm x1, PLAT_AGX_SEC_ENTRY
+       ldr     x0, [x1]
+       ret
+endfunc plat_get_my_entrypoint
+
+       /* ---------------------------------------------
+        * int plat_crash_console_init(void)
+        * Function to initialize the crash console
+        * without a C Runtime to print crash report.
+        * Clobber list : x0, x1, x2
+        * ---------------------------------------------
+        */
+func plat_crash_console_init
+       mov_imm x0, PLAT_UART0_BASE
+       mov_imm x1, PLAT_UART_CLOCK
+       mov_imm x2, PLAT_BAUDRATE
+       b       console_16550_core_init
+endfunc plat_crash_console_init
+
+       /* ---------------------------------------------
+        * int plat_crash_console_putc(void)
+        * Function to print a character on the crash
+        * console without a C Runtime.
+        * Clobber list : x1, x2
+        * ---------------------------------------------
+        */
+func plat_crash_console_putc
+       mov_imm x1, PLAT_UART0_BASE
+       b       console_16550_core_putc
+endfunc plat_crash_console_putc
+
+func plat_crash_console_flush
+       mov_imm x0, CRASH_CONSOLE_BASE
+       b       console_16550_core_flush
+endfunc plat_crash_console_flush
+
+
+       /* --------------------------------------------------------
+        * void platform_mem_init (void);
+        *
+        * Any memory init, relocation to be done before the
+        * platform boots. Called very early in the boot process.
+        * --------------------------------------------------------
+        */
+func platform_mem_init
+       mov     x0, #0
+       ret
+endfunc platform_mem_init
diff --git a/plat/intel/soc/agilex/aarch64/platform_common.c b/plat/intel/soc/agilex/aarch64/platform_common.c
new file mode 100644 (file)
index 0000000..6d3d817
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <arch.h>
+#include <arch_helpers.h>
+#include <platform_def.h>
+#include <plat/common/platform.h>
+#include <socfpga_private.h>
+
+
+unsigned int plat_get_syscnt_freq2(void)
+{
+       return PLAT_SYS_COUNTER_FREQ_IN_TICKS;
+}
+
+unsigned long socfpga_get_ns_image_entrypoint(void)
+{
+       return PLAT_NS_IMAGE_OFFSET;
+}
+
+/******************************************************************************
+ * Gets SPSR for BL32 entry
+ *****************************************************************************/
+uint32_t socfpga_get_spsr_for_bl32_entry(void)
+{
+       /*
+        * The Secure Payload Dispatcher service is responsible for
+        * setting the SPSR prior to entry into the BL32 image.
+        */
+       return 0;
+}
+
+/******************************************************************************
+ * Gets SPSR for BL33 entry
+ *****************************************************************************/
+uint32_t socfpga_get_spsr_for_bl33_entry(void)
+{
+       unsigned long el_status;
+       unsigned int mode;
+       uint32_t spsr;
+
+       /* Figure out what mode we enter the non-secure world in */
+       el_status = read_id_aa64pfr0_el1() >> ID_AA64PFR0_EL2_SHIFT;
+       el_status &= ID_AA64PFR0_ELX_MASK;
+
+       mode = (el_status) ? MODE_EL2 : MODE_EL1;
+
+       /*
+        * TODO: Consider the possibility of specifying the SPSR in
+        * the FIP ToC and allowing the platform to have a say as
+        * well.
+        */
+       spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
+       return spsr;
+}
+
diff --git a/plat/intel/soc/agilex/bl2_plat_mem_params_desc.c b/plat/intel/soc/agilex/bl2_plat_mem_params_desc.c
new file mode 100644 (file)
index 0000000..4f75665
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <common/bl_common.h>
+#include <common/desc_image_load.h>
+#include <platform_def.h>
+#include <plat/common/platform.h>
+
+
+/*******************************************************************************
+ * Following descriptor provides BL image/ep information that gets used
+ * by BL2 to load the images and also subset of this information is
+ * passed to next BL image. The image loading sequence is managed by
+ * populating the images in required loading order. The image execution
+ * sequence is managed by populating the `next_handoff_image_id` with
+ * the next executable image id.
+ ******************************************************************************/
+static bl_mem_params_node_t bl2_mem_params_descs[] = {
+#ifdef SCP_BL2_BASE
+       /* Fill SCP_BL2 related information if it exists */
+       {
+           .image_id = SCP_BL2_IMAGE_ID,
+
+           SET_STATIC_PARAM_HEAD(ep_info, PARAM_IMAGE_BINARY,
+                   VERSION_2, entry_point_info_t, SECURE | NON_EXECUTABLE),
+
+           SET_STATIC_PARAM_HEAD(image_info, PARAM_IMAGE_BINARY,
+                   VERSION_2, image_info_t, 0),
+           .image_info.image_base = SCP_BL2_BASE,
+           .image_info.image_max_size = SCP_BL2_SIZE,
+
+           .next_handoff_image_id = INVALID_IMAGE_ID,
+       },
+#endif /* SCP_BL2_BASE */
+
+#ifdef EL3_PAYLOAD_BASE
+       /* Fill EL3 payload related information (BL31 is EL3 payload)*/
+       {
+           .image_id = BL31_IMAGE_ID,
+
+           SET_STATIC_PARAM_HEAD(ep_info, PARAM_EP,
+                   VERSION_2, entry_point_info_t,
+                   SECURE | EXECUTABLE | EP_FIRST_EXE),
+           .ep_info.pc = EL3_PAYLOAD_BASE,
+           .ep_info.spsr = SPSR_64(MODE_EL3, MODE_SP_ELX,
+                   DISABLE_ALL_EXCEPTIONS),
+
+           SET_STATIC_PARAM_HEAD(image_info, PARAM_EP,
+                   VERSION_2, image_info_t,
+                   IMAGE_ATTRIB_PLAT_SETUP | IMAGE_ATTRIB_SKIP_LOADING),
+
+           .next_handoff_image_id = INVALID_IMAGE_ID,
+       },
+
+#else /* EL3_PAYLOAD_BASE */
+
+       /* Fill BL31 related information */
+       {
+           .image_id = BL31_IMAGE_ID,
+
+           SET_STATIC_PARAM_HEAD(ep_info, PARAM_EP,
+                   VERSION_2, entry_point_info_t,
+                   SECURE | EXECUTABLE | EP_FIRST_EXE),
+           .ep_info.pc = BL31_BASE,
+           .ep_info.spsr = SPSR_64(MODE_EL3, MODE_SP_ELX,
+                   DISABLE_ALL_EXCEPTIONS),
+
+           SET_STATIC_PARAM_HEAD(image_info, PARAM_EP,
+                   VERSION_2, image_info_t, IMAGE_ATTRIB_PLAT_SETUP),
+           .image_info.image_base = BL31_BASE,
+           .image_info.image_max_size = BL31_LIMIT - BL31_BASE,
+
+           .next_handoff_image_id = BL33_IMAGE_ID,
+       },
+#endif /* EL3_PAYLOAD_BASE */
+
+       {
+               .image_id = BL33_IMAGE_ID,
+               SET_STATIC_PARAM_HEAD(ep_info, PARAM_EP,
+                       VERSION_2, entry_point_info_t, NON_SECURE | EXECUTABLE),
+               .ep_info.pc = PLAT_NS_IMAGE_OFFSET,
+
+               SET_STATIC_PARAM_HEAD(image_info, PARAM_EP,
+                       VERSION_2, image_info_t, 0),
+               .image_info.image_base = PLAT_NS_IMAGE_OFFSET,
+               .image_info.image_max_size =
+                       0x0 + 0x40000000 - PLAT_NS_IMAGE_OFFSET,
+
+               .next_handoff_image_id = INVALID_IMAGE_ID,
+       },
+};
+
+REGISTER_BL_IMAGE_DESCS(bl2_mem_params_descs)
diff --git a/plat/intel/soc/agilex/bl2_plat_setup.c b/plat/intel/soc/agilex/bl2_plat_setup.c
new file mode 100644 (file)
index 0000000..385065f
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <arch.h>
+#include <arch_helpers.h>
+#include <common/bl_common.h>
+#include <common/debug.h>
+#include <common/desc_image_load.h>
+#include <drivers/generic_delay_timer.h>
+#include <drivers/synopsys/dw_mmc.h>
+#include <drivers/ti/uart/uart_16550.h>
+#include <lib/xlat_tables/xlat_tables.h>
+#include <platform_def.h>
+#include <socfpga_private.h>
+
+#include "agilex_clock_manager.h"
+#include "agilex_handoff.h"
+#include "agilex_mailbox.h"
+#include "agilex_memory_controller.h"
+#include "agilex_pinmux.h"
+#include "agilex_private.h"
+#include "agilex_reset_manager.h"
+#include "agilex_system_manager.h"
+
+#include "ccu/ncore_ccu.h"
+#include "qspi/cadence_qspi.h"
+#include "wdt/watchdog.h"
+
+
+const mmap_region_t agilex_plat_mmap[] = {
+       MAP_REGION_FLAT(DRAM_BASE, DRAM_SIZE,
+               MT_MEMORY | MT_RW | MT_NS),
+       MAP_REGION_FLAT(DEVICE1_BASE, DEVICE1_SIZE,
+               MT_DEVICE | MT_RW | MT_NS),
+       MAP_REGION_FLAT(DEVICE2_BASE, DEVICE2_SIZE,
+               MT_DEVICE | MT_RW | MT_SECURE),
+       MAP_REGION_FLAT(OCRAM_BASE, OCRAM_SIZE,
+               MT_NON_CACHEABLE | MT_RW | MT_SECURE),
+       MAP_REGION_FLAT(DEVICE3_BASE, DEVICE3_SIZE,
+               MT_DEVICE | MT_RW | MT_SECURE),
+       MAP_REGION_FLAT(MEM64_BASE, MEM64_SIZE,
+               MT_DEVICE | MT_RW | MT_NS),
+       MAP_REGION_FLAT(DEVICE4_BASE, DEVICE4_SIZE,
+               MT_DEVICE | MT_RW | MT_NS),
+       {0},
+};
+
+boot_source_type boot_source;
+
+void bl2_el3_early_platform_setup(u_register_t x0, u_register_t x1,
+                               u_register_t x2, u_register_t x4)
+{
+       static console_16550_t console;
+       handoff reverse_handoff_ptr;
+
+       generic_delay_timer_init();
+
+       if (agilex_get_handoff(&reverse_handoff_ptr))
+               return;
+       config_pinmux(&reverse_handoff_ptr);
+       boot_source = reverse_handoff_ptr.boot_source;
+       config_clkmgr_handoff(&reverse_handoff_ptr);
+
+       enable_nonsecure_access();
+       deassert_peripheral_reset();
+       config_hps_hs_before_warm_reset();
+
+       watchdog_init(get_wdt_clk(&reverse_handoff_ptr));
+
+       console_16550_register(PLAT_UART0_BASE, PLAT_UART_CLOCK, PLAT_BAUDRATE,
+               &console);
+
+       socfpga_delay_timer_init();
+       init_ncore_ccu();
+       init_hard_memory_controller();
+       enable_ns_bridge_access();
+}
+
+
+void bl2_el3_plat_arch_setup(void)
+{
+
+       struct mmc_device_info info;
+       const mmap_region_t bl_regions[] = {
+               MAP_REGION_FLAT(BL2_BASE, BL2_END - BL2_BASE,
+                       MT_MEMORY | MT_RW | MT_SECURE),
+               MAP_REGION_FLAT(BL_CODE_BASE, BL_CODE_END - BL_CODE_BASE,
+                       MT_CODE | MT_SECURE),
+               MAP_REGION_FLAT(BL_RO_DATA_BASE,
+                       BL_RO_DATA_END - BL_RO_DATA_BASE,
+                       MT_RO_DATA | MT_SECURE),
+#if USE_COHERENT_MEM_BAR
+               MAP_REGION_FLAT(BL_COHERENT_RAM_BASE,
+                       BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE,
+                       MT_DEVICE | MT_RW | MT_SECURE),
+#endif
+               {0},
+       };
+
+       setup_page_tables(bl_regions, agilex_plat_mmap);
+
+       enable_mmu_el3(0);
+
+       dw_mmc_params_t params = EMMC_INIT_PARAMS(0x100000);
+
+       info.mmc_dev_type = MMC_IS_SD;
+       info.ocr_voltage = OCR_3_3_3_4 | OCR_3_2_3_3;
+
+       mailbox_init();
+
+       switch (boot_source) {
+       case BOOT_SOURCE_SDMMC:
+               dw_mmc_init(&params, &info);
+               socfpga_io_setup(boot_source);
+               break;
+
+       case BOOT_SOURCE_QSPI:
+               mailbox_set_qspi_open();
+               mailbox_set_qspi_direct();
+               cad_qspi_init(0, QSPI_CONFIG_CPHA, QSPI_CONFIG_CPOL,
+                       QSPI_CONFIG_CSDA, QSPI_CONFIG_CSDADS,
+                       QSPI_CONFIG_CSEOT, QSPI_CONFIG_CSSOT, 0);
+               socfpga_io_setup(boot_source);
+               break;
+
+       default:
+               ERROR("Unsupported boot source\n");
+               panic();
+               break;
+       }
+}
+
+uint32_t get_spsr_for_bl33_entry(void)
+{
+       unsigned long el_status;
+       unsigned int mode;
+       uint32_t spsr;
+
+       /* Figure out what mode we enter the non-secure world in */
+       el_status = read_id_aa64pfr0_el1() >> ID_AA64PFR0_EL2_SHIFT;
+       el_status &= ID_AA64PFR0_ELX_MASK;
+
+       mode = (el_status) ? MODE_EL2 : MODE_EL1;
+
+       /*
+        * TODO: Consider the possibility of specifying the SPSR in
+        * the FIP ToC and allowing the platform to have a say as
+        * well.
+        */
+       spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
+       return spsr;
+}
+
+
+int bl2_plat_handle_post_image_load(unsigned int image_id)
+{
+       bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
+
+       switch (image_id) {
+       case BL33_IMAGE_ID:
+               bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
+               bl_mem_params->ep_info.spsr = get_spsr_for_bl33_entry();
+               break;
+       default:
+               break;
+       }
+
+       return 0;
+}
+
+/*******************************************************************************
+ * Perform any BL3-1 platform setup code
+ ******************************************************************************/
+void bl2_platform_setup(void)
+{
+}
+
diff --git a/plat/intel/soc/agilex/bl31_plat_setup.c b/plat/intel/soc/agilex/bl31_plat_setup.c
new file mode 100644 (file)
index 0000000..03fba8a
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <arch.h>
+#include <arch_helpers.h>
+#include <assert.h>
+#include <common/bl_common.h>
+#include <drivers/arm/gicv2.h>
+#include <drivers/ti/uart/uart_16550.h>
+#include <lib/xlat_tables/xlat_tables.h>
+#include <platform_def.h>
+
+
+static entry_point_info_t bl32_image_ep_info;
+static entry_point_info_t bl33_image_ep_info;
+
+entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
+{
+       entry_point_info_t *next_image_info;
+
+       next_image_info = (type == NON_SECURE) ?
+                         &bl33_image_ep_info : &bl32_image_ep_info;
+
+       /* None of the images on this platform can have 0x0 as the entrypoint */
+       if (next_image_info->pc)
+               return next_image_info;
+       else
+               return NULL;
+}
+
+void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
+                               u_register_t arg2, u_register_t arg3)
+{
+       static console_16550_t console;
+
+       console_16550_register(PLAT_UART0_BASE, PLAT_UART_CLOCK, PLAT_BAUDRATE,
+               &console);
+       /*
+        * Check params passed from BL31 should not be NULL,
+        */
+       void *from_bl2 = (void *) arg0;
+
+       bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
+
+       assert(params_from_bl2 != NULL);
+       assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
+       assert(params_from_bl2->h.version >= VERSION_2);
+
+       /*
+        * Copy BL32 (if populated by BL31) and BL33 entry point information.
+        * They are stored in Secure RAM, in BL31's address space.
+        */
+
+       bl_params_node_t *bl_params = params_from_bl2->head;
+
+       while (bl_params) {
+               if (bl_params->image_id == BL33_IMAGE_ID)
+                       bl33_image_ep_info = *bl_params->ep_info;
+
+               bl_params = bl_params->next_params_info;
+       }
+       SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE);
+}
+
+static const interrupt_prop_t s10_interrupt_props[] = {
+       PLAT_INTEL_AGX_G1S_IRQ_PROPS(GICV2_INTR_GROUP0),
+       PLAT_INTEL_AGX_G0_IRQ_PROPS(GICV2_INTR_GROUP0)
+};
+
+static unsigned int target_mask_array[PLATFORM_CORE_COUNT];
+
+static const gicv2_driver_data_t plat_gicv2_gic_data = {
+       .gicd_base = PLAT_INTEL_AGX_GICD_BASE,
+       .gicc_base = PLAT_INTEL_AGX_GICC_BASE,
+       .interrupt_props = s10_interrupt_props,
+       .interrupt_props_num = ARRAY_SIZE(s10_interrupt_props),
+       .target_masks = target_mask_array,
+       .target_masks_num = ARRAY_SIZE(target_mask_array),
+};
+
+/*******************************************************************************
+ * Perform any BL3-1 platform setup code
+ ******************************************************************************/
+void bl31_platform_setup(void)
+{
+       /* Initialize the gic cpu and distributor interfaces */
+       gicv2_driver_init(&plat_gicv2_gic_data);
+       gicv2_distif_init();
+       gicv2_pcpu_distif_init();
+       gicv2_cpuif_enable();
+}
+
+const mmap_region_t plat_agilex_mmap[] = {
+       MAP_REGION_FLAT(DRAM_BASE, DRAM_SIZE, MT_MEMORY | MT_RW | MT_NS),
+       MAP_REGION_FLAT(DEVICE1_BASE, DEVICE1_SIZE, MT_DEVICE | MT_RW | MT_NS),
+       MAP_REGION_FLAT(DEVICE2_BASE, DEVICE2_SIZE, MT_DEVICE | MT_RW | MT_NS),
+       MAP_REGION_FLAT(OCRAM_BASE, OCRAM_SIZE,
+               MT_NON_CACHEABLE | MT_RW | MT_SECURE),
+       MAP_REGION_FLAT(DEVICE3_BASE, DEVICE3_SIZE,
+               MT_DEVICE | MT_RW | MT_SECURE),
+       MAP_REGION_FLAT(MEM64_BASE, MEM64_SIZE, MT_DEVICE | MT_RW | MT_NS),
+       MAP_REGION_FLAT(DEVICE4_BASE, DEVICE4_SIZE, MT_DEVICE | MT_RW | MT_NS),
+       {0},
+};
+
+/*******************************************************************************
+ * Perform the very early platform specific architectural setup here. At the
+ * moment this is only intializes the mmu in a quick and dirty way.
+ ******************************************************************************/
+void bl31_plat_arch_setup(void)
+{
+       const mmap_region_t bl_regions[] = {
+               MAP_REGION_FLAT(BL31_BASE, BL31_END - BL31_BASE,
+                       MT_MEMORY | MT_RW | MT_SECURE),
+               MAP_REGION_FLAT(BL_CODE_BASE, BL_CODE_END - BL_CODE_BASE,
+                       MT_CODE | MT_SECURE),
+               MAP_REGION_FLAT(BL_RO_DATA_BASE,
+                       BL_RO_DATA_END - BL_RO_DATA_BASE,
+                       MT_RO_DATA | MT_SECURE),
+#if USE_COHERENT_MEM
+               MAP_REGION_FLAT(BL_COHERENT_RAM_BASE,
+                       BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE,
+                       MT_DEVICE | MT_RW | MT_SECURE),
+#endif
+               {0},
+       };
+
+       setup_page_tables(bl_regions, plat_agilex_mmap);
+       enable_mmu_el3(0);
+}
+
diff --git a/plat/intel/soc/agilex/include/agilex_clock_manager.h b/plat/intel/soc/agilex/include/agilex_clock_manager.h
new file mode 100644 (file)
index 0000000..c1a7546
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef CLOCKMANAGER_H
+#define CLOCKMANAGER_H
+
+#include "agilex_handoff.h"
+
+/* Clock Manager Registers */
+#define CLKMGR_OFFSET                          0xffd10000
+
+#define CLKMGR_CTRL                            0x0
+#define CLKMGR_STAT                            0x4
+#define CLKMGR_INTRCLR                         0x14
+
+/* Main PLL Group */
+#define CLKMGR_MAINPLL                         0xffd10024
+#define CLKMGR_MAINPLL_EN                      0x0
+#define CLKMGR_MAINPLL_BYPASS                  0xc
+#define CLKMGR_MAINPLL_MPUCLK                  0x18
+#define CLKMGR_MAINPLL_NOCCLK                  0x1c
+#define CLKMGR_MAINPLL_NOCDIV                  0x20
+#define CLKMGR_MAINPLL_PLLGLOB                 0x24
+#define CLKMGR_MAINPLL_FDBCK                   0x28
+#define CLKMGR_MAINPLL_MEM                     0x2c
+#define CLKMGR_MAINPLL_MEMSTAT                 0x30
+#define CLKMGR_MAINPLL_PLLC0                   0x34
+#define CLKMGR_MAINPLL_PLLC1                   0x38
+#define CLKMGR_MAINPLL_VCOCALIB                        0x3c
+#define CLKMGR_MAINPLL_PLLC2                   0x40
+#define CLKMGR_MAINPLL_PLLC3                   0x44
+#define CLKMGR_MAINPLL_PLLM                    0x48
+
+/* Peripheral PLL Group */
+#define CLKMGR_PERPLL                          0xffd1007c
+#define CLKMGR_PERPLL_EN                       0x0
+#define CLKMGR_PERPLL_BYPASS                   0xc
+#define CLKMGR_PERPLL_EMACCTL                  0x18
+#define CLKMGR_PERPLL_GPIODIV                  0x1c
+#define CLKMGR_PERPLL_PLLGLOB                  0x20
+#define CLKMGR_PERPLL_FDBCK                    0x24
+#define CLKMGR_PERPLL_MEM                      0x28
+#define CLKMGR_PERPLL_MEMSTAT                  0x2c
+#define CLKMGR_PERPLL_PLLC0                    0x30
+#define CLKMGR_PERPLL_PLLC1                    0x34
+#define CLKMGR_PERPLL_VCOCALIB                 0x38
+#define CLKMGR_PERPLL_PLLC2                    0x3c
+#define CLKMGR_PERPLL_PLLC3                    0x40
+#define CLKMGR_PERPLL_PLLM                     0x44
+
+/* Altera Group */
+#define CLKMGR_ALTERA                          0xffd100d0
+#define CLKMGR_ALTERA_JTAG                     0x0
+#define CLKMGR_ALTERA_EMACACTR                 0x4
+#define CLKMGR_ALTERA_EMACBCTR                 0x8
+#define CLKMGR_ALTERA_EMACPTPCTR               0xc
+#define CLKMGR_ALTERA_GPIODBCTR                        0x10
+#define CLKMGR_ALTERA_SDMMCCTR                 0x14
+#define CLKMGR_ALTERA_S2FUSER0CTR              0x18
+#define CLKMGR_ALTERA_S2FUSER1CTR              0x1c
+#define CLKMGR_ALTERA_PSIREFCTR                        0x20
+#define CLKMGR_ALTERA_EXTCNTRST                        0x24
+
+/* Membus */
+#define CLKMGR_MEM_REQ                         BIT(24)
+#define CLKMGR_MEM_WR                          BIT(25)
+#define CLKMGR_MEM_ERR                         BIT(26)
+#define CLKMGR_MEM_WDAT_OFFSET                 16
+#define CLKMGR_MEM_ADDR                                0x4027
+#define CLKMGR_MEM_WDAT                                0x80
+
+/* Clock Manager Macros */
+#define CLKMGR_CTRL_BOOTMODE_SET_MSK           0x00000001
+#define CLKMGR_STAT_BUSY_E_BUSY                        0x1
+#define CLKMGR_STAT_BUSY(x)                    (((x) & 0x00000001) >> 0)
+#define CLKMGR_STAT_MAINPLLLOCKED(x)           (((x) & 0x00000100) >> 8)
+#define CLKMGR_STAT_PERPLLLOCKED(x)            (((x) & 0x00010000) >> 16)
+#define CLKMGR_INTRCLR_MAINLOCKLOST_SET_MSK    0x00000004
+#define CLKMGR_INTRCLR_PERLOCKLOST_SET_MSK     0x00000008
+
+/* Main PLL Macros */
+#define CLKMGR_MAINPLL_EN_RESET                        0x000000ff
+#define CLKMGR_MAINPLL_PLLM_MDIV(x)            ((x) & 0x000003ff)
+#define CLKMGR_MAINPLL_PLLGLOB_PD_SET_MSK      0x00000001
+#define CLKMGR_MAINPLL_PLLGLOB_RST_SET_MSK     0x00000002
+
+#define CLKMGR_MAINPLL_PLLGLOB_REFCLKDIV(x)    (((x) & 0x00003f00) >> 8)
+#define CLKMGR_MAINPLL_PLLGLOB_AREFCLKDIV(x)   (((x) & 0x00000f00) >> 8)
+#define CLKMGR_MAINPLL_PLLGLOB_DREFCLKDIV(x)   (((x) & 0x00003000) >> 12)
+
+#define CLKMGR_MAINPLL_PLLGLOB_PSRC(x)         (((x) & 0x00030000) >> 16)
+#define CLKMGR_MAINPLL_PLLGLOB_PSRC_EOSC1      0x0
+#define CLKMGR_MAINPLL_PLLGLOB_PSRC_INTOSC     0x1
+#define CLKMGR_MAINPLL_PLLGLOB_PSRC_F2S                0x2
+#define CLKMGR_MAINPLL_VCOCALIB_HSCNT_SET(x)   (((x) << 0) & 0x000003ff)
+#define CLKMGR_MAINPLL_VCOCALIB_MSCNT_SET(x)   (((x) << 16) & 0x00ff0000)
+
+/* Peripheral PLL Macros */
+#define CLKMGR_PERPLL_EN_RESET                 0x00000fff
+#define CLKMGR_PERPLL_PLLM_MDIV(x)             ((x) & 0x000003ff)
+#define CLKMGR_PERPLL_GPIODIV_GPIODBCLK_SET(x) (((x) << 0) & 0x0000ffff)
+#define CLKMGR_PERPLL_PLLGLOB_PD_SET_MSK       0x00000001
+
+#define CLKMGR_PERPLL_PLLGLOB_REFCLKDIV(x)     (((x) & 0x00003f00) >> 8)
+#define CLKMGR_PERPLL_PLLGLOB_AREFCLKDIV(x)    (((x) & 0x00000f00) >> 8)
+#define CLKMGR_PERPLL_PLLGLOB_DREFCLKDIV(x)    (((x) & 0x00003000) >> 12)
+
+#define CLKMGR_PERPLL_PLLGLOB_RST_SET_MSK      0x00000002
+#define CLKMGR_PERPLL_VCOCALIB_HSCNT_SET(x)    (((x) << 0) & 0x000003ff)
+#define CLKMGR_PERPLL_VCOCALIB_MSCNT_SET(x)    (((x) << 16) & 0x00ff0000)
+
+/* Altera Macros */
+#define CLKMGR_ALTERA_EXTCNTRST_RESET          0xff
+
+
+typedef struct {
+       uint32_t  clk_freq_of_eosc1;
+       uint32_t  clk_freq_of_f2h_free;
+       uint32_t  clk_freq_of_cb_intosc_ls;
+} CLOCK_SOURCE_CONFIG;
+
+void config_clkmgr_handoff(handoff *hoff_ptr);
+int get_wdt_clk(handoff *hoff_ptr);
+
+#endif
diff --git a/plat/intel/soc/agilex/include/agilex_handoff.h b/plat/intel/soc/agilex/include/agilex_handoff.h
new file mode 100644 (file)
index 0000000..2016406
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef        HANDOFF_H
+#define        HANDOFF_H
+
+#define HANDOFF_MAGIC_HEADER           0x424f4f54      /* BOOT */
+#define HANDOFF_MAGIC_PINMUX_SEL       0x504d5558      /* PMUX */
+#define HANDOFF_MAGIC_IOCTLR           0x494f4354      /* IOCT */
+#define HANDOFF_MAGIC_FPGA             0x46504741      /* FPGA */
+#define HANDOFF_MAGIC_IODELAY          0x444c4159      /* DLAY */
+#define HANDOFF_MAGIC_CLOCK            0x434c4b53      /* CLKS */
+#define HANDOFF_MAGIC_MISC             0x4d495343      /* MISC */
+
+typedef struct handoff_t {
+       /* header */
+       uint32_t        header_magic;
+       uint32_t        header_device;
+       uint32_t        _pad_0x08_0x10[2];
+
+       /* pinmux configuration - select */
+       uint32_t        pinmux_sel_magic;
+       uint32_t        pinmux_sel_length;
+       uint32_t        _pad_0x18_0x20[2];
+       uint32_t        pinmux_sel_array[96];   /* offset, value */
+
+       /* pinmux configuration - io control */
+       uint32_t        pinmux_io_magic;
+       uint32_t        pinmux_io_length;
+       uint32_t        _pad_0x1a8_0x1b0[2];
+       uint32_t        pinmux_io_array[96];    /* offset, value */
+
+       /* pinmux configuration - use fpga switch */
+       uint32_t        pinmux_fpga_magic;
+       uint32_t        pinmux_fpga_length;
+       uint32_t        _pad_0x338_0x340[2];
+       uint32_t        pinmux_fpga_array[42];  /* offset, value */
+       uint32_t        _pad_0x3e8_0x3f0[2];
+
+       /* pinmux configuration - io delay */
+       uint32_t        pinmux_delay_magic;
+       uint32_t        pinmux_delay_length;
+       uint32_t        _pad_0x3f8_0x400[2];
+       uint32_t        pinmux_iodelay_array[96];       /* offset, value */
+
+       /* clock configuration */
+       uint32_t        clock_magic;
+       uint32_t        clock_length;
+       uint32_t        _pad_0x588_0x590[2];
+       uint32_t        main_pll_mpuclk;
+       uint32_t        main_pll_nocclk;
+       uint32_t        main_pll_nocdiv;
+       uint32_t        main_pll_pllglob;
+       uint32_t        main_pll_fdbck;
+       uint32_t        main_pll_pllc0;
+       uint32_t        main_pll_pllc1;
+       uint32_t        main_pll_pllc2;
+       uint32_t        main_pll_pllc3;
+       uint32_t        main_pll_pllm;
+       uint32_t        per_pll_emacctl;
+       uint32_t        per_pll_gpiodiv;
+       uint32_t        per_pll_pllglob;
+       uint32_t        per_pll_fdbck;
+       uint32_t        per_pll_pllc0;
+       uint32_t        per_pll_pllc1;
+       uint32_t        per_pll_pllc2;
+       uint32_t        per_pll_pllc3;
+       uint32_t        per_pll_pllm;
+       uint32_t        alt_emacactr;
+       uint32_t        alt_emacbctr;
+       uint32_t        alt_emacptpctr;
+       uint32_t        alt_gpiodbctr;
+       uint32_t        alt_sdmmcctr;
+       uint32_t        alt_s2fuser0ctr;
+       uint32_t        alt_s2fuser1ctr;
+       uint32_t        alt_psirefctr;
+       uint32_t        hps_osc_clk_h;
+       uint32_t        fpga_clk_hz;
+       uint32_t        _pad_0x604_0x610[3];
+
+       /* misc configuration */
+       uint32_t        misc_magic;
+       uint32_t        misc_length;
+       uint32_t        _pad_0x618_0x620[2];
+       uint32_t        boot_source;
+} handoff;
+
+int verify_handoff_image(handoff *hoff_ptr, handoff *reverse_hoff_ptr);
+int agilex_get_handoff(handoff *hoff_ptr);
+
+#endif
+
+
diff --git a/plat/intel/soc/agilex/include/agilex_mailbox.h b/plat/intel/soc/agilex/include/agilex_mailbox.h
new file mode 100644 (file)
index 0000000..cd8be28
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef AGX_MBOX_H
+#define AGX_MBOX_H
+
+#include <lib/utils_def.h>
+
+#define MBOX_OFFSET                    0xffa30000
+
+#define MBOX_ATF_CLIENT_ID             0x1
+#define MBOX_JOB_ID                    0x1
+
+/* Mailbox interrupt flags and masks */
+#define MBOX_INT_FLAG_COE              0x1
+#define MBOX_INT_FLAG_RIE              0x2
+#define MBOX_INT_FLAG_UAE              0x100
+#define MBOX_COE_BIT(INTERRUPT)                ((INTERRUPT) & 0x3)
+#define MBOX_UAE_BIT(INTERRUPT)                (((INTERRUPT) & (1<<8)))
+
+/* Mailbox response and status */
+#define MBOX_RESP_BUFFER_SIZE          16
+#define MBOX_RESP_ERR(BUFFER)          ((BUFFER) & 0x00000fff)
+#define MBOX_RESP_LEN(BUFFER)          (((BUFFER) & 0x007ff000) >> 12)
+#define MBOX_RESP_CLIENT_ID(BUFFER)    (((BUFFER) & 0xf0000000) >> 28)
+#define MBOX_RESP_JOB_ID(BUFFER)       (((BUFFER) & 0x0f000000) >> 24)
+#define MBOX_STATUS_UA_MASK            (1<<8)
+
+/* Mailbox command and response */
+#define MBOX_CMD_FREE_OFFSET           0x14
+#define MBOX_CMD_BUFFER_SIZE           32
+#define MBOX_CLIENT_ID_CMD(CLIENT_ID)  ((CLIENT_ID) << 28)
+#define MBOX_JOB_ID_CMD(JOB_ID)                (JOB_ID<<24)
+#define MBOX_CMD_LEN_CMD(CMD_LEN)      ((CMD_LEN) << 12)
+#define MBOX_INDIRECT                  (1 << 11)
+#define MBOX_INSUFFICIENT_BUFFER       -2
+#define MBOX_CIN                       0x00
+#define MBOX_ROUT                      0x04
+#define MBOX_URG                       0x08
+#define MBOX_INT                       0x0C
+#define MBOX_COUT                      0x20
+#define MBOX_RIN                       0x24
+#define MBOX_STATUS                    0x2C
+#define MBOX_CMD_BUFFER                        0x40
+#define MBOX_RESP_BUFFER               0xC0
+
+#define MBOX_RESP_BUFFER_SIZE          16
+#define MBOX_RESP_OK                   0
+#define MBOX_RESP_INVALID_CMD          1
+#define MBOX_RESP_UNKNOWN_BR           2
+#define MBOX_RESP_UNKNOWN              3
+#define MBOX_RESP_NOT_CONFIGURED       256
+
+/* Mailbox SDM doorbell */
+#define MBOX_DOORBELL_TO_SDM           0x400
+#define MBOX_DOORBELL_FROM_SDM         0x480
+
+/* Mailbox QSPI commands */
+#define MBOX_CMD_RESTART               2
+#define MBOX_CMD_QSPI_OPEN             50
+#define MBOX_CMD_QSPI_CLOSE            51
+#define MBOX_CMD_QSPI_DIRECT           59
+#define MBOX_CMD_GET_IDCODE            16
+#define MBOX_CMD_QSPI_SET_CS           52
+
+/* Mailbox REBOOT commands */
+#define MBOX_CMD_REBOOT_HPS            71
+
+/* Generic error handling */
+#define MBOX_TIMEOUT                   -2047
+#define MBOX_NO_RESPONSE               -2
+#define MBOX_WRONG_ID                  -3
+
+/* Mailbox status */
+#define RECONFIG_STATUS_STATE          0
+#define RECONFIG_STATUS_PIN_STATUS     2
+#define RECONFIG_STATUS_SOFTFUNC_STATUS 3
+#define PIN_STATUS_NSTATUS             (U(1) << 31)
+#define SOFTFUNC_STATUS_SEU_ERROR      (1 << 3)
+#define SOFTFUNC_STATUS_INIT_DONE      (1 << 1)
+#define SOFTFUNC_STATUS_CONF_DONE      (1 << 0)
+#define MBOX_CFGSTAT_STATE_CONFIG      0x10000000
+
+/* SMC function IDs for SiP Service queries */
+#define SIP_SVC_CALL_COUNT     0x8200ff00
+#define SIP_SVC_UID            0x8200ff01
+#define SIP_SVC_VERSION                0x8200ff03
+
+/* SiP Service Calls version numbers */
+#define SIP_SVC_VERSION_MAJOR  0
+#define SIP_SVC_VERSION_MINOR  1
+
+/* Mailbox reconfiguration commands */
+#define MBOX_RECONFIG          6
+#define MBOX_RECONFIG_DATA     8
+#define MBOX_RECONFIG_STATUS   9
+
+/* Sip get memory */
+#define INTEL_SIP_SMC_FPGA_CONFIG_START                        0xC2000001
+#define INTEL_SIP_SMC_FPGA_CONFIG_GET_MEM              0xC2000005
+#define INTEL_SIP_SMC_FPGA_CONFIG_ISDONE               0xC2000004
+#define INTEL_SIP_SMC_FPGA_CONFIG_WRITE                        0x42000002
+#define INTEL_SIP_SMC_FPGA_CONFIG_COMPLETED_WRITE      0xC2000003
+#define INTEL_SIP_SMC_STATUS_OK                                0
+#define INTEL_SIP_SMC_STATUS_ERROR                     0x4
+#define INTEL_SIP_SMC_STATUS_BUSY                      0x1
+#define INTEL_SIP_SMC_STATUS_REJECTED                  0x2
+#define INTEL_SIP_SMC_FPGA_CONFIG_ADDR                 0x1000
+#define INTEL_SIP_SMC_FPGA_CONFIG_SIZE                 16777216
+
+void mailbox_set_int(int interrupt_input);
+int mailbox_init(void);
+void mailbox_set_qspi_close(void);
+void mailbox_set_qspi_open(void);
+void mailbox_set_qspi_direct(void);
+int mailbox_send_cmd(int job_id, unsigned int cmd, uint32_t *args,
+                               int len, int urgent, uint32_t *response);
+void mailbox_send_cmd_async(int job_id, unsigned int cmd, uint32_t *args,
+                               int len, int urgent);
+int mailbox_read_response(int job_id, uint32_t *response);
+int mailbox_get_qspi_clock(void);
+void mailbox_reset_cold(void);
+
+#endif
diff --git a/plat/intel/soc/agilex/include/agilex_memory_controller.h b/plat/intel/soc/agilex/include/agilex_memory_controller.h
new file mode 100644 (file)
index 0000000..c0c94e6
--- /dev/null
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef AGX_MEMORYCONTROLLER_H
+#define AGX_MEMORYCONTROLLER_H
+
+#define AGX_MPFE_IOHMC_REG_DRAMADDRW                   0xf80100a8
+#define AGX_MPFE_IOHMC_CTRLCFG0                                0xf8010028
+#define AGX_MPFE_IOHMC_CTRLCFG1                                0xf801002c
+#define AGX_MPFE_IOHMC_DRAMADDRW                       0xf80100a8
+#define AGX_MPFE_IOHMC_DRAMTIMING0                     0xf8010050
+#define AGX_MPFE_IOHMC_CALTIMING0                      0xf801007c
+#define AGX_MPFE_IOHMC_CALTIMING1                      0xf8010080
+#define AGX_MPFE_IOHMC_CALTIMING2                      0xf8010084
+#define AGX_MPFE_IOHMC_CALTIMING3                      0xf8010088
+#define AGX_MPFE_IOHMC_CALTIMING4                      0xf801008c
+#define AGX_MPFE_IOHMC_CALTIMING9                      0xf80100a0
+#define AGX_MPFE_IOHMC_CALTIMING9_ACT_TO_ACT(x) (((x) & 0x000000ff) >> 0)
+#define AGX_MPFE_IOHMC_CTRLCFG1_CFG_ADDR_ORDER(value)  \
+                                               (((value) & 0x00000060) >> 5)
+
+#define AGX_RSTMGR_BRGMODRST                           0xffd1102c
+#define AGX_RSTMGR_BRGMODRST_DDRSCH                    0x00000040
+
+#define AGX_MPFE_HMC_ADP_ECCCTRL1                      0xf8011100
+#define AGX_MPFE_HMC_ADP_ECCCTRL2                      0xf8011104
+#define AGX_MPFE_HMC_ADP_RSTHANDSHAKESTAT              0xf8011218
+#define AGX_MPFE_HMC_ADP_RSTHANDSHAKESTAT_SEQ2CORE     0x000000ff
+#define AGX_MPFE_HMC_ADP_RSTHANDSHAKECTRL              0xf8011214
+
+
+#define AGX_MPFE_IOHMC_REG_CTRLCFG1                    0xf801002c
+
+#define AGX_MPFE_IOHMC_REG_NIOSRESERVE0_OFST           0xf8010110
+
+#define IOHMC_DRAMADDRW_COL_ADDR_WIDTH(x)      (((x) & 0x0000001f) >> 0)
+#define IOHMC_DRAMADDRW_ROW_ADDR_WIDTH(x)      (((x) & 0x000003e0) >> 5)
+#define IOHMC_DRAMADDRW_CS_ADDR_WIDTH(x)       (((x) & 0x00070000) >> 16)
+#define IOHMC_DRAMADDRW_BANK_GRP_ADDR_WIDTH(x) (((x) & 0x0000c000) >> 14)
+#define IOHMC_DRAMADDRW_BANK_ADDR_WIDTH(x)     (((x) & 0x00003c00) >> 10)
+
+#define AGX_MPFE_DDR(x)                                        (0xf8000000 + x)
+#define AGX_MPFE_HMC_ADP_DDRCALSTAT                    0xf801100c
+#define AGX_MPFE_DDR_MAIN_SCHED                                0xf8000400
+#define AGX_MPFE_DDR_MAIN_SCHED_DDRCONF                        0xf8000408
+#define AGX_MPFE_DDR_MAIN_SCHED_DDRTIMING              0xf800040c
+#define AGX_MPFE_DDR_MAIN_SCHED_DDRCONF_SET_MSK                0x0000001f
+#define AGX_MPFE_DDR_MAIN_SCHED_DDRMODE                        0xf8000410
+#define AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV               0xf800043c
+#define AGX_MPFE_DDR_MAIN_SCHED_READLATENCY            0xf8000414
+#define AGX_MPFE_DDR_MAIN_SCHED_ACTIVATE               0xf8000438
+#define AGX_MPFE_DDR_MAIN_SCHED_ACTIVATE_FAWBANK_OFST  10
+#define AGX_MPFE_DDR_MAIN_SCHED_ACTIVATE_FAW_OFST      4
+#define AGX_MPFE_DDR_MAIN_SCHED_ACTIVATE_RRD_OFST      0
+#define AGX_MPFE_DDR_MAIN_SCHED_DDRCONF_SET(x) (((x) << 0) & 0x0000001f)
+#define AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV_BUSRDTORD_OFST        0
+#define AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV_BUSRDTORD_MSK (BIT(0) | BIT(1))
+#define AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV_BUSRDTOWR_OFST        2
+#define AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV_BUSRDTOWR_MSK (BIT(2) | BIT(3))
+#define AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV_BUSWRTORD_OFST        4
+#define AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV_BUSWRTORD_MSK (BIT(4) | BIT(5))
+
+#define AGX_MPFE_HMC_ADP(x)                            (0xf8011000 + (x))
+#define AGX_MPFE_HMC_ADP_HPSINTFCSEL                   0xf8011210
+#define AGX_MPFE_HMC_ADP_DDRIOCTRL                     0xf8011008
+#define HMC_ADP_DDRIOCTRL                              0x8
+#define HMC_ADP_DDRIOCTRL_IO_SIZE(x)           (((x) & 0x00000003) >> 0)
+#define HMC_ADP_DDRIOCTRL_CTRL_BURST_LENGTH(x) (((x) & 0x00003e00) >> 9)
+#define ADP_DRAMADDRWIDTH                              0xe0
+
+#define ACT_TO_ACT_DIFF_BANK(value)            (((value) & 0x00fc0000) >> 18)
+#define ACT_TO_ACT(value)                      (((value) & 0x0003f000) >> 12)
+#define ACT_TO_RDWR(value)                     (((value) & 0x0000003f) >> 0)
+#define ACT_TO_ACT(value)                      (((value) & 0x0003f000) >> 12)
+
+/* timing 2 */
+#define RD_TO_RD_DIFF_CHIP(value)              (((value) & 0x00000fc0) >> 6)
+#define RD_TO_WR_DIFF_CHIP(value)              (((value) & 0x3f000000) >> 24)
+#define RD_TO_WR(value)                                (((value) & 0x00fc0000) >> 18)
+#define RD_TO_PCH(value)                       (((value) & 0x00000fc0) >> 6)
+
+/* timing 3 */
+#define CALTIMING3_WR_TO_RD_DIFF_CHIP(value)   (((value) & 0x0003f000) >> 12)
+#define CALTIMING3_WR_TO_RD(value)             (((value) & 0x00000fc0) >> 6)
+
+/* timing 4 */
+#define PCH_TO_VALID(value)                    (((value) & 0x00000fc0) >> 6)
+
+#define DDRTIMING_BWRATIO_OFST                         31
+#define DDRTIMING_WRTORD_OFST                          26
+#define DDRTIMING_RDTOWR_OFST                          21
+#define DDRTIMING_BURSTLEN_OFST                                18
+#define DDRTIMING_WRTOMISS_OFST                                12
+#define DDRTIMING_RDTOMISS_OFST                                6
+#define DDRTIMING_ACTTOACT_OFST                                0
+
+#define ADP_DDRIOCTRL_IO_SIZE(x)                       (((x) & 0x3) >> 0)
+
+#define DDRMODE_AUTOPRECHARGE_OFST                     1
+#define DDRMODE_BWRATIOEXTENDED_OFST                   0
+
+
+#define AGX_MPFE_IOHMC_REG_DRAMTIMING0_CFG_TCL(x)      (((x) & 0x7f) >> 0)
+#define AGX_MPFE_IOHMC_REG_CTRLCFG0_CFG_MEM_TYPE(x)    (((x) & 0x0f) >> 0)
+
+#define AGX_CCU_CPU0_MPRT_DDR                          0xf7004400
+#define AGX_CCU_CPU0_MPRT_MEM0                         0xf70045c0
+#define AGX_CCU_CPU0_MPRT_MEM1A                                0xf70045e0
+#define AGX_CCU_CPU0_MPRT_MEM1B                                0xf7004600
+#define AGX_CCU_CPU0_MPRT_MEM1C                                0xf7004620
+#define AGX_CCU_CPU0_MPRT_MEM1D                                0xf7004640
+#define AGX_CCU_CPU0_MPRT_MEM1E                                0xf7004660
+#define AGX_CCU_IOM_MPRT_MEM0                          0xf7018560
+#define AGX_CCU_IOM_MPRT_MEM1A                         0xf7018580
+#define        AGX_CCU_IOM_MPRT_MEM1B                          0xf70185a0
+#define        AGX_CCU_IOM_MPRT_MEM1C                          0xf70185c0
+#define        AGX_CCU_IOM_MPRT_MEM1D                          0xf70185e0
+#define        AGX_CCU_IOM_MPRT_MEM1E                          0xf7018600
+
+#define AGX_NOC_FW_DDR_SCR                             0xf8020200
+#define AGX_NOC_FW_DDR_SCR_MPUREGION0ADDR_LIMITEXT     0xf802021c
+#define AGX_NOC_FW_DDR_SCR_MPUREGION0ADDR_LIMIT                0xf8020218
+#define AGX_NOC_FW_DDR_SCR_NONMPUREGION0ADDR_LIMITEXT  0xf802029c
+#define AGX_NOC_FW_DDR_SCR_NONMPUREGION0ADDR_LIMIT     0xf8020298
+
+#define AGX_SOC_NOC_FW_DDR_SCR_ENABLE                  0xf8020200
+#define AGX_CCU_NOC_DI_SET_MSK                         0x10
+
+#define AGX_SYSMGR_CORE_HMC_CLK                                0xffd120b4
+#define AGX_SYSMGR_CORE_HMC_CLK_STATUS                 0x00000001
+
+#define AGX_MPFE_IOHMC_NIOSRESERVE0_NIOS_RESERVE0(x)   (((x) & 0xffff) >> 0)
+#define AGX_MPFE_HMC_ADP_DDRIOCTRL_IO_SIZE_MSK         0x00000003
+#define AGX_MPFE_HMC_ADP_DDRIOCTRL_IO_SIZE_OFST                0
+#define AGX_MPFE_HMC_ADP_HPSINTFCSEL_ENABLE            0x001f1f1f
+#define AGX_IOHMC_CTRLCFG1_ENABLE_ECC_OFST             7
+
+#define AGX_MPFE_HMC_ADP_ECCCTRL1_AUTOWB_CNT_RST_SET_MSK       0x00010000
+#define AGX_MPFE_HMC_ADP_ECCCTRL1_CNT_RST_SET_MSK              0x00000100
+#define AGX_MPFE_HMC_ADP_ECCCTRL1_ECC_EN_SET_MSK               0x00000001
+
+#define AGX_MPFE_HMC_ADP_ECCCTRL2_AUTOWB_EN_SET_MSK            0x00000001
+#define AGX_MPFE_HMC_ADP_ECCCTRL2_OVRW_RB_ECC_EN_SET_MSK       0x00010000
+#define AGX_MPFE_HMC_ADP_ECCCTRL2_RMW_EN_SET_MSK               0x00000100
+#define AGX_MPFE_HMC_ADP_DDRCALSTAT_CAL(value)         (((value) & 0x1) >> 0)
+
+
+#define AGX_MPFE_HMC_ADP_DDRIOCTRL_IO_SIZE(x)          (((x) & 0x00003) >> 0)
+#define IOHMC_DRAMADDRW_CFG_BANK_ADDR_WIDTH(x)         (((x) & 0x03c00) >> 10)
+#define IOHMC_DRAMADDRW_CFG_BANK_GROUP_ADDR_WIDTH(x)   (((x) & 0x0c000) >> 14)
+#define IOHMC_DRAMADDRW_CFG_COL_ADDR_WIDTH(x)          (((x) & 0x0001f) >> 0)
+#define IOHMC_DRAMADDRW_CFG_CS_ADDR_WIDTH(x)           (((x) & 0x70000) >> 16)
+#define IOHMC_DRAMADDRW_CFG_ROW_ADDR_WIDTH(x)          (((x) & 0x003e0) >> 5)
+
+#define AGX_SDRAM_0_LB_ADDR                            0x0
+
+int init_hard_memory_controller(void);
+
+#endif
diff --git a/plat/intel/soc/agilex/include/agilex_noc.h b/plat/intel/soc/agilex/include/agilex_noc.h
new file mode 100644 (file)
index 0000000..22db3e2
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef AGX_NOC_H
+#define AGX_NOC_H
+
+
+#define AXI_AP                                 (1<<0)
+#define FPGA2SOC                               (1<<16)
+#define MPU                                    (1<<24)
+#define AGX_NOC_PER_SCR_NAND                   0xffd21000
+#define AGX_NOC_PER_SCR_NAND_DATA              0xffd21004
+#define AGX_NOC_PER_SCR_USB0                   0xffd2100c
+#define AGX_NOC_PER_SCR_USB1                   0xffd21010
+#define AGX_NOC_PER_SCR_SPI_M0                 0xffd2101c
+#define AGX_NOC_PER_SCR_SPI_M1                 0xffd21020
+#define AGX_NOC_PER_SCR_SPI_S0                 0xffd21024
+#define AGX_NOC_PER_SCR_SPI_S1                 0xffd21028
+#define AGX_NOC_PER_SCR_EMAC0                  0xffd2102c
+#define AGX_NOC_PER_SCR_EMAC1                  0xffd21030
+#define AGX_NOC_PER_SCR_EMAC2                  0xffd21034
+#define AGX_NOC_PER_SCR_SDMMC                  0xffd21040
+#define AGX_NOC_PER_SCR_GPIO0                  0xffd21044
+#define AGX_NOC_PER_SCR_GPIO1                  0xffd21048
+#define AGX_NOC_PER_SCR_I2C0                   0xffd21050
+#define AGX_NOC_PER_SCR_I2C1                   0xffd21058
+#define AGX_NOC_PER_SCR_I2C2                   0xffd2105c
+#define AGX_NOC_PER_SCR_I2C3                   0xffd21060
+#define AGX_NOC_PER_SCR_SP_TIMER0              0xffd21064
+#define AGX_NOC_PER_SCR_SP_TIMER1              0xffd21068
+#define AGX_NOC_PER_SCR_UART0                  0xffd2106c
+#define AGX_NOC_PER_SCR_UART1                  0xffd21070
+
+
+#define AGX_NOC_SYS_SCR_DMA_ECC                        0xffd21108
+#define AGX_NOC_SYS_SCR_EMAC0RX_ECC            0xffd2110c
+#define AGX_NOC_SYS_SCR_EMAC0TX_ECC            0xffd21110
+#define AGX_NOC_SYS_SCR_EMAC1RX_ECC            0xffd21114
+#define AGX_NOC_SYS_SCR_EMAC1TX_ECC            0xffd21118
+#define AGX_NOC_SYS_SCR_EMAC2RX_ECC            0xffd2111c
+#define AGX_NOC_SYS_SCR_EMAC2TX_ECC            0xffd21120
+#define AGX_NOC_SYS_SCR_NAND_ECC               0xffd2112c
+#define AGX_NOC_SYS_SCR_NAND_READ_ECC          0xffd21130
+#define AGX_NOC_SYS_SCR_NAND_WRITE_ECC         0xffd21134
+#define AGX_NOC_SYS_SCR_OCRAM_ECC              0xffd21138
+#define AGX_NOC_SYS_SCR_SDMMC_ECC              0xffd21140
+#define AGX_NOC_SYS_SCR_USB0_ECC               0xffd21144
+#define AGX_NOC_SYS_SCR_USB1_ECC               0xffd21148
+#define AGX_NOC_SYS_SCR_CLK_MGR                        0xffd2114c
+#define AGX_NOC_SYS_SCR_IO_MGR                 0xffd21154
+#define AGX_NOC_SYS_SCR_RST_MGR                        0xffd21158
+#define AGX_NOC_SYS_SCR_SYS_MGR                        0xffd2115c
+#define AGX_NOC_SYS_SCR_OSC0_TIMER             0xffd21160
+#define AGX_NOC_SYS_SCR_OSC1_TIMER             0xffd21164
+#define AGX_NOC_SYS_SCR_WATCHDOG0              0xffd21168
+#define AGX_NOC_SYS_SCR_WATCHDOG1              0xffd2116c
+#define AGX_NOC_SYS_SCR_WATCHDOG2              0xffd21170
+#define AGX_NOC_SYS_SCR_WATCHDOG3              0xffd21174
+#define AGX_NOC_SYS_SCR_DAP                    0xffd21178
+#define AGX_NOC_SYS_SCR_L4_NOC_PROBES          0xffd21190
+#define AGX_NOC_SYS_SCR_L4_NOC_QOS             0xffd21194
+
+#define AGX_CCU_NOC_BRIDGE_CPU0_RAM            0xf7004688
+#define AGX_CCU_NOC_BRIDGE_IOM_RAM             0xf7004688
+
+#endif
diff --git a/plat/intel/soc/agilex/include/agilex_pinmux.h b/plat/intel/soc/agilex/include/agilex_pinmux.h
new file mode 100644 (file)
index 0000000..e6a7b34
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef AGX_PINMUX_H
+#define AGX_PINMUX_H
+
+#define AGX_PINMUX_PIN0SEL             0xffd13000
+#define AGX_PINMUX_IO0CTRL             0xffd13130
+#define AGX_PINMUX_PINMUX_EMAC0_USEFPGA        0xffd13300
+#define AGX_PINMUX_IO0_DELAY           0xffd13400
+
+#include "agilex_handoff.h"
+
+void config_pinmux(handoff *handoff);
+
+#endif
+
diff --git a/plat/intel/soc/agilex/include/agilex_private.h b/plat/intel/soc/agilex/include/agilex_private.h
new file mode 100644 (file)
index 0000000..5ccbc8c
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef AGX_PRIVATE_H
+#define AGX_PRIVATE_H
+
+#define AGX_MMC_REG_BASE       0xff808000
+
+#define EMMC_DESC_SIZE         (1<<20)
+#define EMMC_INIT_PARAMS(base)                 \
+       {       .bus_width = MMC_BUS_WIDTH_4,   \
+               .clk_rate = 50000000,           \
+               .desc_base = (base),            \
+               .desc_size = EMMC_DESC_SIZE,    \
+               .flags = 0,                     \
+               .reg_base = AGX_MMC_REG_BASE,   \
+               \
+       }
+
+typedef enum {
+       BOOT_SOURCE_FPGA = 0,
+       BOOT_SOURCE_SDMMC,
+       BOOT_SOURCE_NAND,
+       BOOT_SOURCE_RSVD,
+       BOOT_SOURCE_QSPI,
+} boot_source_type;
+
+void enable_nonsecure_access(void);
+void socfpga_io_setup(int boot_source);
+
+#endif
diff --git a/plat/intel/soc/agilex/include/agilex_reset_manager.h b/plat/intel/soc/agilex/include/agilex_reset_manager.h
new file mode 100644 (file)
index 0000000..a1b6297
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef AGX_RESETMANAGER_H
+#define AGX_RESETMANAGER_H
+
+#define AGX_RSTMGR_HDSKEN                              0xffd11010
+#define AGX_RSTMGR_PER0MODRST                          0xffd11024
+#define AGX_RSTMGR_PER1MODRST                          0xffd11028
+#define AGX_RSTMGR_BRGMODRST                           0xffd1102c
+
+#define AGX_RSTMGR_PER0MODRST_EMAC0                    0x00000001
+#define AGX_RSTMGR_PER0MODRST_EMAC1                    0x00000002
+#define AGX_RSTMGR_PER0MODRST_EMAC2                    0x00000004
+#define AGX_RSTMGR_PER0MODRST_USB0                     0x00000008
+#define AGX_RSTMGR_PER0MODRST_USB1                     0x00000010
+#define AGX_RSTMGR_PER0MODRST_NAND                     0x00000020
+#define AGX_RSTMGR_PER0MODRST_SDMMC                    0x00000080
+#define AGX_RSTMGR_PER0MODRST_EMAC0OCP                 0x00000100
+#define AGX_RSTMGR_PER0MODRST_EMAC1OCP                 0x00000200
+#define AGX_RSTMGR_PER0MODRST_EMAC2OCP                 0x00000400
+#define AGX_RSTMGR_PER0MODRST_USB0OCP                  0x00000800
+#define AGX_RSTMGR_PER0MODRST_USB1OCP                  0x00001000
+#define AGX_RSTMGR_PER0MODRST_NANDOCP                  0x00002000
+#define AGX_RSTMGR_PER0MODRST_SDMMCOCP                 0x00008000
+#define AGX_RSTMGR_PER0MODRST_DMA                      0x00010000
+#define AGX_RSTMGR_PER0MODRST_SPIM0                    0x00020000
+#define AGX_RSTMGR_PER0MODRST_SPIM1                    0x00040000
+#define AGX_RSTMGR_PER0MODRST_SPIS0                    0x00080000
+#define AGX_RSTMGR_PER0MODRST_SPIS1                    0x00100000
+#define AGX_RSTMGR_PER0MODRST_DMAOCP                   0x00200000
+#define AGX_RSTMGR_PER0MODRST_EMACPTP                  0x00400000
+#define AGX_RSTMGR_PER0MODRST_DMAIF0                   0x01000000
+#define AGX_RSTMGR_PER0MODRST_DMAIF1                   0x02000000
+#define AGX_RSTMGR_PER0MODRST_DMAIF2                   0x04000000
+#define AGX_RSTMGR_PER0MODRST_DMAIF3                   0x08000000
+#define AGX_RSTMGR_PER0MODRST_DMAIF4                   0x10000000
+#define AGX_RSTMGR_PER0MODRST_DMAIF5                   0x20000000
+#define AGX_RSTMGR_PER0MODRST_DMAIF6                   0x40000000
+#define AGX_RSTMGR_PER0MODRST_DMAIF7                   0x80000000
+
+#define AGX_RSTMGR_PER1MODRST_WATCHDOG0                        0x1
+#define AGX_RSTMGR_PER1MODRST_WATCHDOG1                        0x2
+#define AGX_RSTMGR_PER1MODRST_WATCHDOG2                        0x4
+#define AGX_RSTMGR_PER1MODRST_WATCHDOG3                        0x8
+#define AGX_RSTMGR_PER1MODRST_L4SYSTIMER0              0x00000010
+#define AGX_RSTMGR_PER1MODRST_L4SYSTIMER1              0x00000020
+#define AGX_RSTMGR_PER1MODRST_SPTIMER0                 0x00000040
+#define AGX_RSTMGR_PER1MODRST_SPTIMER1                 0x00000080
+#define AGX_RSTMGR_PER1MODRST_I2C0                     0x00000100
+#define AGX_RSTMGR_PER1MODRST_I2C1                     0x00000200
+#define AGX_RSTMGR_PER1MODRST_I2C2                     0x00000400
+#define AGX_RSTMGR_PER1MODRST_I2C3                     0x00000800
+#define AGX_RSTMGR_PER1MODRST_I2C4                     0x00001000
+#define AGX_RSTMGR_PER1MODRST_UART0                    0x00010000
+#define AGX_RSTMGR_PER1MODRST_UART1                    0x00020000
+#define AGX_RSTMGR_PER1MODRST_GPIO0                    0x01000000
+#define AGX_RSTMGR_PER1MODRST_GPIO1                    0x02000000
+
+#define AGX_RSTMGR_HDSKEN_FPGAHSEN                     0x00000004
+#define AGX_RSTMGR_HDSKEN_ETRSTALLEN                   0x00000008
+#define AGX_RSTMGR_HDSKEN_L2FLUSHEN                    0x00000100
+#define AGX_RSTMGR_HDSKEN_L3NOC_DBG                    0x00010000
+#define AGX_RSTMGR_HDSKEN_DEBUG_L3NOC                  0x00020000
+#define AGX_RSTMGR_HDSKEN_SDRSELFREFEN                 0x00000001
+
+#define AGX_RSTMGR_BRGMODRST_SOC2FPGA                  0x1
+#define AGX_RSTMGR_BRGMODRST_LWHPS2FPGA                        0x2
+#define AGX_RSTMGR_BRGMODRST_FPGA2SOC                  0x4
+#define AGX_RSTMGR_BRGMODRST_MPFE                      0x40
+
+void deassert_peripheral_reset(void);
+void config_hps_hs_before_warm_reset(void);
+
+#endif
+
diff --git a/plat/intel/soc/agilex/include/agilex_system_manager.h b/plat/intel/soc/agilex/include/agilex_system_manager.h
new file mode 100644 (file)
index 0000000..6ec2084
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef AGX_SYSTEMMANAGER_H
+#define AGX_SYSTEMMANAGER_H
+
+#define AGX_FIREWALL_SOC2FPGA                  0xffd21200
+#define AGX_FIREWALL_LWSOC2FPGA                        0xffd21300
+
+#define AGX_NOC_FW_L4_PER_SCR_NAND_REGISTER    0xffd21000
+#define AGX_NOC_FW_L4_PER_SCR_NAND_DATA                0xffd21004
+#define AGX_NOC_FW_L4_PER_SCR_USB0_REGISTER    0xffd2100c
+#define AGX_NOC_FW_L4_PER_SCR_USB1_REGISTER    0xffd21010
+#define AGX_NOC_FW_L4_PER_SCR_SPI_MASTER0      0xffd2101c
+#define AGX_NOC_FW_L4_PER_SCR_SPI_MASTER1      0xffd21020
+#define AGX_NOC_FW_L4_PER_SCR_SPI_SLAVE0       0xffd21024
+#define AGX_NOC_FW_L4_PER_SCR_SPI_SLAVE1       0xffd21028
+#define AGX_NOC_FW_L4_PER_SCR_EMAC0            0xffd2102c
+#define AGX_NOC_FW_L4_PER_SCR_EMAC1            0xffd21030
+#define AGX_NOC_FW_L4_PER_SCR_EMAC2            0xffd21034
+#define AGX_NOC_FW_L4_PER_SCR_SDMMC            0xffd21040
+#define AGX_NOC_FW_L4_PER_SCR_GPIO0            0xffd21044
+#define AGX_NOC_FW_L4_PER_SCR_GPIO1            0xffd21048
+#define AGX_NOC_FW_L4_PER_SCR_I2C0             0xffd21050
+#define AGX_NOC_FW_L4_PER_SCR_I2C1             0xffd21054
+#define AGX_NOC_FW_L4_PER_SCR_I2C2             0xffd21058
+#define AGX_NOC_FW_L4_PER_SCR_I2C3             0xffd2105c
+#define AGX_NOC_FW_L4_PER_SCR_I2C4             0xffd21060
+#define AGX_NOC_FW_L4_PER_SCR_SP_TIMER0                0xffd21064
+#define AGX_NOC_FW_L4_PER_SCR_SP_TIMER1                0xffd21068
+#define AGX_NOC_FW_L4_PER_SCR_UART0            0xffd2106c
+#define AGX_NOC_FW_L4_PER_SCR_UART1            0xffd21070
+
+#define AGX_NOC_FW_L4_SYS_SCR_DMA_ECC          0xffd21108
+#define AGX_NOC_FW_L4_SYS_SCR_EMAC0RX_ECC      0xffd2110c
+#define AGX_NOC_FW_L4_SYS_SCR_EMAC0TX_ECC      0xffd21110
+#define AGX_NOC_FW_L4_SYS_SCR_EMAC1RX_ECC      0xffd21114
+#define AGX_NOC_FW_L4_SYS_SCR_EMAC1TX_ECC      0xffd21118
+#define AGX_NOC_FW_L4_SYS_SCR_EMAC2RX_ECC      0xffd2111c
+#define AGX_NOC_FW_L4_SYS_SCR_EMAC2TX_ECC      0xffd21120
+#define AGX_NOC_FW_L4_SYS_SCR_NAND_ECC         0xffd2112c
+#define AGX_NOC_FW_L4_SYS_SCR_NAND_READ_ECC    0xffd21130
+#define AGX_NOC_FW_L4_SYS_SCR_NAND_WRITE_ECC   0xffd21134
+#define AGX_NOC_FW_L4_SYS_SCR_OCRAM_ECC                0xffd21138
+#define AGX_NOC_FW_L4_SYS_SCR_SDMMC_ECC                0xffd21140
+#define AGX_NOC_FW_L4_SYS_SCR_USB0_ECC         0xffd21144
+#define AGX_NOC_FW_L4_SYS_SCR_USB1_ECC         0xffd21148
+#define AGX_NOC_FW_L4_SYS_SCR_CLK_MGR          0xffd2114c
+#define AGX_NOC_FW_L4_SYS_SCR_IO_MGR           0xffd21154
+#define AGX_NOC_FW_L4_SYS_SCR_RST_MGR          0xffd21158
+#define AGX_NOC_FW_L4_SYS_SCR_SYS_MGR          0xffd2115c
+#define AGX_NOC_FW_L4_SYS_SCR_OSC0_TIMER       0xffd21160
+#define AGX_NOC_FW_L4_SYS_SCR_OSC1_TIMER       0xffd21164
+#define AGX_NOC_FW_L4_SYS_SCR_WATCHDOG0                0xffd21168
+#define AGX_NOC_FW_L4_SYS_SCR_WATCHDOG1                0xffd2116c
+#define AGX_NOC_FW_L4_SYS_SCR_WATCHDOG2                0xffd21170
+#define AGX_NOC_FW_L4_SYS_SCR_WATCHDOG3                0xffd21174
+#define AGX_NOC_FW_L4_SYS_SCR_DAP              0xffd21178
+#define AGX_NOC_FW_L4_SYS_SCR_L4_NOC_PROBES    0xffd21190
+#define AGX_NOC_FW_L4_SYS_SCR_L4_NOC_QOS       0xffd21194
+
+#define AGX_CCU_NOC_CPU0_RAMSPACE0_0           0xf7004688
+#define AGX_CCU_NOC_IOM_RAMSPACE0_0            0xf7018628
+
+#define DISABLE_BRIDGE_FIREWALL                        0x0ffe0101
+#define DISABLE_L4_FIREWALL    (BIT(0) | BIT(16) | BIT(24))
+
+void enable_nonsecure_access(void);
+void enable_ns_bridge_access(void);
+
+#endif
diff --git a/plat/intel/soc/agilex/include/plat_macros.S b/plat/intel/soc/agilex/include/plat_macros.S
new file mode 100644 (file)
index 0000000..43db9a2
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PLAT_MACROS_S
+#define PLAT_MACROS_S
+
+#include <platform_def.h>
+
+       /* ---------------------------------------------
+        * The below required platform porting macro
+        * prints out relevant platform registers
+        * whenever an unhandled exception is taken in
+        * BL31.
+        * ---------------------------------------------
+        */
+       .macro plat_crash_print_regs
+       .endm
+
+#endif /* PLAT_MACROS_S */
diff --git a/plat/intel/soc/agilex/include/platform_def.h b/plat/intel/soc/agilex/include/platform_def.h
new file mode 100644 (file)
index 0000000..10f7338
--- /dev/null
@@ -0,0 +1,196 @@
+/*
+ * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PLATFORM_DEF_H
+#define PLATFORM_DEF_H
+
+#include <arch.h>
+#include <common/interrupt_props.h>
+#include <common/tbbr/tbbr_img_def.h>
+#include <plat/common/common_def.h>
+
+
+#define PLAT_CPUID_RELEASE                     0xffe1b000
+#define PLAT_AGX_SEC_ENTRY                     0xffe1b008
+
+/* Define next boot image name and offset */
+#define PLAT_NS_IMAGE_OFFSET                   0x50000
+#define PLAT_HANDOFF_OFFSET                    0xFFE3F000
+
+/*******************************************************************************
+ * Platform binary types for linking
+ ******************************************************************************/
+#define PLATFORM_LINKER_FORMAT                 "elf64-littleaarch64"
+#define PLATFORM_LINKER_ARCH                   aarch64
+
+/* Agilex supports up to 124GB RAM */
+#define PLAT_PHY_ADDR_SPACE_SIZE               (1ULL << 39)
+#define PLAT_VIRT_ADDR_SPACE_SIZE              (1ULL << 39)
+
+
+/*******************************************************************************
+ * Generic platform constants
+ ******************************************************************************/
+#define PLAT_PRIMARY_CPU                       0
+#define PLAT_SECONDARY_ENTRY_BASE              0x01f78bf0
+
+/* Size of cacheable stacks */
+#define PLATFORM_STACK_SIZE                    0x2000
+
+/* PSCI related constant */
+#define PLAT_NUM_POWER_DOMAINS                 5
+#define PLAT_MAX_PWR_LVL                       1
+#define PLAT_MAX_RET_STATE                     1
+#define PLAT_MAX_OFF_STATE                     2
+#define PLATFORM_SYSTEM_COUNT                  1
+#define PLATFORM_CLUSTER_COUNT                 1
+#define PLATFORM_CLUSTER0_CORE_COUNT           4
+#define PLATFORM_CLUSTER1_CORE_COUNT           0
+#define PLATFORM_CORE_COUNT            (PLATFORM_CLUSTER1_CORE_COUNT + \
+                                       PLATFORM_CLUSTER0_CORE_COUNT)
+#define PLATFORM_MAX_CPUS_PER_CLUSTER          4
+
+/* Interrupt related constant */
+
+#define INTEL_AGX_IRQ_SEC_PHY_TIMER            29
+
+#define INTEL_AGX_IRQ_SEC_SGI_0                        8
+#define INTEL_AGX_IRQ_SEC_SGI_1                        9
+#define INTEL_AGX_IRQ_SEC_SGI_2                        10
+#define INTEL_AGX_IRQ_SEC_SGI_3                        11
+#define INTEL_AGX_IRQ_SEC_SGI_4                        12
+#define INTEL_AGX_IRQ_SEC_SGI_5                        13
+#define INTEL_AGX_IRQ_SEC_SGI_6                        14
+#define INTEL_AGX_IRQ_SEC_SGI_7                        15
+
+#define TSP_IRQ_SEC_PHY_TIMER          INTEL_AGX_IRQ_SEC_PHY_TIMER
+#define TSP_SEC_MEM_BASE               BL32_BASE
+#define TSP_SEC_MEM_SIZE               (BL32_LIMIT - BL32_BASE + 1)
+/*******************************************************************************
+ * Platform memory map related constants
+ ******************************************************************************/
+#define DRAM_BASE                              (0x0)
+#define DRAM_SIZE                              (0x80000000)
+
+#define OCRAM_BASE                             (0xFFE00000)
+#define OCRAM_SIZE                             (0x00040000)
+
+#define MEM64_BASE                             (0x0100000000)
+#define MEM64_SIZE                             (0x1F00000000)
+
+#define DEVICE1_BASE                           (0x80000000)
+#define DEVICE1_SIZE                           (0x60000000)
+
+#define DEVICE2_BASE                           (0xF7000000)
+#define DEVICE2_SIZE                           (0x08E00000)
+
+#define DEVICE3_BASE                           (0xFFFC0000)
+#define DEVICE3_SIZE                           (0x00008000)
+
+#define DEVICE4_BASE                           (0x2000000000)
+#define DEVICE4_SIZE                           (0x0100000000)
+
+/*******************************************************************************
+ * BL31 specific defines.
+ ******************************************************************************/
+/*
+ * Put BL3-1 at the top of the Trusted SRAM (just below the shared memory, if
+ * present). BL31_BASE is calculated using the current BL3-1 debug size plus a
+ * little space for growth.
+ */
+
+
+#define FIRMWARE_WELCOME_STR           "Booting Trusted Firmware\n"
+
+#define BL1_RO_BASE    (0xffe00000)
+#define BL1_RO_LIMIT   (0xffe0f000)
+#define BL1_RW_BASE    (0xffe10000)
+#define BL1_RW_LIMIT   (0xffe1ffff)
+#define BL1_RW_SIZE    (0x14000)
+
+#define BL2_BASE       (0xffe00000)
+#define BL2_LIMIT      (0xffe1b000)
+
+#define BL31_BASE      (0xffe1c000)
+#define BL31_LIMIT     (0xffe3bfff)
+
+/*******************************************************************************
+ * Platform specific page table and MMU setup constants
+ ******************************************************************************/
+#define MAX_XLAT_TABLES                        8
+#define MAX_MMAP_REGIONS               16
+
+/*******************************************************************************
+ * Declarations and constants to access the mailboxes safely. Each mailbox is
+ * aligned on the biggest cache line size in the platform. This is known only
+ * to the platform as it might have a combination of integrated and external
+ * caches. Such alignment ensures that two maiboxes do not sit on the same cache
+ * line at any cache level. They could belong to different cpus/clusters &
+ * get written while being protected by different locks causing corruption of
+ * a valid mailbox address.
+ ******************************************************************************/
+#define CACHE_WRITEBACK_SHIFT                  6
+#define CACHE_WRITEBACK_GRANULE                (1 << CACHE_WRITEBACK_SHIFT)
+
+#define PLAT_GIC_BASE                  (0xFFFC0000)
+#define PLAT_GICC_BASE                 (PLAT_GIC_BASE + 0x2000)
+#define PLAT_GICD_BASE                 (PLAT_GIC_BASE + 0x1000)
+#define PLAT_GICR_BASE                 0
+
+/*******************************************************************************
+ * UART related constants
+ ******************************************************************************/
+#define PLAT_UART0_BASE                (0xFFC02000)
+#define PLAT_UART1_BASE                (0xFFC02100)
+
+#define CRASH_CONSOLE_BASE     PLAT_UART0_BASE
+
+#define PLAT_BAUDRATE          (115200)
+#define PLAT_UART_CLOCK                (100000000)
+
+/*******************************************************************************
+ * System counter frequency related constants
+ ******************************************************************************/
+#define PLAT_SYS_COUNTER_FREQ_IN_TICKS (400000000)
+#define PLAT_SYS_COUNTER_FREQ_IN_MHZ   (400)
+
+#define PLAT_INTEL_AGX_GICD_BASE       PLAT_GICD_BASE
+#define PLAT_INTEL_AGX_GICC_BASE       PLAT_GICC_BASE
+
+/*
+ * Define a list of Group 1 Secure and Group 0 interrupts as per GICv3
+ * terminology. On a GICv2 system or mode, the lists will be merged and treated
+ * as Group 0 interrupts.
+ */
+#define PLAT_INTEL_AGX_G1S_IRQ_PROPS(grp) \
+       INTR_PROP_DESC(INTEL_AGX_IRQ_SEC_PHY_TIMER, GIC_HIGHEST_SEC_PRIORITY, \
+                       grp, GIC_INTR_CFG_LEVEL), \
+       INTR_PROP_DESC(INTEL_AGX_IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY, grp, \
+                       GIC_INTR_CFG_EDGE), \
+       INTR_PROP_DESC(INTEL_AGX_IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY, grp, \
+                       GIC_INTR_CFG_EDGE), \
+       INTR_PROP_DESC(INTEL_AGX_IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY, grp, \
+                       GIC_INTR_CFG_EDGE), \
+       INTR_PROP_DESC(INTEL_AGX_IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY, grp, \
+                       GIC_INTR_CFG_EDGE), \
+       INTR_PROP_DESC(INTEL_AGX_IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY, grp, \
+                       GIC_INTR_CFG_EDGE), \
+       INTR_PROP_DESC(INTEL_AGX_IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY, grp, \
+                       GIC_INTR_CFG_EDGE), \
+       INTR_PROP_DESC(INTEL_AGX_IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY, grp, \
+                       GIC_INTR_CFG_EDGE), \
+       INTR_PROP_DESC(INTEL_AGX_IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY, grp, \
+                       GIC_INTR_CFG_EDGE)
+
+#define PLAT_INTEL_AGX_G0_IRQ_PROPS(grp)
+
+#define MAX_IO_HANDLES                 4
+#define MAX_IO_DEVICES                 4
+#define MAX_IO_BLOCK_DEVICES           2
+
+#endif /* PLATFORM_DEF_H */
+
diff --git a/plat/intel/soc/agilex/include/socfpga_private.h b/plat/intel/soc/agilex/include/socfpga_private.h
new file mode 100644 (file)
index 0000000..6ab1409
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PLATFORM_PRIVATE_H
+#define PLATFORM_PRIVATE_H
+
+/*******************************************************************************
+ * Function and variable prototypes
+ ******************************************************************************/
+void socfgpa_configure_mmu_el3(unsigned long total_base,
+                       unsigned long total_size,
+                       unsigned long ro_start,
+                       unsigned long ro_limit,
+                       unsigned long coh_start,
+                       unsigned long coh_limit);
+
+
+void socfpga_configure_mmu_el1(unsigned long total_base,
+                       unsigned long total_size,
+                       unsigned long ro_start,
+                       unsigned long ro_limit,
+                       unsigned long coh_start,
+                       unsigned long coh_limit);
+
+void socfpga_delay_timer_init(void);
+
+void socfpga_gic_driver_init(void);
+
+uint32_t socfpga_get_spsr_for_bl32_entry(void);
+
+uint32_t socfpga_get_spsr_for_bl33_entry(void);
+
+unsigned long socfpga_get_ns_image_entrypoint(void);
+
+
+#endif /* PLATFORM_PRIVATE_H */
diff --git a/plat/intel/soc/agilex/platform.mk b/plat/intel/soc/agilex/platform.mk
new file mode 100644 (file)
index 0000000..22ff160
--- /dev/null
@@ -0,0 +1,73 @@
+#
+# Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
+# Copyright (c) 2019, Intel Corporation. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#
+PLAT_INCLUDES          :=      \
+                       -Iplat/intel/soc/agilex/include/                \
+                       -Iplat/intel/soc/common/drivers/
+
+PLAT_BL_COMMON_SOURCES :=      \
+                       drivers/arm/gic/common/gic_common.c             \
+                       drivers/arm/gic/v2/gicv2_main.c                 \
+                       drivers/arm/gic/v2/gicv2_helpers.c              \
+                       drivers/delay_timer/delay_timer.c               \
+                       drivers/delay_timer/generic_delay_timer.c       \
+                       drivers/ti/uart/aarch64/16550_console.S         \
+                       lib/xlat_tables/aarch64/xlat_tables.c           \
+                       lib/xlat_tables/xlat_tables_common.c            \
+                       plat/common/plat_gicv2.c                        \
+                       plat/intel/soc/agilex/aarch64/platform_common.c \
+                       plat/intel/soc/agilex/aarch64/plat_helpers.S    \
+
+BL2_SOURCES     +=     \
+               common/desc_image_load.c                                \
+               drivers/partition/partition.c                           \
+               drivers/partition/gpt.c                                 \
+               drivers/arm/pl061/pl061_gpio.c                          \
+               drivers/mmc/mmc.c                                       \
+               drivers/synopsys/emmc/dw_mmc.c                          \
+               drivers/io/io_storage.c                                 \
+               drivers/io/io_block.c                                   \
+               drivers/io/io_fip.c                                     \
+               drivers/gpio/gpio.c                                     \
+               drivers/intel/soc/stratix10/io/s10_memmap_qspi.c        \
+               lib/cpus/aarch64/cortex_a53.S                           \
+               plat/intel/soc/agilex/bl2_plat_setup.c                  \
+               plat/intel/soc/agilex/socfpga_storage.c                 \
+                plat/intel/soc/agilex/bl2_plat_mem_params_desc.c       \
+               plat/intel/soc/agilex/soc/agilex_reset_manager.c        \
+               plat/intel/soc/agilex/soc/agilex_handoff.c              \
+               plat/intel/soc/agilex/soc/agilex_clock_manager.c        \
+               plat/intel/soc/agilex/soc/agilex_pinmux.c               \
+               plat/intel/soc/agilex/soc/agilex_memory_controller.c    \
+               plat/intel/soc/agilex/socfpga_delay_timer.c             \
+               plat/intel/soc/agilex/socfpga_image_load.c              \
+               plat/intel/soc/agilex/soc/agilex_system_manager.c       \
+               plat/intel/soc/agilex/soc/agilex_mailbox.c              \
+               plat/intel/soc/common/drivers/qspi/cadence_qspi.c       \
+               plat/intel/soc/common/drivers/wdt/watchdog.c            \
+               plat/intel/soc/common/drivers/ccu/ncore_ccu.c
+
+BL31_SOURCES   +=      \
+               drivers/arm/cci/cci.c                                   \
+               lib/cpus/aarch64/cortex_a53.S                           \
+               lib/cpus/aarch64/aem_generic.S                          \
+               plat/common/plat_psci_common.c                          \
+               plat/intel/soc/agilex/socfpga_sip_svc.c                 \
+               plat/intel/soc/agilex/bl31_plat_setup.c                 \
+               plat/intel/soc/agilex/socfpga_psci.c                    \
+               plat/intel/soc/agilex/socfpga_topology.c                \
+               plat/intel/soc/agilex/socfpga_delay_timer.c             \
+               plat/intel/soc/agilex/soc/agilex_reset_manager.c        \
+               plat/intel/soc/agilex/soc/agilex_pinmux.c               \
+               plat/intel/soc/agilex/soc/agilex_clock_manager.c        \
+               plat/intel/soc/agilex/soc/agilex_handoff.c              \
+               plat/intel/soc/agilex/soc/agilex_mailbox.c
+
+PROGRAMMABLE_RESET_ADDRESS     := 0
+BL2_AT_EL3                     := 1
+MULTI_CONSOLE_API              := 1
+USE_COHERENT_MEM               := 1
diff --git a/plat/intel/soc/agilex/soc/agilex_clock_manager.c b/plat/intel/soc/agilex/soc/agilex_clock_manager.c
new file mode 100644 (file)
index 0000000..6e7b43e
--- /dev/null
@@ -0,0 +1,293 @@
+/*
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <assert.h>
+#include <common/debug.h>
+#include <drivers/delay_timer.h>
+#include <errno.h>
+#include <lib/mmio.h>
+
+#include "agilex_clock_manager.h"
+#include "agilex_handoff.h"
+
+static const CLOCK_SOURCE_CONFIG  clk_source = {
+       /* clk_freq_of_eosc1 */
+       (uint32_t) 25000000,
+       /* clk_freq_of_f2h_free */
+       (uint32_t) 400000000,
+       /* clk_freq_of_cb_intosc_ls */
+       (uint32_t) 50000000,
+};
+
+uint32_t wait_pll_lock(void)
+{
+       uint32_t data;
+       uint32_t count = 0;
+
+       do {
+               data = mmio_read_32(CLKMGR_OFFSET + CLKMGR_STAT);
+               count++;
+               if (count >= 1000)
+                       return -ETIMEDOUT;
+
+       } while ((CLKMGR_STAT_MAINPLLLOCKED(data) == 0) ||
+                       (CLKMGR_STAT_PERPLLLOCKED(data) == 0));
+       return 0;
+}
+
+uint32_t wait_fsm(void)
+{
+       uint32_t data;
+       uint32_t count = 0;
+
+       do {
+               data = mmio_read_32(CLKMGR_OFFSET + CLKMGR_STAT);
+               count++;
+               if (count >= 1000)
+                       return -ETIMEDOUT;
+
+       } while (CLKMGR_STAT_BUSY(data) == CLKMGR_STAT_BUSY_E_BUSY);
+
+       return 0;
+}
+
+uint32_t pll_source_sync_config(uint32_t pll_mem_offset)
+{
+       uint32_t val = 0;
+       uint32_t count = 0;
+       uint32_t req_status = 0;
+
+       val = (CLKMGR_MEM_WR | CLKMGR_MEM_REQ |
+               CLKMGR_MEM_WDAT << CLKMGR_MEM_WDAT_OFFSET | CLKMGR_MEM_ADDR);
+       mmio_write_32(pll_mem_offset, val);
+
+       do {
+               req_status = mmio_read_32(pll_mem_offset);
+               count++;
+       } while ((req_status & CLKMGR_MEM_REQ) && (count < 10));
+
+       if (count >= 100)
+               return -ETIMEDOUT;
+
+       return 0;
+}
+
+uint32_t pll_source_sync_read(uint32_t pll_mem_offset)
+{
+       uint32_t val = 0;
+       uint32_t rdata = 0;
+       uint32_t count = 0;
+       uint32_t req_status = 0;
+
+       val = (CLKMGR_MEM_REQ | CLKMGR_MEM_ADDR);
+       mmio_write_32(pll_mem_offset, val);
+
+       do {
+               req_status = mmio_read_32(pll_mem_offset);
+               count++;
+       } while ((req_status & CLKMGR_MEM_REQ) && (count < 10));
+
+       if (count >= 100)
+               return -ETIMEDOUT;
+
+       rdata = mmio_read_32(pll_mem_offset + 0x4);
+       INFO("rdata (%x) = %x\n", pll_mem_offset + 0x4, rdata);
+
+       return 0;
+}
+
+void config_clkmgr_handoff(handoff *hoff_ptr)
+{
+       uint32_t mdiv, mscnt, hscnt;
+       uint32_t arefclk_div, drefclk_div;
+
+       /* Bypass all mainpllgrp's clocks */
+       mmio_write_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_BYPASS, 0x7);
+       wait_fsm();
+
+       /* Bypass all perpllgrp's clocks */
+       mmio_write_32(CLKMGR_PERPLL + CLKMGR_PERPLL_BYPASS, 0x7f);
+       wait_fsm();
+
+       /* Put both PLL in reset and power down */
+       mmio_clrbits_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_PLLGLOB,
+                       CLKMGR_MAINPLL_PLLGLOB_PD_SET_MSK |
+                       CLKMGR_MAINPLL_PLLGLOB_RST_SET_MSK);
+       mmio_clrbits_32(CLKMGR_PERPLL + CLKMGR_PERPLL_PLLGLOB,
+                       CLKMGR_PERPLL_PLLGLOB_PD_SET_MSK |
+                       CLKMGR_PERPLL_PLLGLOB_RST_SET_MSK);
+
+       /* Setup main PLL dividers */
+       mdiv = CLKMGR_MAINPLL_PLLM_MDIV(hoff_ptr->main_pll_pllm);
+
+       arefclk_div = CLKMGR_MAINPLL_PLLGLOB_AREFCLKDIV(
+                       hoff_ptr->main_pll_pllglob);
+       drefclk_div = CLKMGR_MAINPLL_PLLGLOB_DREFCLKDIV(
+                       hoff_ptr->main_pll_pllglob);
+
+       mscnt = 100 / (mdiv / BIT(drefclk_div));
+       if (!mscnt)
+               mscnt = 1;
+       hscnt = (mdiv * mscnt * BIT(drefclk_div) / arefclk_div) - 4;
+
+       mmio_write_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_VCOCALIB,
+                       CLKMGR_MAINPLL_VCOCALIB_HSCNT_SET(hscnt) |
+                       CLKMGR_MAINPLL_VCOCALIB_MSCNT_SET(mscnt));
+
+       mmio_write_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_NOCDIV,
+                       hoff_ptr->main_pll_nocdiv);
+       mmio_write_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_PLLGLOB,
+                       hoff_ptr->main_pll_pllglob);
+       mmio_write_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_FDBCK,
+                       hoff_ptr->main_pll_fdbck);
+       mmio_write_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_PLLC0,
+                       hoff_ptr->main_pll_pllc0);
+       mmio_write_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_PLLC1,
+                       hoff_ptr->main_pll_pllc1);
+       mmio_write_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_PLLC2,
+                       hoff_ptr->main_pll_pllc2);
+       mmio_write_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_PLLC3,
+                       hoff_ptr->main_pll_pllc3);
+       mmio_write_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_PLLM,
+                       hoff_ptr->main_pll_pllm);
+       mmio_write_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_MPUCLK,
+                       hoff_ptr->main_pll_mpuclk);
+       mmio_write_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_NOCCLK,
+                       hoff_ptr->main_pll_nocclk);
+
+       /* Setup peripheral PLL dividers */
+       mdiv = CLKMGR_PERPLL_PLLM_MDIV(hoff_ptr->per_pll_pllm);
+
+       arefclk_div = CLKMGR_PERPLL_PLLGLOB_AREFCLKDIV(
+                       hoff_ptr->per_pll_pllglob);
+       drefclk_div = CLKMGR_PERPLL_PLLGLOB_DREFCLKDIV(
+                       hoff_ptr->per_pll_pllglob);
+
+       mscnt = 100 / (mdiv / BIT(drefclk_div));
+       if (!mscnt)
+               mscnt = 1;
+       hscnt = (mdiv * mscnt * BIT(drefclk_div) / arefclk_div) - 4;
+
+       mmio_write_32(CLKMGR_PERPLL + CLKMGR_PERPLL_VCOCALIB,
+                       CLKMGR_PERPLL_VCOCALIB_HSCNT_SET(hscnt) |
+                       CLKMGR_PERPLL_VCOCALIB_MSCNT_SET(mscnt));
+
+       mmio_write_32(CLKMGR_PERPLL + CLKMGR_PERPLL_EMACCTL,
+                       hoff_ptr->per_pll_emacctl);
+       mmio_write_32(CLKMGR_PERPLL + CLKMGR_PERPLL_GPIODIV,
+                       CLKMGR_PERPLL_GPIODIV_GPIODBCLK_SET(
+                       hoff_ptr->per_pll_gpiodiv));
+       mmio_write_32(CLKMGR_PERPLL + CLKMGR_PERPLL_PLLGLOB,
+                       hoff_ptr->per_pll_pllglob);
+       mmio_write_32(CLKMGR_PERPLL + CLKMGR_PERPLL_FDBCK,
+                       hoff_ptr->per_pll_fdbck);
+       mmio_write_32(CLKMGR_PERPLL + CLKMGR_PERPLL_PLLC0,
+                       hoff_ptr->per_pll_pllc0);
+       mmio_write_32(CLKMGR_PERPLL + CLKMGR_PERPLL_PLLC1,
+                       hoff_ptr->per_pll_pllc1);
+       mmio_write_32(CLKMGR_PERPLL + CLKMGR_PERPLL_PLLC2,
+                       hoff_ptr->per_pll_pllc2);
+       mmio_write_32(CLKMGR_PERPLL + CLKMGR_PERPLL_PLLC3,
+                       hoff_ptr->per_pll_pllc3);
+       mmio_write_32(CLKMGR_PERPLL + CLKMGR_PERPLL_PLLM,
+                       hoff_ptr->per_pll_pllm);
+
+       /* Take both PLL out of reset and power up */
+       mmio_setbits_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_PLLGLOB,
+                       CLKMGR_MAINPLL_PLLGLOB_PD_SET_MSK |
+                       CLKMGR_MAINPLL_PLLGLOB_RST_SET_MSK);
+       mmio_setbits_32(CLKMGR_PERPLL + CLKMGR_PERPLL_PLLGLOB,
+                       CLKMGR_PERPLL_PLLGLOB_PD_SET_MSK |
+                       CLKMGR_PERPLL_PLLGLOB_RST_SET_MSK);
+
+       wait_pll_lock();
+
+       pll_source_sync_config(CLKMGR_MAINPLL + CLKMGR_MAINPLL_MEM);
+       pll_source_sync_read(CLKMGR_MAINPLL + CLKMGR_MAINPLL_MEM);
+
+       pll_source_sync_config(CLKMGR_PERPLL + CLKMGR_PERPLL_MEM);
+       pll_source_sync_read(CLKMGR_PERPLL + CLKMGR_PERPLL_MEM);
+
+       /*Configure Ping Pong counters in altera group */
+       mmio_write_32(CLKMGR_ALTERA + CLKMGR_ALTERA_EMACACTR,
+                       hoff_ptr->alt_emacactr);
+       mmio_write_32(CLKMGR_ALTERA + CLKMGR_ALTERA_EMACBCTR,
+                       hoff_ptr->alt_emacbctr);
+       mmio_write_32(CLKMGR_ALTERA + CLKMGR_ALTERA_EMACPTPCTR,
+                       hoff_ptr->alt_emacptpctr);
+       mmio_write_32(CLKMGR_ALTERA + CLKMGR_ALTERA_GPIODBCTR,
+                       hoff_ptr->alt_gpiodbctr);
+       mmio_write_32(CLKMGR_ALTERA + CLKMGR_ALTERA_SDMMCCTR,
+                       hoff_ptr->alt_sdmmcctr);
+       mmio_write_32(CLKMGR_ALTERA + CLKMGR_ALTERA_S2FUSER0CTR,
+                       hoff_ptr->alt_s2fuser0ctr);
+       mmio_write_32(CLKMGR_ALTERA + CLKMGR_ALTERA_S2FUSER1CTR,
+                       hoff_ptr->alt_s2fuser1ctr);
+       mmio_write_32(CLKMGR_ALTERA + CLKMGR_ALTERA_PSIREFCTR,
+                       hoff_ptr->alt_psirefctr);
+
+       /* Take all PLLs out of bypass */
+       mmio_write_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_BYPASS, 0);
+       wait_fsm();
+
+       mmio_write_32(CLKMGR_PERPLL + CLKMGR_PERPLL_BYPASS, 0);
+       wait_fsm();
+
+       /* Clear loss lock  interrupt status register that */
+       /* might be set during configuration */
+       mmio_setbits_32(CLKMGR_OFFSET + CLKMGR_INTRCLR,
+                       CLKMGR_INTRCLR_MAINLOCKLOST_SET_MSK |
+                       CLKMGR_INTRCLR_PERLOCKLOST_SET_MSK);
+
+       /* Take all ping pong counters out of reset */
+       mmio_clrbits_32(CLKMGR_ALTERA + CLKMGR_ALTERA_EXTCNTRST,
+                       CLKMGR_ALTERA_EXTCNTRST_RESET);
+
+       /* Set safe mode / out of boot mode */
+       mmio_clrbits_32(CLKMGR_OFFSET + CLKMGR_CTRL,
+               CLKMGR_CTRL_BOOTMODE_SET_MSK);
+       wait_fsm();
+
+       /* Enable mainpllgrp's software-managed clock */
+       mmio_write_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_EN,
+                       CLKMGR_MAINPLL_EN_RESET);
+       mmio_write_32(CLKMGR_PERPLL + CLKMGR_PERPLL_EN,
+                       CLKMGR_PERPLL_EN_RESET);
+}
+
+int get_wdt_clk(handoff *hoff_ptr)
+{
+       int main_noc_base_clk, l3_main_free_clk, l4_sys_free_clk;
+       int data32, mdiv, arefclkdiv, ref_clk;
+
+       data32 = mmio_read_32(CLKMGR_MAINPLL + CLKMGR_MAINPLL_PLLGLOB);
+
+       switch (CLKMGR_MAINPLL_PLLGLOB_PSRC(data32)) {
+       case CLKMGR_MAINPLL_PLLGLOB_PSRC_EOSC1:
+               ref_clk = clk_source.clk_freq_of_eosc1;
+               break;
+       case CLKMGR_MAINPLL_PLLGLOB_PSRC_INTOSC:
+               ref_clk = clk_source.clk_freq_of_cb_intosc_ls;
+               break;
+       case CLKMGR_MAINPLL_PLLGLOB_PSRC_F2S:
+               ref_clk = clk_source.clk_freq_of_f2h_free;
+               break;
+       default:
+               ref_clk = 0;
+               assert(0);
+               break;
+       }
+
+       arefclkdiv = CLKMGR_MAINPLL_PLLGLOB_AREFCLKDIV(data32);
+       mdiv = CLKMGR_MAINPLL_PLLM_MDIV(hoff_ptr->main_pll_pllm);
+
+       ref_clk = (ref_clk / arefclkdiv) * mdiv;
+       main_noc_base_clk = ref_clk / (hoff_ptr->main_pll_pllc1 & 0x7ff);
+       l3_main_free_clk = main_noc_base_clk / (hoff_ptr->main_pll_nocclk + 1);
+       l4_sys_free_clk = l3_main_free_clk / 4;
+
+       return l4_sys_free_clk;
+}
diff --git a/plat/intel/soc/agilex/soc/agilex_handoff.c b/plat/intel/soc/agilex/soc/agilex_handoff.c
new file mode 100644 (file)
index 0000000..a458686
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <platform_def.h>
+#include <string.h>
+
+#include "agilex_handoff.h"
+
+#define SWAP_UINT32(x) (((x) >> 24) | (((x) & 0x00FF0000) >> 8) |      \
+                               (((x) & 0x0000FF00) << 8) | ((x) << 24))
+
+int agilex_get_handoff(handoff *reverse_hoff_ptr)
+{
+       int i;
+       uint32_t *buffer;
+       handoff *handoff_ptr = (handoff *) PLAT_HANDOFF_OFFSET;
+
+       memcpy(reverse_hoff_ptr, handoff_ptr, sizeof(handoff));
+       buffer = (uint32_t *)reverse_hoff_ptr;
+
+       /* convert big endian to little endian */
+       for (i = 0; i < sizeof(handoff) / 4; i++)
+               buffer[i] = SWAP_UINT32(buffer[i]);
+
+       if (reverse_hoff_ptr->header_magic != HANDOFF_MAGIC_HEADER)
+               return -1;
+       if (reverse_hoff_ptr->pinmux_sel_magic != HANDOFF_MAGIC_PINMUX_SEL)
+               return -1;
+       if (reverse_hoff_ptr->pinmux_io_magic != HANDOFF_MAGIC_IOCTLR)
+               return -1;
+       if (reverse_hoff_ptr->pinmux_fpga_magic != HANDOFF_MAGIC_FPGA)
+               return -1;
+       if (reverse_hoff_ptr->pinmux_delay_magic != HANDOFF_MAGIC_IODELAY)
+               return -1;
+
+       return 0;
+}
diff --git a/plat/intel/soc/agilex/soc/agilex_mailbox.c b/plat/intel/soc/agilex/soc/agilex_mailbox.c
new file mode 100644 (file)
index 0000000..ebfea61
--- /dev/null
@@ -0,0 +1,280 @@
+/*
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <lib/mmio.h>
+#include <common/debug.h>
+
+#include "agilex_mailbox.h"
+
+static int fill_mailbox_circular_buffer(uint32_t header_cmd, uint32_t *args,
+                                       int len)
+{
+       uint32_t cmd_free_offset;
+       int i;
+
+       cmd_free_offset = mmio_read_32(MBOX_OFFSET + MBOX_CIN);
+
+       if (cmd_free_offset >= MBOX_CMD_BUFFER_SIZE) {
+               INFO("Insufficient buffer in mailbox\n");
+               return MBOX_INSUFFICIENT_BUFFER;
+       }
+
+
+       mmio_write_32(MBOX_OFFSET + MBOX_CMD_BUFFER + (cmd_free_offset++ * 4),
+                       header_cmd);
+
+
+       for (i = 0; i < len; i++) {
+               cmd_free_offset %= MBOX_CMD_BUFFER_SIZE;
+               mmio_write_32(MBOX_OFFSET + MBOX_CMD_BUFFER +
+                               (cmd_free_offset++ * 4), args[i]);
+       }
+
+       cmd_free_offset %= MBOX_CMD_BUFFER_SIZE;
+       mmio_write_32(MBOX_OFFSET + MBOX_CIN, cmd_free_offset);
+
+       return 0;
+}
+
+int mailbox_read_response(int job_id, uint32_t *response)
+{
+       int rin = 0;
+       int rout = 0;
+       int response_length = 0;
+       int resp = 0;
+       int total_resp_len = 0;
+       int timeout = 100000;
+
+       mmio_write_32(MBOX_OFFSET + MBOX_DOORBELL_TO_SDM, 1);
+
+       while (mmio_read_32(MBOX_OFFSET + MBOX_DOORBELL_FROM_SDM) != 1) {
+               if (timeout-- < 0)
+                       return MBOX_NO_RESPONSE;
+       }
+
+       mmio_write_32(MBOX_OFFSET + MBOX_DOORBELL_FROM_SDM, 0);
+
+       rin = mmio_read_32(MBOX_OFFSET + MBOX_RIN);
+       rout = mmio_read_32(MBOX_OFFSET + MBOX_ROUT);
+
+       while (rout != rin) {
+               resp = mmio_read_32(MBOX_OFFSET +
+                                   MBOX_RESP_BUFFER + ((rout++)*4));
+
+               rout %= MBOX_RESP_BUFFER_SIZE;
+               mmio_write_32(MBOX_OFFSET + MBOX_ROUT, rout);
+
+               if (MBOX_RESP_CLIENT_ID(resp) != MBOX_ATF_CLIENT_ID ||
+                  MBOX_RESP_JOB_ID(resp) != job_id) {
+                       return MBOX_WRONG_ID;
+               }
+
+               if (MBOX_RESP_ERR(resp) > 0) {
+                       INFO("Error in response: %x\n", resp);
+                       return -resp;
+               }
+               response_length = MBOX_RESP_LEN(resp);
+
+               while (response_length) {
+
+                       response_length--;
+                       resp = mmio_read_32(MBOX_OFFSET +
+                                               MBOX_RESP_BUFFER +
+                                               (rout)*4);
+                       if (response) {
+                               *(response + total_resp_len) = resp;
+                               total_resp_len++;
+                       }
+                       rout++;
+                       rout %= MBOX_RESP_BUFFER_SIZE;
+                       mmio_write_32(MBOX_OFFSET + MBOX_ROUT, rout);
+               }
+               return total_resp_len;
+       }
+
+       return MBOX_NO_RESPONSE;
+}
+
+
+int mailbox_poll_response(int job_id, int urgent, uint32_t *response)
+{
+       int timeout = 80000;
+       int rin = 0;
+       int rout = 0;
+       int response_length = 0;
+       int resp = 0;
+       int total_resp_len = 0;
+
+       mmio_write_32(MBOX_OFFSET + MBOX_DOORBELL_TO_SDM, 1);
+
+       while (1) {
+               while (timeout > 0 &&
+                       mmio_read_32(MBOX_OFFSET +
+                               MBOX_DOORBELL_FROM_SDM) != 1) {
+                       timeout--;
+               }
+
+               if (mmio_read_32(MBOX_OFFSET + MBOX_DOORBELL_FROM_SDM) != 1) {
+                       INFO("Timed out waiting for SDM");
+                       return MBOX_TIMEOUT;
+               }
+
+               mmio_write_32(MBOX_OFFSET + MBOX_DOORBELL_FROM_SDM, 0);
+
+               if (urgent & 1) {
+                       if ((mmio_read_32(MBOX_OFFSET + MBOX_STATUS) &
+                               MBOX_STATUS_UA_MASK) ^
+                               (urgent & MBOX_STATUS_UA_MASK)) {
+                               mmio_write_32(MBOX_OFFSET + MBOX_URG, 0);
+                               return 0;
+                       }
+
+                       mmio_write_32(MBOX_OFFSET + MBOX_URG, 0);
+                       INFO("Error: Mailbox did not get UA");
+                       return -1;
+               }
+
+               rin = mmio_read_32(MBOX_OFFSET + MBOX_RIN);
+               rout = mmio_read_32(MBOX_OFFSET + MBOX_ROUT);
+
+               while (rout != rin) {
+                       resp = mmio_read_32(MBOX_OFFSET +
+                                           MBOX_RESP_BUFFER + ((rout++)*4));
+
+                       rout %= MBOX_RESP_BUFFER_SIZE;
+                       mmio_write_32(MBOX_OFFSET + MBOX_ROUT, rout);
+
+                       if (MBOX_RESP_CLIENT_ID(resp) != MBOX_ATF_CLIENT_ID ||
+                          MBOX_RESP_JOB_ID(resp) != job_id)
+                               continue;
+
+                       if (MBOX_RESP_ERR(resp) > 0) {
+                               INFO("Error in response: %x\n", resp);
+                               return -MBOX_RESP_ERR(resp);
+                       }
+                       response_length = MBOX_RESP_LEN(resp);
+
+                       while (response_length) {
+
+                               response_length--;
+                               resp = mmio_read_32(MBOX_OFFSET +
+                                                       MBOX_RESP_BUFFER +
+                                                       (rout)*4);
+                               if (response) {
+                                       *(response + total_resp_len) = resp;
+                                       total_resp_len++;
+                               }
+                               rout++;
+                               rout %= MBOX_RESP_BUFFER_SIZE;
+                               mmio_write_32(MBOX_OFFSET + MBOX_ROUT, rout);
+                       }
+                       return total_resp_len;
+               }
+       }
+}
+
+void mailbox_send_cmd_async(int job_id, unsigned int cmd, uint32_t *args,
+                         int len, int urgent)
+{
+       if (urgent)
+               mmio_write_32(MBOX_OFFSET + MBOX_URG, 1);
+
+       fill_mailbox_circular_buffer(MBOX_CLIENT_ID_CMD(MBOX_ATF_CLIENT_ID) |
+                                       MBOX_JOB_ID_CMD(job_id) |
+                                       MBOX_CMD_LEN_CMD(len) |
+                                       MBOX_INDIRECT |
+                                       cmd, args, len);
+}
+
+int mailbox_send_cmd(int job_id, unsigned int cmd, uint32_t *args,
+                         int len, int urgent, uint32_t *response)
+{
+       int status;
+
+       if (urgent) {
+               urgent |= mmio_read_32(MBOX_OFFSET + MBOX_STATUS) &
+                                       MBOX_STATUS_UA_MASK;
+               mmio_write_32(MBOX_OFFSET + MBOX_URG, cmd);
+               status = 0;
+       } else {
+               status = fill_mailbox_circular_buffer(
+                       MBOX_CLIENT_ID_CMD(MBOX_ATF_CLIENT_ID) |
+                       MBOX_JOB_ID_CMD(job_id) |
+                       cmd, args, len);
+       }
+
+       if (status)
+               return status;
+
+       return mailbox_poll_response(job_id, urgent, response);
+}
+
+void mailbox_set_int(int interrupt)
+{
+
+       mmio_write_32(MBOX_OFFSET+MBOX_INT, MBOX_COE_BIT(interrupt) |
+                       MBOX_UAE_BIT(interrupt));
+}
+
+
+void mailbox_set_qspi_open(void)
+{
+       mailbox_set_int(MBOX_INT_FLAG_COE | MBOX_INT_FLAG_RIE);
+       mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_QSPI_OPEN, 0, 0, 0, 0);
+}
+
+void mailbox_set_qspi_direct(void)
+{
+       mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_QSPI_DIRECT, 0, 0, 0, 0);
+}
+
+void mailbox_set_qspi_close(void)
+{
+       mailbox_set_int(MBOX_INT_FLAG_COE | MBOX_INT_FLAG_RIE);
+       mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_QSPI_CLOSE, 0, 0, 0, 0);
+}
+
+int mailbox_get_qspi_clock(void)
+{
+       mailbox_set_int(MBOX_INT_FLAG_COE | MBOX_INT_FLAG_RIE);
+       return mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_QSPI_DIRECT, 0, 0, 0, 0);
+}
+
+void mailbox_qspi_set_cs(int device_select)
+{
+       uint32_t cs_setting = device_select;
+
+       /* QSPI device select settings at 31:28 */
+       cs_setting = (cs_setting << 28);
+       mailbox_set_int(MBOX_INT_FLAG_COE | MBOX_INT_FLAG_RIE);
+       mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_QSPI_SET_CS, &cs_setting,
+               1, 0, 0);
+}
+
+void mailbox_reset_cold(void)
+{
+       mailbox_set_int(MBOX_INT_FLAG_COE | MBOX_INT_FLAG_RIE);
+       mailbox_send_cmd(MBOX_JOB_ID, MBOX_CMD_REBOOT_HPS, 0, 0, 0, 0);
+}
+
+int mailbox_init(void)
+{
+       int status = 0;
+
+       mailbox_set_int(MBOX_INT_FLAG_COE | MBOX_INT_FLAG_RIE |
+                       MBOX_INT_FLAG_UAE);
+       mmio_write_32(MBOX_OFFSET + MBOX_URG, 0);
+       mmio_write_32(MBOX_OFFSET + MBOX_DOORBELL_FROM_SDM, 0);
+       status = mailbox_send_cmd(0, MBOX_CMD_RESTART, 0, 0, 1, 0);
+
+       if (status)
+               return status;
+
+       mailbox_set_int(MBOX_INT_FLAG_COE | MBOX_INT_FLAG_RIE);
+
+       return 0;
+}
+
diff --git a/plat/intel/soc/agilex/soc/agilex_memory_controller.c b/plat/intel/soc/agilex/soc/agilex_memory_controller.c
new file mode 100644 (file)
index 0000000..9fc3e0a
--- /dev/null
@@ -0,0 +1,395 @@
+/*
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <errno.h>
+#include <lib/mmio.h>
+#include <lib/utils.h>
+#include <common/debug.h>
+#include <drivers/delay_timer.h>
+#include <platform_def.h>
+
+#include "agilex_memory_controller.h"
+
+#define ALT_CCU_NOC_DI_SET_MSK         0x10
+
+#define DDR_READ_LATENCY_DELAY         40
+#define MAX_MEM_CAL_RETRY              3
+#define PRE_CALIBRATION_DELAY          1
+#define POST_CALIBRATION_DELAY         1
+#define TIMEOUT_EMIF_CALIBRATION       100
+#define CLEAR_EMIF_DELAY               50000
+#define CLEAR_EMIF_TIMEOUT             0x100000
+#define TIMEOUT_INT_RESP               10000
+
+#define DDR_CONFIG(A, B, C, R) (((A) << 24) | ((B) << 16) | ((C) << 8) | (R))
+#define DDR_CONFIG_ELEMENTS    (sizeof(ddr_config)/sizeof(uint32_t))
+
+/* tWR = Min. 15ns constant, see JEDEC standard eg. DDR4 is JESD79-4.pdf */
+#define tWR_IN_NS 15
+
+void configure_hmc_adaptor_regs(void);
+void configure_ddr_sched_ctrl_regs(void);
+
+/* The followring are the supported configurations */
+uint32_t ddr_config[] = {
+       /* DDR_CONFIG(Address order,Bank,Column,Row) */
+       /* List for DDR3 or LPDDR3 (pinout order > chip, row, bank, column) */
+       DDR_CONFIG(0, 3, 10, 12),
+       DDR_CONFIG(0, 3,  9, 13),
+       DDR_CONFIG(0, 3, 10, 13),
+       DDR_CONFIG(0, 3,  9, 14),
+       DDR_CONFIG(0, 3, 10, 14),
+       DDR_CONFIG(0, 3, 10, 15),
+       DDR_CONFIG(0, 3, 11, 14),
+       DDR_CONFIG(0, 3, 11, 15),
+       DDR_CONFIG(0, 3, 10, 16),
+       DDR_CONFIG(0, 3, 11, 16),
+       DDR_CONFIG(0, 3, 12, 15),       /* 0xa */
+       /* List for DDR4 only (pinout order > chip, bank, row, column) */
+       DDR_CONFIG(1, 3, 10, 14),
+       DDR_CONFIG(1, 4, 10, 14),
+       DDR_CONFIG(1, 3, 10, 15),
+       DDR_CONFIG(1, 4, 10, 15),
+       DDR_CONFIG(1, 3, 10, 16),
+       DDR_CONFIG(1, 4, 10, 16),
+       DDR_CONFIG(1, 3, 10, 17),
+       DDR_CONFIG(1, 4, 10, 17),
+};
+
+static int match_ddr_conf(uint32_t ddr_conf)
+{
+       int i;
+
+       for (i = 0; i < DDR_CONFIG_ELEMENTS; i++) {
+               if (ddr_conf == ddr_config[i])
+                       return i;
+       }
+       return 0;
+}
+
+static int check_hmc_clk(void)
+{
+       unsigned long timeout = 0;
+       uint32_t hmc_clk;
+
+       do {
+               hmc_clk = mmio_read_32(AGX_SYSMGR_CORE_HMC_CLK);
+               if (hmc_clk & AGX_SYSMGR_CORE_HMC_CLK_STATUS)
+                       break;
+               udelay(1);
+       } while (++timeout < 1000);
+       if (timeout >= 1000)
+               return -ETIMEDOUT;
+
+       return 0;
+}
+
+static int clear_emif(void)
+{
+       uint32_t data;
+       unsigned long timeout;
+
+       mmio_write_32(AGX_MPFE_HMC_ADP_RSTHANDSHAKECTRL, 0);
+
+       timeout = 0;
+       do {
+               data = mmio_read_32(AGX_MPFE_HMC_ADP_RSTHANDSHAKESTAT);
+               if ((data & AGX_MPFE_HMC_ADP_RSTHANDSHAKESTAT_SEQ2CORE) == 0)
+                       break;
+               udelay(CLEAR_EMIF_DELAY);
+       } while (++timeout < CLEAR_EMIF_TIMEOUT);
+       if (timeout >= CLEAR_EMIF_TIMEOUT)
+               return -ETIMEDOUT;
+
+       return 0;
+}
+
+static int mem_calibration(void)
+{
+       int status = 0;
+       uint32_t data;
+       unsigned long timeout;
+       unsigned long retry = 0;
+
+       udelay(PRE_CALIBRATION_DELAY);
+
+       do {
+               if (retry != 0)
+                       INFO("DDR: Retrying DRAM calibration\n");
+
+               timeout = 0;
+               do {
+                       data = mmio_read_32(AGX_MPFE_HMC_ADP_DDRCALSTAT);
+                       if (AGX_MPFE_HMC_ADP_DDRCALSTAT_CAL(data) == 1)
+                               break;
+                       udelay(1);
+               } while (++timeout < TIMEOUT_EMIF_CALIBRATION);
+
+               if (AGX_MPFE_HMC_ADP_DDRCALSTAT_CAL(data) == 0) {
+                       status = clear_emif();
+               if (status)
+                       ERROR("Failed to clear Emif\n");
+               } else {
+                       break;
+               }
+       } while (++retry < MAX_MEM_CAL_RETRY);
+
+       if (AGX_MPFE_HMC_ADP_DDRCALSTAT_CAL(data) == 0) {
+               ERROR("DDR: DRAM calibration failed.\n");
+               status = -EIO;
+       } else {
+               INFO("DDR: DRAM calibration success.\n");
+               status = 0;
+       }
+
+       udelay(POST_CALIBRATION_DELAY);
+
+       return status;
+}
+
+int init_hard_memory_controller(void)
+{
+       int status;
+
+       status = check_hmc_clk();
+       if (status) {
+               ERROR("DDR: Error, HMC clock not running\n");
+               return status;
+       }
+
+/*     mmio_clrbits_32(AGX_RSTMGR_BRGMODRST, AGX_RSTMGR_BRGMODRST_DDRSCH);*/
+
+       status = mem_calibration();
+       if (status) {
+               ERROR("DDR: Memory Calibration Failed\n");
+               return status;
+       }
+
+       configure_hmc_adaptor_regs();
+/*     configure_ddr_sched_ctrl_regs();*/
+
+       return 0;
+}
+
+void configure_ddr_sched_ctrl_regs(void)
+{
+       uint32_t data, dram_addr_order, ddr_conf, bank, row, col,
+               rd_to_miss, wr_to_miss, burst_len, burst_len_ddr_clk,
+               burst_len_sched_clk, act_to_act, rd_to_wr, wr_to_rd, bw_ratio,
+               t_rtp, t_rp, t_rcd, rd_latency, tw_rin_clk_cycles,
+               bw_ratio_extended, auto_precharge = 0, act_to_act_bank, faw,
+               faw_bank, bus_rd_to_rd, bus_rd_to_wr, bus_wr_to_rd;
+
+       INFO("Init HPS NOC's DDR Scheduler.\n");
+
+       data = mmio_read_32(AGX_MPFE_IOHMC_CTRLCFG1);
+       dram_addr_order = AGX_MPFE_IOHMC_CTRLCFG1_CFG_ADDR_ORDER(data);
+
+       data = mmio_read_32(AGX_MPFE_IOHMC_DRAMADDRW);
+
+       col  = IOHMC_DRAMADDRW_COL_ADDR_WIDTH(data);
+       row  = IOHMC_DRAMADDRW_ROW_ADDR_WIDTH(data);
+       bank = IOHMC_DRAMADDRW_BANK_ADDR_WIDTH(data) +
+               IOHMC_DRAMADDRW_BANK_GRP_ADDR_WIDTH(data);
+
+       ddr_conf = match_ddr_conf(DDR_CONFIG(dram_addr_order, bank, col, row));
+
+       if (ddr_conf) {
+               mmio_clrsetbits_32(
+                       AGX_MPFE_DDR_MAIN_SCHED_DDRCONF,
+                       AGX_MPFE_DDR_MAIN_SCHED_DDRCONF_SET_MSK,
+                       AGX_MPFE_DDR_MAIN_SCHED_DDRCONF_SET(ddr_conf));
+       } else {
+               ERROR("DDR: Cannot find predefined ddrConf configuration.\n");
+       }
+
+       mmio_write_32(AGX_MPFE_HMC_ADP(ADP_DRAMADDRWIDTH), data);
+
+       data = mmio_read_32(AGX_MPFE_IOHMC_DRAMTIMING0);
+       rd_latency = AGX_MPFE_IOHMC_REG_DRAMTIMING0_CFG_TCL(data);
+
+       data = mmio_read_32(AGX_MPFE_IOHMC_CALTIMING0);
+       act_to_act = ACT_TO_ACT(data);
+       t_rcd = ACT_TO_RDWR(data);
+       act_to_act_bank = ACT_TO_ACT_DIFF_BANK(data);
+
+       data = mmio_read_32(AGX_MPFE_IOHMC_CALTIMING1);
+       rd_to_wr = RD_TO_WR(data);
+       bus_rd_to_rd = RD_TO_RD_DIFF_CHIP(data);
+       bus_rd_to_wr = RD_TO_WR_DIFF_CHIP(data);
+
+       data = mmio_read_32(AGX_MPFE_IOHMC_CALTIMING2);
+       t_rtp = RD_TO_PCH(data);
+
+       data = mmio_read_32(AGX_MPFE_IOHMC_CALTIMING3);
+       wr_to_rd = CALTIMING3_WR_TO_RD(data);
+       bus_wr_to_rd = CALTIMING3_WR_TO_RD_DIFF_CHIP(data);
+
+       data = mmio_read_32(AGX_MPFE_IOHMC_CALTIMING4);
+       t_rp = PCH_TO_VALID(data);
+
+       data = mmio_read_32(AGX_MPFE_HMC_ADP(HMC_ADP_DDRIOCTRL));
+       bw_ratio = ((HMC_ADP_DDRIOCTRL_IO_SIZE(data) == 0) ? 0 : 1);
+
+       data = mmio_read_32(AGX_MPFE_IOHMC_CTRLCFG0);
+       burst_len = HMC_ADP_DDRIOCTRL_CTRL_BURST_LENGTH(data);
+       burst_len_ddr_clk = burst_len / 2;
+       burst_len_sched_clk = ((burst_len/2) / 2);
+
+       data = mmio_read_32(AGX_MPFE_IOHMC_CTRLCFG0);
+       switch (AGX_MPFE_IOHMC_REG_CTRLCFG0_CFG_MEM_TYPE(data)) {
+       case 1:
+               /* DDR4 - 1333MHz */
+               /* 20 (19.995) clock cycles = 15ns */
+               /* Calculate with rounding */
+               tw_rin_clk_cycles = (((tWR_IN_NS * 1333) % 1000) >= 500) ?
+                       ((tWR_IN_NS * 1333) / 1000) + 1 :
+                       ((tWR_IN_NS * 1333) / 1000);
+               break;
+       default:
+               /* Others - 1066MHz or slower */
+               /* 16 (15.990) clock cycles = 15ns */
+               /* Calculate with rounding */
+               tw_rin_clk_cycles = (((tWR_IN_NS * 1066) % 1000) >= 500) ?
+                       ((tWR_IN_NS * 1066) / 1000) + 1 :
+                       ((tWR_IN_NS * 1066) / 1000);
+               break;
+       }
+
+       rd_to_miss = t_rtp + t_rp + t_rcd - burst_len_sched_clk;
+       wr_to_miss = ((rd_latency + burst_len_ddr_clk + 2 + tw_rin_clk_cycles)
+                       / 2) - rd_to_wr + t_rp + t_rcd;
+
+       mmio_write_32(AGX_MPFE_DDR_MAIN_SCHED_DDRTIMING,
+               bw_ratio << DDRTIMING_BWRATIO_OFST |
+               wr_to_rd << DDRTIMING_WRTORD_OFST|
+               rd_to_wr << DDRTIMING_RDTOWR_OFST |
+               burst_len_sched_clk << DDRTIMING_BURSTLEN_OFST |
+               wr_to_miss << DDRTIMING_WRTOMISS_OFST |
+               rd_to_miss << DDRTIMING_RDTOMISS_OFST |
+               act_to_act << DDRTIMING_ACTTOACT_OFST);
+
+       data = mmio_read_32(AGX_MPFE_HMC_ADP(HMC_ADP_DDRIOCTRL));
+       bw_ratio_extended = ((ADP_DDRIOCTRL_IO_SIZE(data) == 0) ? 1 : 0);
+
+       mmio_write_32(AGX_MPFE_DDR_MAIN_SCHED_DDRMODE,
+               bw_ratio_extended << DDRMODE_BWRATIOEXTENDED_OFST |
+               auto_precharge << DDRMODE_AUTOPRECHARGE_OFST);
+
+       mmio_write_32(AGX_MPFE_DDR_MAIN_SCHED_READLATENCY,
+               (rd_latency / 2) + DDR_READ_LATENCY_DELAY);
+
+       data = mmio_read_32(AGX_MPFE_IOHMC_CALTIMING9);
+       faw = AGX_MPFE_IOHMC_CALTIMING9_ACT_TO_ACT(data);
+
+       faw_bank = 1; // always 1 because we always have 4 bank DDR.
+
+       mmio_write_32(AGX_MPFE_DDR_MAIN_SCHED_ACTIVATE,
+               faw_bank << AGX_MPFE_DDR_MAIN_SCHED_ACTIVATE_FAWBANK_OFST |
+               faw << AGX_MPFE_DDR_MAIN_SCHED_ACTIVATE_FAW_OFST |
+               act_to_act_bank << AGX_MPFE_DDR_MAIN_SCHED_ACTIVATE_RRD_OFST);
+
+       mmio_write_32(AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV,
+               ((bus_rd_to_rd
+                       << AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV_BUSRDTORD_OFST)
+                       & AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV_BUSRDTORD_MSK) |
+               ((bus_rd_to_wr
+                       << AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV_BUSRDTOWR_OFST)
+                       & AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV_BUSRDTOWR_MSK) |
+               ((bus_wr_to_rd
+                       << AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV_BUSWRTORD_OFST)
+                       & AGX_MPFE_DDR_MAIN_SCHED_DEVTODEV_BUSWRTORD_MSK));
+
+}
+
+unsigned long get_physical_dram_size(void)
+{
+       uint32_t data;
+       unsigned long ram_addr_width, ram_ext_if_io_width;
+
+       data = mmio_read_32(AGX_MPFE_HMC_ADP_DDRIOCTRL);
+       switch (AGX_MPFE_HMC_ADP_DDRIOCTRL_IO_SIZE(data)) {
+       case 0:
+               ram_ext_if_io_width = 16;
+               break;
+       case 1:
+               ram_ext_if_io_width = 32;
+               break;
+       case 2:
+               ram_ext_if_io_width = 64;
+               break;
+       default:
+               ram_ext_if_io_width = 0;
+               break;
+       }
+
+       data = mmio_read_32(AGX_MPFE_IOHMC_REG_DRAMADDRW);
+       ram_addr_width = IOHMC_DRAMADDRW_CFG_COL_ADDR_WIDTH(data) +
+               IOHMC_DRAMADDRW_CFG_ROW_ADDR_WIDTH(data) +
+               IOHMC_DRAMADDRW_CFG_BANK_ADDR_WIDTH(data) +
+               IOHMC_DRAMADDRW_CFG_BANK_GROUP_ADDR_WIDTH(data) +
+               IOHMC_DRAMADDRW_CFG_CS_ADDR_WIDTH(data);
+
+       return (1 << ram_addr_width) * (ram_ext_if_io_width / 8);
+}
+
+
+
+void configure_hmc_adaptor_regs(void)
+{
+       uint32_t data;
+       uint32_t dram_io_width;
+
+       /* Configure DDR data rate */
+       dram_io_width = AGX_MPFE_IOHMC_NIOSRESERVE0_NIOS_RESERVE0(
+               mmio_read_32(AGX_MPFE_IOHMC_REG_NIOSRESERVE0_OFST));
+       dram_io_width = (dram_io_width & 0xFF) >> 5;
+
+       mmio_clrsetbits_32(AGX_MPFE_HMC_ADP_DDRIOCTRL,
+               AGX_MPFE_HMC_ADP_DDRIOCTRL_IO_SIZE_MSK,
+               dram_io_width << AGX_MPFE_HMC_ADP_DDRIOCTRL_IO_SIZE_OFST);
+
+       /* Copy dram addr width from IOHMC to HMC ADP */
+       data = mmio_read_32(AGX_MPFE_IOHMC_DRAMADDRW);
+       mmio_write_32(AGX_MPFE_HMC_ADP(ADP_DRAMADDRWIDTH), data);
+
+       /* Enable nonsecure access to DDR */
+       mmio_write_32(AGX_NOC_FW_DDR_SCR_MPUREGION0ADDR_LIMIT,
+                       0x4000000 - 1);
+       mmio_write_32(AGX_NOC_FW_DDR_SCR_NONMPUREGION0ADDR_LIMIT,
+                       0x4000000 - 1);
+       mmio_write_32(AGX_SOC_NOC_FW_DDR_SCR_ENABLE, BIT(0) | BIT(8));
+
+       /* ECC enablement */
+       data = mmio_read_32(AGX_MPFE_IOHMC_REG_CTRLCFG1);
+       if (data & (1 << AGX_IOHMC_CTRLCFG1_ENABLE_ECC_OFST)) {
+               mmio_clrsetbits_32(AGX_MPFE_HMC_ADP_ECCCTRL1,
+                       AGX_MPFE_HMC_ADP_ECCCTRL1_AUTOWB_CNT_RST_SET_MSK |
+                       AGX_MPFE_HMC_ADP_ECCCTRL1_CNT_RST_SET_MSK |
+                       AGX_MPFE_HMC_ADP_ECCCTRL1_ECC_EN_SET_MSK,
+                       AGX_MPFE_HMC_ADP_ECCCTRL1_AUTOWB_CNT_RST_SET_MSK |
+                       AGX_MPFE_HMC_ADP_ECCCTRL1_CNT_RST_SET_MSK);
+
+               mmio_clrsetbits_32(AGX_MPFE_HMC_ADP_ECCCTRL2,
+                       AGX_MPFE_HMC_ADP_ECCCTRL2_OVRW_RB_ECC_EN_SET_MSK |
+                       AGX_MPFE_HMC_ADP_ECCCTRL2_RMW_EN_SET_MSK |
+                       AGX_MPFE_HMC_ADP_ECCCTRL2_AUTOWB_EN_SET_MSK,
+                       AGX_MPFE_HMC_ADP_ECCCTRL2_RMW_EN_SET_MSK |
+                       AGX_MPFE_HMC_ADP_ECCCTRL2_AUTOWB_EN_SET_MSK);
+
+               mmio_clrsetbits_32(AGX_MPFE_HMC_ADP_ECCCTRL1,
+                       AGX_MPFE_HMC_ADP_ECCCTRL1_AUTOWB_CNT_RST_SET_MSK |
+                       AGX_MPFE_HMC_ADP_ECCCTRL1_CNT_RST_SET_MSK |
+                       AGX_MPFE_HMC_ADP_ECCCTRL1_ECC_EN_SET_MSK,
+                       AGX_MPFE_HMC_ADP_ECCCTRL1_ECC_EN_SET_MSK);
+               INFO("Scrubbing ECC\n");
+
+               /* ECC Scrubbing */
+               zeromem(DRAM_BASE, DRAM_SIZE);
+       } else {
+               INFO("ECC is disabled.\n");
+       }
+}
diff --git a/plat/intel/soc/agilex/soc/agilex_pinmux.c b/plat/intel/soc/agilex/soc/agilex_pinmux.c
new file mode 100644 (file)
index 0000000..eff1947
--- /dev/null
@@ -0,0 +1,217 @@
+/*
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <lib/mmio.h>
+
+#include "agilex_pinmux.h"
+
+const uint32_t sysmgr_pinmux_array_sel[] = {
+       0x00000000, 0x00000001, /* usb */
+       0x00000004, 0x00000001,
+       0x00000008, 0x00000001,
+       0x0000000c, 0x00000001,
+       0x00000010, 0x00000001,
+       0x00000014, 0x00000001,
+       0x00000018, 0x00000001,
+       0x0000001c, 0x00000001,
+       0x00000020, 0x00000001,
+       0x00000024, 0x00000001,
+       0x00000028, 0x00000001,
+       0x0000002c, 0x00000001,
+       0x00000030, 0x00000000, /* emac0 */
+       0x00000034, 0x00000000,
+       0x00000038, 0x00000000,
+       0x0000003c, 0x00000000,
+       0x00000040, 0x00000000,
+       0x00000044, 0x00000000,
+       0x00000048, 0x00000000,
+       0x0000004c, 0x00000000,
+       0x00000050, 0x00000000,
+       0x00000054, 0x00000000,
+       0x00000058, 0x00000000,
+       0x0000005c, 0x00000000,
+       0x00000060, 0x00000008, /* gpio1 */
+       0x00000064, 0x00000008,
+       0x00000068, 0x00000005,  /* uart0 tx */
+       0x0000006c, 0x00000005,  /*  uart 0 rx */
+       0x00000070, 0x00000008,  /*  gpio */
+       0x00000074, 0x00000008,
+       0x00000078, 0x00000004, /* i2c1 */
+       0x0000007c, 0x00000004,
+       0x00000080, 0x00000007,  /* jtag */
+       0x00000084, 0x00000007,
+       0x00000088, 0x00000007,
+       0x0000008c, 0x00000007,
+       0x00000090, 0x00000001,  /* sdmmc data0 */
+       0x00000094, 0x00000001,
+       0x00000098, 0x00000001,
+       0x0000009c, 0x00000001,
+       0x00000100, 0x00000001,
+       0x00000104, 0x00000001,  /* sdmmc.data3 */
+       0x00000108, 0x00000008,  /* loan */
+       0x0000010c, 0x00000008,   /* gpio */
+       0x00000110, 0x00000008,
+       0x00000114, 0x00000008,  /* gpio1.io21 */
+       0x00000118, 0x00000005,  /* mdio0.mdio */
+       0x0000011c, 0x00000005  /* mdio0.mdc */
+};
+
+const uint32_t sysmgr_pinmux_array_ctrl[] = {
+       0x00000000, 0x00502c38, /* Q1_1 */
+       0x00000004, 0x00102c38,
+       0x00000008, 0x00502c38,
+       0x0000000c, 0x00502c38,
+       0x00000010, 0x00502c38,
+       0x00000014, 0x00502c38,
+       0x00000018, 0x00502c38,
+       0x0000001c, 0x00502c38,
+       0x00000020, 0x00502c38,
+       0x00000024, 0x00502c38,
+       0x00000028, 0x00502c38,
+       0x0000002c, 0x00502c38,
+       0x00000030, 0x00102c38, /* Q2_1 */
+       0x00000034, 0x00102c38,
+       0x00000038, 0x00502c38,
+       0x0000003c, 0x00502c38,
+       0x00000040, 0x00102c38,
+       0x00000044, 0x00102c38,
+       0x00000048, 0x00502c38,
+       0x0000004c, 0x00502c38,
+       0x00000050, 0x00102c38,
+       0x00000054, 0x00102c38,
+       0x00000058, 0x00502c38,
+       0x0000005c, 0x00502c38,
+       0x00000060, 0x00502c38, /* Q3_1 */
+       0x00000064, 0x00502c38,
+       0x00000068, 0x00102c38,
+       0x0000006c, 0x00502c38,
+       0x000000d0, 0x00502c38,
+       0x000000d4, 0x00502c38,
+       0x000000d8, 0x00542c38,
+       0x000000dc, 0x00542c38,
+       0x000000e0, 0x00502c38,
+       0x000000e4, 0x00502c38,
+       0x000000e8, 0x00102c38,
+       0x000000ec, 0x00502c38,
+       0x000000f0, 0x00502c38, /* Q4_1 */
+       0x000000f4, 0x00502c38,
+       0x000000f8, 0x00102c38,
+       0x000000fc, 0x00502c38,
+       0x00000100, 0x00502c38,
+       0x00000104, 0x00502c38,
+       0x00000108, 0x00102c38,
+       0x0000010c, 0x00502c38,
+       0x00000110, 0x00502c38,
+       0x00000114, 0x00502c38,
+       0x00000118, 0x00542c38,
+       0x0000011c, 0x00102c38
+};
+
+const uint32_t sysmgr_pinmux_array_fpga[] = {
+       0x00000000, 0x00000000,
+       0x00000004, 0x00000000,
+       0x00000008, 0x00000000,
+       0x0000000c, 0x00000000,
+       0x00000010, 0x00000000,
+       0x00000014, 0x00000000,
+       0x00000018, 0x00000000,
+       0x0000001c, 0x00000000,
+       0x00000020, 0x00000000,
+       0x00000028, 0x00000000,
+       0x0000002c, 0x00000000,
+       0x00000030, 0x00000000,
+       0x00000034, 0x00000000,
+       0x00000038, 0x00000000,
+       0x0000003c, 0x00000000,
+       0x00000040, 0x00000000,
+       0x00000044, 0x00000000,
+       0x00000048, 0x00000000,
+       0x00000050, 0x00000000,
+       0x00000054, 0x00000000,
+       0x00000058, 0x0000002a
+};
+
+const uint32_t sysmgr_pinmux_array_iodelay[] = {
+       0x00000000, 0x00000000,
+       0x00000004, 0x00000000,
+       0x00000008, 0x00000000,
+       0x0000000c, 0x00000000,
+       0x00000010, 0x00000000,
+       0x00000014, 0x00000000,
+       0x00000018, 0x00000000,
+       0x0000001c, 0x00000000,
+       0x00000020, 0x00000000,
+       0x00000024, 0x00000000,
+       0x00000028, 0x00000000,
+       0x0000002c, 0x00000000,
+       0x00000030, 0x00000000,
+       0x00000034, 0x00000000,
+       0x00000038, 0x00000000,
+       0x0000003c, 0x00000000,
+       0x00000040, 0x00000000,
+       0x00000044, 0x00000000,
+       0x00000048, 0x00000000,
+       0x0000004c, 0x00000000,
+       0x00000050, 0x00000000,
+       0x00000054, 0x00000000,
+       0x00000058, 0x00000000,
+       0x0000005c, 0x00000000,
+       0x00000060, 0x00000000,
+       0x00000064, 0x00000000,
+       0x00000068, 0x00000000,
+       0x0000006c, 0x00000000,
+       0x00000070, 0x00000000,
+       0x00000074, 0x00000000,
+       0x00000078, 0x00000000,
+       0x0000007c, 0x00000000,
+       0x00000080, 0x00000000,
+       0x00000084, 0x00000000,
+       0x00000088, 0x00000000,
+       0x0000008c, 0x00000000,
+       0x00000090, 0x00000000,
+       0x00000094, 0x00000000,
+       0x00000098, 0x00000000,
+       0x0000009c, 0x00000000,
+       0x00000100, 0x00000000,
+       0x00000104, 0x00000000,
+       0x00000108, 0x00000000,
+       0x0000010c, 0x00000000,
+       0x00000110, 0x00000000,
+       0x00000114, 0x00000000,
+       0x00000118, 0x00000000,
+       0x0000011c, 0x00000000
+};
+
+void config_pinmux(handoff *hoff_ptr)
+{
+       unsigned int i;
+
+       for (i = 0; i < 96; i += 2) {
+               mmio_write_32(AGX_PINMUX_PIN0SEL +
+                       hoff_ptr->pinmux_sel_array[i],
+                       hoff_ptr->pinmux_sel_array[i+1]);
+       }
+
+       for (i = 0; i < 96; i += 2) {
+               mmio_write_32(AGX_PINMUX_IO0CTRL +
+                       hoff_ptr->pinmux_io_array[i],
+                       hoff_ptr->pinmux_io_array[i+1]);
+       }
+
+       for (i = 0; i < 42; i += 2) {
+               mmio_write_32(AGX_PINMUX_PINMUX_EMAC0_USEFPGA +
+                       hoff_ptr->pinmux_fpga_array[i],
+                       hoff_ptr->pinmux_fpga_array[i+1]);
+       }
+
+       for (i = 0; i < 96; i += 2) {
+               mmio_write_32(AGX_PINMUX_IO0_DELAY +
+                       hoff_ptr->pinmux_iodelay_array[i],
+                       hoff_ptr->pinmux_iodelay_array[i+1]);
+       }
+
+}
+
diff --git a/plat/intel/soc/agilex/soc/agilex_reset_manager.c b/plat/intel/soc/agilex/soc/agilex_reset_manager.c
new file mode 100644 (file)
index 0000000..65d2029
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <lib/mmio.h>
+
+#include "agilex_reset_manager.h"
+
+void deassert_peripheral_reset(void)
+{
+       mmio_clrbits_32(AGX_RSTMGR_PER1MODRST,
+                       AGX_RSTMGR_PER1MODRST_WATCHDOG0 |
+                       AGX_RSTMGR_PER1MODRST_WATCHDOG1 |
+                       AGX_RSTMGR_PER1MODRST_WATCHDOG2 |
+                       AGX_RSTMGR_PER1MODRST_WATCHDOG3 |
+                       AGX_RSTMGR_PER1MODRST_L4SYSTIMER0 |
+                       AGX_RSTMGR_PER1MODRST_L4SYSTIMER1 |
+                       AGX_RSTMGR_PER1MODRST_SPTIMER0 |
+                       AGX_RSTMGR_PER1MODRST_SPTIMER1 |
+                       AGX_RSTMGR_PER1MODRST_I2C0 |
+                       AGX_RSTMGR_PER1MODRST_I2C1 |
+                       AGX_RSTMGR_PER1MODRST_I2C2 |
+                       AGX_RSTMGR_PER1MODRST_I2C3 |
+                       AGX_RSTMGR_PER1MODRST_I2C4 |
+                       AGX_RSTMGR_PER1MODRST_UART0 |
+                       AGX_RSTMGR_PER1MODRST_UART1 |
+                       AGX_RSTMGR_PER1MODRST_GPIO0 |
+                       AGX_RSTMGR_PER1MODRST_GPIO1);
+
+       mmio_clrbits_32(AGX_RSTMGR_PER0MODRST,
+                       AGX_RSTMGR_PER0MODRST_EMAC0OCP |
+                       AGX_RSTMGR_PER0MODRST_EMAC1OCP |
+                       AGX_RSTMGR_PER0MODRST_EMAC2OCP |
+                       AGX_RSTMGR_PER0MODRST_USB0OCP |
+                       AGX_RSTMGR_PER0MODRST_USB1OCP |
+                       AGX_RSTMGR_PER0MODRST_NANDOCP |
+                       AGX_RSTMGR_PER0MODRST_SDMMCOCP |
+                       AGX_RSTMGR_PER0MODRST_DMAOCP);
+
+       mmio_clrbits_32(AGX_RSTMGR_PER0MODRST,
+                       AGX_RSTMGR_PER0MODRST_EMAC0 |
+                       AGX_RSTMGR_PER0MODRST_EMAC1 |
+                       AGX_RSTMGR_PER0MODRST_EMAC2 |
+                       AGX_RSTMGR_PER0MODRST_USB0 |
+                       AGX_RSTMGR_PER0MODRST_USB1 |
+                       AGX_RSTMGR_PER0MODRST_NAND |
+                       AGX_RSTMGR_PER0MODRST_SDMMC |
+                       AGX_RSTMGR_PER0MODRST_DMA |
+                       AGX_RSTMGR_PER0MODRST_SPIM0 |
+                       AGX_RSTMGR_PER0MODRST_SPIM1 |
+                       AGX_RSTMGR_PER0MODRST_SPIS0 |
+                       AGX_RSTMGR_PER0MODRST_SPIS1 |
+                       AGX_RSTMGR_PER0MODRST_EMACPTP |
+                       AGX_RSTMGR_PER0MODRST_DMAIF0 |
+                       AGX_RSTMGR_PER0MODRST_DMAIF1 |
+                       AGX_RSTMGR_PER0MODRST_DMAIF2 |
+                       AGX_RSTMGR_PER0MODRST_DMAIF3 |
+                       AGX_RSTMGR_PER0MODRST_DMAIF4 |
+                       AGX_RSTMGR_PER0MODRST_DMAIF5 |
+                       AGX_RSTMGR_PER0MODRST_DMAIF6 |
+                       AGX_RSTMGR_PER0MODRST_DMAIF7);
+
+       mmio_clrbits_32(AGX_RSTMGR_BRGMODRST,
+                       AGX_RSTMGR_BRGMODRST_MPFE);
+}
+
+void config_hps_hs_before_warm_reset(void)
+{
+       uint32_t or_mask = 0;
+
+       or_mask |= AGX_RSTMGR_HDSKEN_SDRSELFREFEN;
+       or_mask |= AGX_RSTMGR_HDSKEN_FPGAHSEN;
+       or_mask |= AGX_RSTMGR_HDSKEN_ETRSTALLEN;
+       or_mask |= AGX_RSTMGR_HDSKEN_L2FLUSHEN;
+       or_mask |= AGX_RSTMGR_HDSKEN_L3NOC_DBG;
+       or_mask |= AGX_RSTMGR_HDSKEN_DEBUG_L3NOC;
+
+       mmio_setbits_32(AGX_RSTMGR_HDSKEN, or_mask);
+}
+
diff --git a/plat/intel/soc/agilex/soc/agilex_system_manager.c b/plat/intel/soc/agilex/soc/agilex_system_manager.c
new file mode 100644 (file)
index 0000000..88e895d
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <lib/mmio.h>
+#include <lib/utils_def.h>
+
+#include "agilex_system_manager.h"
+
+void enable_nonsecure_access(void)
+{
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_NAND_REGISTER, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_NAND_DATA, DISABLE_L4_FIREWALL);
+
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_NAND_ECC, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_NAND_READ_ECC, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_NAND_WRITE_ECC,
+               DISABLE_L4_FIREWALL);
+
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_USB0_REGISTER, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_USB1_REGISTER, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_USB0_ECC, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_USB1_ECC, DISABLE_L4_FIREWALL);
+
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_SPI_MASTER0, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_SPI_MASTER1, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_SPI_SLAVE0, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_SPI_SLAVE1, DISABLE_L4_FIREWALL);
+
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_EMAC0, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_EMAC1, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_EMAC2, DISABLE_L4_FIREWALL);
+
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_EMAC0RX_ECC, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_EMAC0TX_ECC, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_EMAC1RX_ECC, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_EMAC1TX_ECC, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_EMAC2RX_ECC, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_EMAC2TX_ECC, DISABLE_L4_FIREWALL);
+
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_SDMMC, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_SDMMC_ECC, DISABLE_L4_FIREWALL);
+
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_GPIO0, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_GPIO1, DISABLE_L4_FIREWALL);
+
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_I2C0, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_I2C1, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_I2C2, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_I2C3, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_I2C4, DISABLE_L4_FIREWALL);
+
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_SP_TIMER1, DISABLE_L4_FIREWALL);
+
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_UART0, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_PER_SCR_UART1, DISABLE_L4_FIREWALL);
+
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_DMA_ECC, DISABLE_L4_FIREWALL);
+
+
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_OCRAM_ECC, DISABLE_L4_FIREWALL);
+
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_CLK_MGR, DISABLE_L4_FIREWALL);
+
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_IO_MGR, DISABLE_L4_FIREWALL);
+
+
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_RST_MGR, DISABLE_L4_FIREWALL);
+
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_SYS_MGR, DISABLE_L4_FIREWALL);
+
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_OSC0_TIMER, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_OSC1_TIMER, DISABLE_L4_FIREWALL);
+
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_WATCHDOG0, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_WATCHDOG1, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_WATCHDOG2, DISABLE_L4_FIREWALL);
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_WATCHDOG3, DISABLE_L4_FIREWALL);
+
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_DAP, DISABLE_L4_FIREWALL);
+
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_L4_NOC_PROBES, DISABLE_L4_FIREWALL);
+
+       mmio_write_32(AGX_NOC_FW_L4_SYS_SCR_L4_NOC_QOS, DISABLE_L4_FIREWALL);
+}
+
+void enable_ns_bridge_access(void)
+{
+       mmio_write_32(AGX_FIREWALL_SOC2FPGA, DISABLE_BRIDGE_FIREWALL);
+       mmio_write_32(AGX_FIREWALL_LWSOC2FPGA, DISABLE_BRIDGE_FIREWALL);
+}
diff --git a/plat/intel/soc/agilex/socfpga_delay_timer.c b/plat/intel/soc/agilex/socfpga_delay_timer.c
new file mode 100644 (file)
index 0000000..e74b8bd
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <assert.h>
+#include <arch_helpers.h>
+#include <drivers/delay_timer.h>
+#include <lib/mmio.h>
+
+#define AGX_GLOBAL_TIMER       0xffd01000
+#define AGX_GLOBAL_TIMER_EN    0x3
+
+/********************************************************************
+ * The timer delay function
+ ********************************************************************/
+static uint32_t socfpga_get_timer_value(void)
+{
+       /*
+        * Generic delay timer implementation expects the timer to be a down
+        * counter. We apply bitwise NOT operator to the tick values returned
+        * by read_cntpct_el0() to simulate the down counter. The value is
+        * clipped from 64 to 32 bits.
+        */
+       return (uint32_t)(~read_cntpct_el0());
+}
+
+static const timer_ops_t plat_timer_ops = {
+       .get_timer_value    = socfpga_get_timer_value,
+       .clk_mult           = 1,
+       .clk_div            = PLAT_SYS_COUNTER_FREQ_IN_MHZ,
+};
+
+void socfpga_delay_timer_init(void)
+{
+       timer_init(&plat_timer_ops);
+       mmio_write_32(AGX_GLOBAL_TIMER, AGX_GLOBAL_TIMER_EN);
+}
diff --git a/plat/intel/soc/agilex/socfpga_image_load.c b/plat/intel/soc/agilex/socfpga_image_load.c
new file mode 100644 (file)
index 0000000..67c02bc
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <common/desc_image_load.h>
+
+/*******************************************************************************
+ * This function flushes the data structures so that they are visible
+ * in memory for the next BL image.
+ ******************************************************************************/
+void plat_flush_next_bl_params(void)
+{
+       flush_bl_params_desc();
+}
+
+/*******************************************************************************
+ * This function returns the list of loadable images.
+ ******************************************************************************/
+bl_load_info_t *plat_get_bl_image_load_info(void)
+{
+       return get_bl_load_info_from_mem_params_desc();
+}
+
+/*******************************************************************************
+ * This function returns the list of executable images.
+ ******************************************************************************/
+bl_params_t *plat_get_next_bl_params(void)
+{
+       return get_next_bl_params_from_mem_params_desc();
+}
diff --git a/plat/intel/soc/agilex/socfpga_psci.c b/plat/intel/soc/agilex/socfpga_psci.c
new file mode 100644 (file)
index 0000000..411e89b
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <arch_helpers.h>
+#include <common/debug.h>
+#include <drivers/arm/gicv2.h>
+#include <lib/mmio.h>
+#include <lib/psci/psci.h>
+#include <plat/common/platform.h>
+
+#include "agilex_reset_manager.h"
+#include "agilex_mailbox.h"
+
+#define AGX_RSTMGR_OFST                        0xffd11000
+#define AGX_RSTMGR_MPUMODRST_OFST      0x20
+
+uintptr_t *agilex_sec_entry = (uintptr_t *) PLAT_AGX_SEC_ENTRY;
+uintptr_t *cpuid_release = (uintptr_t *) PLAT_CPUID_RELEASE;
+
+/*******************************************************************************
+ * plat handler called when a CPU is about to enter standby.
+ ******************************************************************************/
+void socfpga_cpu_standby(plat_local_state_t cpu_state)
+{
+       /*
+        * Enter standby state
+        * dsb is good practice before using wfi to enter low power states
+        */
+       VERBOSE("%s: cpu_state: 0x%x\n", __func__, cpu_state);
+       dsb();
+       wfi();
+}
+
+/*******************************************************************************
+ * plat handler called when a power domain is about to be turned on. The
+ * mpidr determines the CPU to be turned on.
+ ******************************************************************************/
+int socfpga_pwr_domain_on(u_register_t mpidr)
+{
+       unsigned int cpu_id = plat_core_pos_by_mpidr(mpidr);
+
+       VERBOSE("%s: mpidr: 0x%lx\n", __func__, mpidr);
+
+       if (cpu_id == -1)
+               return PSCI_E_INTERN_FAIL;
+
+       *cpuid_release = cpu_id;
+
+       /* release core reset */
+       mmio_setbits_32(AGX_RSTMGR_OFST + AGX_RSTMGR_MPUMODRST_OFST,
+               1 << cpu_id);
+       return PSCI_E_SUCCESS;
+}
+
+/*******************************************************************************
+ * plat handler called when a power domain is about to be turned off. The
+ * target_state encodes the power state that each level should transition to.
+ ******************************************************************************/
+void socfpga_pwr_domain_off(const psci_power_state_t *target_state)
+{
+       unsigned int cpu_id = plat_my_core_pos();
+
+       for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++)
+               VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
+                       __func__, i, target_state->pwr_domain_state[i]);
+
+       /* TODO: Prevent interrupts from spuriously waking up this cpu */
+       /* gicv2_cpuif_disable(); */
+
+       /* assert core reset */
+       mmio_setbits_32(AGX_RSTMGR_OFST + AGX_RSTMGR_MPUMODRST_OFST,
+               1 << cpu_id);
+}
+
+/*******************************************************************************
+ * plat handler called when a power domain is about to be suspended. The
+ * target_state encodes the power state that each level should transition to.
+ ******************************************************************************/
+void socfpga_pwr_domain_suspend(const psci_power_state_t *target_state)
+{
+       unsigned int cpu_id = plat_my_core_pos();
+
+       for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++)
+               VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
+                       __func__, i, target_state->pwr_domain_state[i]);
+       /* assert core reset */
+       mmio_setbits_32(AGX_RSTMGR_OFST + AGX_RSTMGR_MPUMODRST_OFST,
+               1 << cpu_id);
+
+}
+
+/*******************************************************************************
+ * plat handler called when a power domain has just been powered on after
+ * being turned off earlier. The target_state encodes the low power state that
+ * each level has woken up from.
+ ******************************************************************************/
+void socfpga_pwr_domain_on_finish(const psci_power_state_t *target_state)
+{
+       for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++)
+               VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
+                       __func__, i, target_state->pwr_domain_state[i]);
+
+       /* Program the gic per-cpu distributor or re-distributor interface */
+       gicv2_pcpu_distif_init();
+       gicv2_set_pe_target_mask(plat_my_core_pos());
+
+       /* Enable the gic cpu interface */
+       gicv2_cpuif_enable();
+}
+
+/*******************************************************************************
+ * plat handler called when a power domain has just been powered on after
+ * having been suspended earlier. The target_state encodes the low power state
+ * that each level has woken up from.
+ * TODO: At the moment we reuse the on finisher and reinitialize the secure
+ * context. Need to implement a separate suspend finisher.
+ ******************************************************************************/
+void socfpga_pwr_domain_suspend_finish(const psci_power_state_t *target_state)
+{
+       unsigned int cpu_id = plat_my_core_pos();
+
+       for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++)
+               VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
+                       __func__, i, target_state->pwr_domain_state[i]);
+
+       /* release core reset */
+       mmio_clrbits_32(AGX_RSTMGR_OFST + AGX_RSTMGR_MPUMODRST_OFST,
+               1 << cpu_id);
+}
+
+/*******************************************************************************
+ * plat handlers to shutdown/reboot the system
+ ******************************************************************************/
+static void __dead2 socfpga_system_off(void)
+{
+       wfi();
+       ERROR("System Off: operation not handled.\n");
+       panic();
+}
+
+static void __dead2 socfpga_system_reset(void)
+{
+       INFO("assert Peripheral from Reset\r\n");
+
+       deassert_peripheral_reset();
+       mailbox_reset_cold();
+
+       while (1)
+               wfi();
+}
+
+int socfpga_validate_power_state(unsigned int power_state,
+                               psci_power_state_t *req_state)
+{
+       VERBOSE("%s: power_state: 0x%x\n", __func__, power_state);
+
+       return PSCI_E_SUCCESS;
+}
+
+int socfpga_validate_ns_entrypoint(unsigned long ns_entrypoint)
+{
+       VERBOSE("%s: ns_entrypoint: 0x%lx\n", __func__, ns_entrypoint);
+       return PSCI_E_SUCCESS;
+}
+
+void socfpga_get_sys_suspend_power_state(psci_power_state_t *req_state)
+{
+       req_state->pwr_domain_state[PSCI_CPU_PWR_LVL] = PLAT_MAX_OFF_STATE;
+       req_state->pwr_domain_state[1] = PLAT_MAX_OFF_STATE;
+}
+
+/*******************************************************************************
+ * Export the platform handlers via plat_arm_psci_pm_ops. The ARM Standard
+ * platform layer will take care of registering the handlers with PSCI.
+ ******************************************************************************/
+const plat_psci_ops_t socfpga_psci_pm_ops = {
+       .cpu_standby = socfpga_cpu_standby,
+       .pwr_domain_on = socfpga_pwr_domain_on,
+       .pwr_domain_off = socfpga_pwr_domain_off,
+       .pwr_domain_suspend = socfpga_pwr_domain_suspend,
+       .pwr_domain_on_finish = socfpga_pwr_domain_on_finish,
+       .pwr_domain_suspend_finish = socfpga_pwr_domain_suspend_finish,
+       .system_off = socfpga_system_off,
+       .system_reset = socfpga_system_reset,
+       .validate_power_state = socfpga_validate_power_state,
+       .validate_ns_entrypoint = socfpga_validate_ns_entrypoint,
+       .get_sys_suspend_power_state = socfpga_get_sys_suspend_power_state
+};
+
+/*******************************************************************************
+ * Export the platform specific power ops.
+ ******************************************************************************/
+int plat_setup_psci_ops(uintptr_t sec_entrypoint,
+                       const struct plat_psci_ops **psci_ops)
+{
+       /* Save warm boot entrypoint.*/
+       *agilex_sec_entry = sec_entrypoint;
+
+       *psci_ops = &socfpga_psci_pm_ops;
+       return 0;
+}
diff --git a/plat/intel/soc/agilex/socfpga_sip_svc.c b/plat/intel/soc/agilex/socfpga_sip_svc.c
new file mode 100644 (file)
index 0000000..6a1c957
--- /dev/null
@@ -0,0 +1,378 @@
+/*
+ * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <assert.h>
+#include <common/debug.h>
+#include <common/runtime_svc.h>
+#include <tools_share/uuid.h>
+
+#include "agilex_mailbox.h"
+
+/* Number of SiP Calls implemented */
+#define SIP_NUM_CALLS          0x3
+
+/* Total buffer the driver can hold */
+#define FPGA_CONFIG_BUFFER_SIZE 4
+
+int current_block;
+int current_buffer;
+int current_id = 1;
+int max_blocks;
+uint32_t bytes_per_block;
+uint32_t blocks_submitted;
+uint32_t blocks_completed;
+
+struct fpga_config_info {
+       uint32_t addr;
+       int size;
+       int size_written;
+       uint32_t write_requested;
+       int subblocks_sent;
+       int block_number;
+};
+
+/*  SiP Service UUID */
+DEFINE_SVC_UUID2(intl_svc_uid,
+               0xa85273b0, 0xe85a, 0x4862, 0xa6, 0x2a,
+               0xfa, 0x88, 0x88, 0x17, 0x68, 0x81);
+
+uint64_t socfpga_sip_handler(uint32_t smc_fid,
+                                  uint64_t x1,
+                                  uint64_t x2,
+                                  uint64_t x3,
+                                  uint64_t x4,
+                                  void *cookie,
+                                  void *handle,
+                                  uint64_t flags)
+{
+       ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
+       SMC_RET1(handle, SMC_UNK);
+}
+
+struct fpga_config_info fpga_config_buffers[FPGA_CONFIG_BUFFER_SIZE];
+
+static void intel_fpga_sdm_write_buffer(struct fpga_config_info *buffer)
+{
+       uint32_t args[3];
+
+       while (max_blocks > 0 && buffer->size > buffer->size_written) {
+               if (buffer->size - buffer->size_written <=
+                       bytes_per_block) {
+                       args[0] = (1<<8);
+                       args[1] = buffer->addr + buffer->size_written;
+                       args[2] = buffer->size - buffer->size_written;
+                       buffer->size_written +=
+                               buffer->size - buffer->size_written;
+                       buffer->subblocks_sent++;
+                       mailbox_send_cmd_async(0x4,
+                               MBOX_RECONFIG_DATA,
+                               args, 3, 0);
+                       current_buffer++;
+                       current_buffer %= FPGA_CONFIG_BUFFER_SIZE;
+               } else {
+                       args[0] = (1<<8);
+                       args[1] = buffer->addr + buffer->size_written;
+                       args[2] = bytes_per_block;
+                       buffer->size_written += bytes_per_block;
+                       mailbox_send_cmd_async(0x4,
+                               MBOX_RECONFIG_DATA,
+                               args, 3, 0);
+                       buffer->subblocks_sent++;
+               }
+               max_blocks--;
+       }
+}
+
+static int intel_fpga_sdm_write_all(void)
+{
+       int i;
+
+       for (i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++)
+               intel_fpga_sdm_write_buffer(
+                       &fpga_config_buffers[current_buffer]);
+
+       return 0;
+}
+
+uint32_t intel_mailbox_fpga_config_isdone(void)
+{
+       uint32_t args[2];
+       uint32_t response[6];
+       int status;
+
+       status = mailbox_send_cmd(1, MBOX_RECONFIG_STATUS, args, 0, 0,
+                               response);
+
+       if (status < 0)
+               return INTEL_SIP_SMC_STATUS_ERROR;
+
+       if (response[RECONFIG_STATUS_STATE] &&
+               response[RECONFIG_STATUS_STATE] != MBOX_CFGSTAT_STATE_CONFIG)
+               return INTEL_SIP_SMC_STATUS_ERROR;
+
+       if (!(response[RECONFIG_STATUS_PIN_STATUS] & PIN_STATUS_NSTATUS))
+               return INTEL_SIP_SMC_STATUS_ERROR;
+
+       if (response[RECONFIG_STATUS_SOFTFUNC_STATUS] &
+               SOFTFUNC_STATUS_SEU_ERROR)
+               return INTEL_SIP_SMC_STATUS_ERROR;
+
+       if ((response[RECONFIG_STATUS_SOFTFUNC_STATUS] &
+               SOFTFUNC_STATUS_CONF_DONE) &&
+               (response[RECONFIG_STATUS_SOFTFUNC_STATUS] &
+               SOFTFUNC_STATUS_INIT_DONE))
+               return INTEL_SIP_SMC_STATUS_OK;
+
+       return INTEL_SIP_SMC_STATUS_ERROR;
+}
+
+static int mark_last_buffer_xfer_completed(uint32_t *buffer_addr_completed)
+{
+       int i;
+
+       for (i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) {
+               if (fpga_config_buffers[i].block_number == current_block) {
+                       fpga_config_buffers[i].subblocks_sent--;
+                       if (fpga_config_buffers[i].subblocks_sent == 0
+                       && fpga_config_buffers[i].size <=
+                       fpga_config_buffers[i].size_written) {
+                               fpga_config_buffers[i].write_requested = 0;
+                               current_block++;
+                               *buffer_addr_completed =
+                                       fpga_config_buffers[i].addr;
+                               return 0;
+                       }
+               }
+       }
+
+       return -1;
+}
+
+unsigned int address_in_ddr(uint32_t *addr)
+{
+       if (((unsigned long long)addr > DRAM_BASE) &&
+               ((unsigned long long)addr < DRAM_BASE + DRAM_SIZE))
+               return 0;
+
+       return -1;
+}
+
+int intel_fpga_config_completed_write(uint32_t *completed_addr,
+                                       uint32_t *count)
+{
+       uint32_t status = INTEL_SIP_SMC_STATUS_OK;
+       *count = 0;
+       int resp_len = 0;
+       uint32_t resp[5];
+       int all_completed = 1;
+       int count_check = 0;
+
+       if (address_in_ddr(completed_addr) != 0 || address_in_ddr(count) != 0)
+               return INTEL_SIP_SMC_STATUS_ERROR;
+
+       for (count_check = 0; count_check < 3; count_check++)
+               if (address_in_ddr(&completed_addr[*count + count_check]) != 0)
+                       return INTEL_SIP_SMC_STATUS_ERROR;
+
+       resp_len = mailbox_read_response(0x4, resp);
+
+       while (resp_len >= 0 && *count < 3) {
+               max_blocks++;
+               if (mark_last_buffer_xfer_completed(
+                       &completed_addr[*count]) == 0)
+                       *count = *count + 1;
+               else
+                       break;
+               resp_len = mailbox_read_response(0x4, resp);
+       }
+
+       if (*count <= 0) {
+               if (resp_len != MBOX_NO_RESPONSE &&
+                       resp_len != MBOX_TIMEOUT && resp_len != 0) {
+                       return INTEL_SIP_SMC_STATUS_ERROR;
+               }
+
+               *count = 0;
+       }
+
+       intel_fpga_sdm_write_all();
+
+       if (*count > 0)
+               status = INTEL_SIP_SMC_STATUS_OK;
+       else if (*count == 0)
+               status = INTEL_SIP_SMC_STATUS_BUSY;
+
+       for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) {
+               if (fpga_config_buffers[i].write_requested != 0) {
+                       all_completed = 0;
+                       break;
+               }
+       }
+
+       if (all_completed == 1)
+               return INTEL_SIP_SMC_STATUS_OK;
+
+       return status;
+}
+
+int intel_fpga_config_start(uint32_t config_type)
+{
+       uint32_t response[3];
+       int status = 0;
+
+       status = mailbox_send_cmd(2, MBOX_RECONFIG, 0, 0, 0,
+                       response);
+
+       if (status < 0)
+               return status;
+
+       max_blocks = response[0];
+       bytes_per_block = response[1];
+
+       for (int i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) {
+               fpga_config_buffers[i].size = 0;
+               fpga_config_buffers[i].size_written = 0;
+               fpga_config_buffers[i].addr = 0;
+               fpga_config_buffers[i].write_requested = 0;
+               fpga_config_buffers[i].block_number = 0;
+               fpga_config_buffers[i].subblocks_sent = 0;
+       }
+
+       blocks_submitted = 0;
+       current_block = 0;
+       current_buffer = 0;
+
+       return 0;
+}
+
+
+uint32_t intel_fpga_config_write(uint64_t mem, uint64_t size)
+{
+       int i = 0;
+       uint32_t status = INTEL_SIP_SMC_STATUS_OK;
+
+       if (mem < DRAM_BASE || mem > DRAM_BASE + DRAM_SIZE)
+               status = INTEL_SIP_SMC_STATUS_REJECTED;
+
+       if (mem + size > DRAM_BASE + DRAM_SIZE)
+               status = INTEL_SIP_SMC_STATUS_REJECTED;
+
+       for (i = 0; i < FPGA_CONFIG_BUFFER_SIZE; i++) {
+               if (!fpga_config_buffers[i].write_requested) {
+                       fpga_config_buffers[i].addr = mem;
+                       fpga_config_buffers[i].size = size;
+                       fpga_config_buffers[i].size_written = 0;
+                       fpga_config_buffers[i].write_requested = 1;
+                       fpga_config_buffers[i].block_number =
+                               blocks_submitted++;
+                       fpga_config_buffers[i].subblocks_sent = 0;
+                       break;
+               }
+       }
+
+
+       if (i == FPGA_CONFIG_BUFFER_SIZE) {
+               status = INTEL_SIP_SMC_STATUS_REJECTED;
+               return status;
+       } else if (i == FPGA_CONFIG_BUFFER_SIZE - 1) {
+               status = INTEL_SIP_SMC_STATUS_BUSY;
+       }
+
+       intel_fpga_sdm_write_all();
+
+       return status;
+}
+
+/*
+ * This function is responsible for handling all SiP calls from the NS world
+ */
+
+uintptr_t sip_smc_handler(uint32_t smc_fid,
+                        u_register_t x1,
+                        u_register_t x2,
+                        u_register_t x3,
+                        u_register_t x4,
+                        void *cookie,
+                        void *handle,
+                        u_register_t flags)
+{
+       uint32_t status = INTEL_SIP_SMC_STATUS_OK;
+       uint32_t completed_addr[3];
+       uint32_t count = 0;
+
+       switch (smc_fid) {
+       case SIP_SVC_UID:
+               /* Return UID to the caller */
+               SMC_UUID_RET(handle, intl_svc_uid);
+               break;
+       case INTEL_SIP_SMC_FPGA_CONFIG_ISDONE:
+               status = intel_mailbox_fpga_config_isdone();
+               SMC_RET4(handle, status, 0, 0, 0);
+               break;
+       case INTEL_SIP_SMC_FPGA_CONFIG_GET_MEM:
+               SMC_RET3(handle, INTEL_SIP_SMC_STATUS_OK,
+                       INTEL_SIP_SMC_FPGA_CONFIG_ADDR,
+                       INTEL_SIP_SMC_FPGA_CONFIG_SIZE -
+                               INTEL_SIP_SMC_FPGA_CONFIG_ADDR);
+               break;
+       case INTEL_SIP_SMC_FPGA_CONFIG_START:
+               status = intel_fpga_config_start(x1);
+               SMC_RET4(handle, status, 0, 0, 0);
+               break;
+       case INTEL_SIP_SMC_FPGA_CONFIG_WRITE:
+               status = intel_fpga_config_write(x1, x2);
+               SMC_RET4(handle, status, 0, 0, 0);
+               break;
+       case INTEL_SIP_SMC_FPGA_CONFIG_COMPLETED_WRITE:
+               status = intel_fpga_config_completed_write(completed_addr,
+                                                               &count);
+               switch (count) {
+               case 1:
+                       SMC_RET4(handle, INTEL_SIP_SMC_STATUS_OK,
+                               completed_addr[0], 0, 0);
+                       break;
+               case 2:
+                       SMC_RET4(handle, INTEL_SIP_SMC_STATUS_OK,
+                               completed_addr[0],
+                               completed_addr[1], 0);
+                       break;
+               case 3:
+                       SMC_RET4(handle, INTEL_SIP_SMC_STATUS_OK,
+                               completed_addr[0],
+                               completed_addr[1],
+                               completed_addr[2]);
+                       break;
+               case 0:
+                       SMC_RET4(handle, status, 0, 0, 0);
+                       break;
+               default:
+                       SMC_RET1(handle, INTEL_SIP_SMC_STATUS_ERROR);
+               }
+               break;
+
+       default:
+               return socfpga_sip_handler(smc_fid, x1, x2, x3, x4,
+                       cookie, handle, flags);
+       }
+}
+
+DECLARE_RT_SVC(
+       agilex_sip_svc,
+       OEN_SIP_START,
+       OEN_SIP_END,
+       SMC_TYPE_FAST,
+       NULL,
+       sip_smc_handler
+);
+
+DECLARE_RT_SVC(
+       agilex_sip_svc_std,
+       OEN_SIP_START,
+       OEN_SIP_END,
+       SMC_TYPE_YIELD,
+       NULL,
+       sip_smc_handler
+);
diff --git a/plat/intel/soc/agilex/socfpga_storage.c b/plat/intel/soc/agilex/socfpga_storage.c
new file mode 100644 (file)
index 0000000..76dd81f
--- /dev/null
@@ -0,0 +1,193 @@
+/*
+ * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2019, Intel Corporation. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <arch_helpers.h>
+#include <assert.h>
+#include <common/debug.h>
+#include <common/tbbr/tbbr_img_def.h>
+#include <drivers/io/io_block.h>
+#include <drivers/io/io_driver.h>
+#include <drivers/io/io_fip.h>
+#include <drivers/io/io_memmap.h>
+#include <drivers/io/io_storage.h>
+#include <drivers/mmc.h>
+#include <drivers/partition/partition.h>
+#include <lib/mmio.h>
+#include <tools_share/firmware_image_package.h>
+
+#include "agilex_private.h"
+
+#define PLAT_FIP_BASE          (0)
+#define PLAT_FIP_MAX_SIZE      (0x1000000)
+#define PLAT_MMC_DATA_BASE     (0xffe3c000)
+#define PLAT_MMC_DATA_SIZE     (0x2000)
+#define PLAT_QSPI_DATA_BASE    (0x3C00000)
+#define PLAT_QSPI_DATA_SIZE    (0x1000000)
+
+
+static const io_dev_connector_t *fip_dev_con;
+static const io_dev_connector_t *boot_dev_con;
+
+static uintptr_t fip_dev_handle;
+static uintptr_t boot_dev_handle;
+
+static const io_uuid_spec_t bl2_uuid_spec = {
+       .uuid = UUID_TRUSTED_BOOT_FIRMWARE_BL2,
+};
+
+static const io_uuid_spec_t bl31_uuid_spec = {
+       .uuid = UUID_EL3_RUNTIME_FIRMWARE_BL31,
+};
+
+static const io_uuid_spec_t bl33_uuid_spec = {
+       .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33,
+};
+
+uintptr_t a2_lba_offset;
+const char a2[] = {0xa2, 0x0};
+
+static const io_block_spec_t gpt_block_spec = {
+       .offset = 0,
+       .length = MMC_BLOCK_SIZE
+};
+
+static int check_fip(const uintptr_t spec);
+static int check_dev(const uintptr_t spec);
+
+static io_block_dev_spec_t boot_dev_spec;
+static int (*register_io_dev)(const io_dev_connector_t **);
+
+static io_block_spec_t fip_spec = {
+       .offset         = PLAT_FIP_BASE,
+       .length         = PLAT_FIP_MAX_SIZE,
+};
+
+struct plat_io_policy {
+       uintptr_t       *dev_handle;
+       uintptr_t       image_spec;
+       int             (*check)(const uintptr_t spec);
+};
+
+static const struct plat_io_policy policies[] = {
+       [FIP_IMAGE_ID] = {
+               &boot_dev_handle,
+               (uintptr_t)&fip_spec,
+               check_dev
+       },
+       [BL2_IMAGE_ID] = {
+         &fip_dev_handle,
+         (uintptr_t)&bl2_uuid_spec,
+         check_fip
+       },
+       [BL31_IMAGE_ID] = {
+               &fip_dev_handle,
+               (uintptr_t)&bl31_uuid_spec,
+               check_fip
+       },
+       [BL33_IMAGE_ID] = {
+               &fip_dev_handle,
+               (uintptr_t) &bl33_uuid_spec,
+               check_fip
+       },
+       [GPT_IMAGE_ID] = {
+               &boot_dev_handle,
+               (uintptr_t) &gpt_block_spec,
+               check_dev
+       },
+};
+
+static int check_dev(const uintptr_t spec)
+{
+       int result;
+       uintptr_t local_handle;
+
+       result = io_dev_init(boot_dev_handle, (uintptr_t)NULL);
+       if (result == 0) {
+               result = io_open(boot_dev_handle, spec, &local_handle);
+               if (result == 0)
+                       io_close(local_handle);
+       }
+       return result;
+}
+
+static int check_fip(const uintptr_t spec)
+{
+       int result;
+       uintptr_t local_image_handle;
+
+       result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID);
+       if (result == 0) {
+               result = io_open(fip_dev_handle, spec, &local_image_handle);
+               if (result == 0)
+                       io_close(local_image_handle);
+       }
+       return result;
+}
+
+void socfpga_io_setup(int boot_source)
+{
+       int result;
+
+       switch (boot_source) {
+       case BOOT_SOURCE_SDMMC:
+               register_io_dev = &register_io_dev_block;
+               boot_dev_spec.buffer.offset     = PLAT_MMC_DATA_BASE;
+               boot_dev_spec.buffer.length     = MMC_BLOCK_SIZE;
+               boot_dev_spec.ops.read          = mmc_read_blocks;
+               boot_dev_spec.ops.write         = mmc_write_blocks;
+               boot_dev_spec.block_size        = MMC_BLOCK_SIZE;
+               break;
+
+       case BOOT_SOURCE_QSPI:
+               register_io_dev = &register_io_dev_memmap;
+               fip_spec.offset = fip_spec.offset + PLAT_QSPI_DATA_BASE;
+               break;
+
+       default:
+               ERROR("Unsupported boot source\n");
+               panic();
+               break;
+       }
+
+       result = (*register_io_dev)(&boot_dev_con);
+       assert(result == 0);
+
+       result = register_io_dev_fip(&fip_dev_con);
+       assert(result == 0);
+
+       result = io_dev_open(boot_dev_con, (uintptr_t)&boot_dev_spec,
+                       &boot_dev_handle);
+       assert(result == 0);
+
+       result = io_dev_open(fip_dev_con, (uintptr_t)NULL, &fip_dev_handle);
+       assert(result == 0);
+
+       if (boot_source == BOOT_SOURCE_SDMMC) {
+               partition_init(GPT_IMAGE_ID);
+               fip_spec.offset = get_partition_entry(a2)->start;
+       }
+
+       (void)result;
+}
+
+int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle,
+                       uintptr_t *image_spec)
+{
+       int result;
+       const struct plat_io_policy *policy;
+
+       assert(image_id < ARRAY_SIZE(policies));
+
+       policy = &policies[image_id];
+       result = policy->check(policy->image_spec);
+       assert(result == 0);
+
+       *image_spec = policy->image_spec;
+       *dev_handle = *(policy->dev_handle);
+
+       return result;
+}
diff --git a/plat/intel/soc/agilex/socfpga_topology.c b/plat/intel/soc/agilex/socfpga_topology.c
new file mode 100644 (file)
index 0000000..ca1a91e
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <arch.h>
+#include <platform_def.h>
+#include <lib/psci/psci.h>
+
+static const unsigned char plat_power_domain_tree_desc[] = {1, 4};
+
+/*******************************************************************************
+ * This function returns the default topology tree information.
+ ******************************************************************************/
+const unsigned char *plat_get_power_domain_tree_desc(void)
+{
+       return plat_power_domain_tree_desc;
+}
+
+/*******************************************************************************
+ * This function implements a part of the critical interface between the psci
+ * generic layer and the platform that allows the former to query the platform
+ * to convert an MPIDR to a unique linear index. An error code (-1) is returned
+ * in case the MPIDR is invalid.
+ ******************************************************************************/
+int plat_core_pos_by_mpidr(u_register_t mpidr)
+{
+       unsigned int cluster_id, cpu_id;
+
+       mpidr &= MPIDR_AFFINITY_MASK;
+
+       if (mpidr & ~(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK))
+               return -1;
+
+       cluster_id = (mpidr >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK;
+       cpu_id = (mpidr >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK;
+
+       if (cluster_id >= PLATFORM_CLUSTER_COUNT)
+               return -1;
+
+       /*
+        * Validate cpu_id by checking whether it represents a CPU in
+        * one of the two clusters present on the platform.
+        */
+       if (cpu_id >= PLATFORM_MAX_CPUS_PER_CLUSTER)
+               return -1;
+
+       return (cpu_id + (cluster_id * 4));
+}
+
index 4fb29223b092f6835a10fbb4c2dfaa51a414b98a..cfef5858c9562326cfb99b4dda0d85b0368e4e10 100644 (file)
@@ -34,7 +34,7 @@
 #define CAD_QSPI_CFG_CS(x)                     (((x) << 11))
 #define CAD_QSPI_CFG_ENABLE                    (1 << 0)
 #define CAD_QSPI_CFG_ENDMA_CLR_MSK             0xffff7fff
-#define CAD_QSPI_CFG_IDLE                      (1 << 31)
+#define CAD_QSPI_CFG_IDLE                      (1U << 31)
 #define CAD_QSPI_CFG_SELCLKPHASE_CLR_MSK       0xfffffffb
 #define CAD_QSPI_CFG_SELCLKPOL_CLR_MSK         0xfffffffd
 
index 78db52059930f0b2ae78d0d4a350dcdd7d1f3cae..554c26566a4a0cb5d7fdce3b019f7be1210e5571 100644 (file)
@@ -76,7 +76,7 @@
 #define RECONFIG_STATUS_STATE          0
 #define RECONFIG_STATUS_PIN_STATUS     2
 #define RECONFIG_STATUS_SOFTFUNC_STATUS 3
-#define PIN_STATUS_NSTATUS             (1 << 31)
+#define PIN_STATUS_NSTATUS             (1U << 31)
 #define SOFTFUNC_STATUS_SEU_ERROR      (1 << 3)
 #define SOFTFUNC_STATUS_INIT_DONE      (1 << 1)
 #define SOFTFUNC_STATUS_CONF_DONE      (1 << 0)
index 802386c8e29ae164f7cc9ffea929fb7c96ffe98d..4500c6fbd1932465cb58d64af9cb9b9af674aaf7 100644 (file)
 #define S10_CCU_NOC_CPU0_RAMSPACE0_0           0xf7004688
 #define S10_CCU_NOC_IOM_RAMSPACE0_0            0xf7018628
 
+#define S10_SYSMGR_CORE(x)                     (0xffd12000 + (x))
+#define SYSMGR_MMC                             0x28
+#define SYSMGR_MMC_DRVSEL(x)                   (((x) & 0x7) << 0)
+
+
 #define DISABLE_L4_FIREWALL    (BIT(0) | BIT(16) | BIT(24))
 
 void enable_nonsecure_access(void);
index 48f37d78d12d41ef2dbe20f411d3b4d88f72346a..a2ed5a3edb43df15fac7ca1181d7f8de43c82ef4 100644 (file)
@@ -86,5 +86,8 @@ void enable_nonsecure_access(void)
 
        mmio_clrbits_32(S10_CCU_NOC_CPU0_RAMSPACE0_0, 0x03);
        mmio_clrbits_32(S10_CCU_NOC_IOM_RAMSPACE0_0, 0x03);
+
+       mmio_write_32(S10_SYSMGR_CORE(SYSMGR_MMC), SYSMGR_MMC_DRVSEL(3));
+
 }
 
index d6429c326103d842dc3d6411bfff90401d94984a..8e282cbad845b5079372f70a0fb7b03c3453d9e9 100644 (file)
@@ -66,12 +66,12 @@ static void ls1043_reset_core(int core_pos)
        dsb();
        /* enable core soft reset */
        mmio_write_32(LS_SCFG_BASE + LS_SCFG_CORESRENCR_OFFSET,
-                     htobe32(1 << 31));
+                     htobe32(1U << 31));
        dsb();
        isb();
        /* reset core */
        mmio_write_32(LS_SCFG_BASE + LS_SCFG_CORE0_SFT_RST_OFFSET +
-                       core_pos * 4, htobe32(1 << 31));
+                       core_pos * 4, htobe32(1U << 31));
        mdelay(10);
 }
 
index 3d8b262d29733f82bcbc5cc7065fc39165c3d507..cba55caffd29812649d1e5f9e44246d6d44e5cbc 100644 (file)
@@ -35,7 +35,7 @@ void get_gic_offset(uint32_t *gicc_base, uint32_t *gicd_base)
                        soc_dev_id == (SVR_LS1043AE << 8)) &&
                        ((val & 0xff) == REV1_1)) {
                val = be32toh(mmio_read_32((uintptr_t)gic_align));
-               if (val & (1 << GIC_ADDR_BIT)) {
+               if (val & (1U << GIC_ADDR_BIT)) {
                        *gicc_base = GICC_BASE;
                        *gicd_base = GICD_BASE;
                } else {
index 76c34189312ed28245db12fc4b29f31388b2239b..a5dc8557b3ee76eafdb191fd6cd6e78e9143211f 100644 (file)
@@ -9,9 +9,9 @@
 
 #include <stdint.h>
 
-#define SVR_WO_E               0xFFFFFE
-#define SVR_LS1043A            0x879204
-#define SVR_LS1043AE           0x879200
+#define SVR_WO_E               0xFFFFFEu
+#define SVR_LS1043A            0x879204u
+#define SVR_LS1043AE           0x879200u
 
 void get_gic_offset(uint32_t *gicc_base, uint32_t *gicd_base);
 
index 8b7cd6486e6179f5466a099ec273462d60f0a4f1..de8031536c0d2b3cd6276d14a41072a7f1c441fe 100644 (file)
@@ -18,7 +18,7 @@
 #define GWD_IIDR2_REV_ID_OFFSET                12
 #define GWD_IIDR2_REV_ID_MASK          0xF
 #define GWD_IIDR2_CHIP_ID_OFFSET       20
-#define GWD_IIDR2_CHIP_ID_MASK         (0xFFF << GWD_IIDR2_CHIP_ID_OFFSET)
+#define GWD_IIDR2_CHIP_ID_MASK         (0xFFFu << GWD_IIDR2_CHIP_ID_OFFSET)
 
 #define CHIP_ID_AP806                  0x806
 #define CHIP_ID_AP807                  0x807
index 0590cc0aef96c5135fbeb1e5d58727a20396b2bb..7f9e242786c88a1230b22183d155d72dec635f1c 100644 (file)
 /* VDD limit is 0.82V for all A3900 devices
  * AVS offsets are not the same as in A70x0
  */
-#define AVS_A3900_CLK_VALUE            ((0x80 << 24) | \
+#define AVS_A3900_CLK_VALUE            ((0x80u << 24) | \
                                         (0x2c2 << 13) | \
                                         (0x2c2 << 3) | \
                                         (0x1 << AVS_SOFT_RESET_OFFSET) | \
                                         (0x1 << AVS_ENABLE_OFFSET))
 /* VDD is 0.88V for 2GHz clock */
-#define AVS_A3900_HIGH_CLK_VALUE       ((0x80 << 24) | \
+#define AVS_A3900_HIGH_CLK_VALUE       ((0x80u << 24) | \
                                         (0x2f5 << 13) | \
                                         (0x2f5 << 3) | \
                                         (0x1 << AVS_SOFT_RESET_OFFSET) | \
index e2575b13c16790617bf8807b445535c69fc4b717..d07601a5f7708413bee5275214571b31f0fd98e1 100644 (file)
@@ -93,7 +93,7 @@ enum CPU_ID {
 #define PWRC_CPUN_CR_ISO_ENABLE_MASK           \
                        (0x1 << PWRC_CPUN_CR_ISO_ENABLE_OFFSET)
 #define PWRC_CPUN_CR_LDO_BYPASS_RDY_MASK       \
-                       (0x1 << PWRC_CPUN_CR_LDO_BYPASS_RDY_OFFSET)
+                       (0x1U << PWRC_CPUN_CR_LDO_BYPASS_RDY_OFFSET)
 
 #define CCU_B_PRCRN_REG(cpu_id)                        \
                        (MVEBU_REGS_BASE + 0x1A50 + \
@@ -253,7 +253,7 @@ static int plat_marvell_cpu_powerup(u_register_t mpidr)
 
        /* 3. Assert power ready */
        reg_val = mmio_read_32(PWRC_CPUN_CR_REG(cpu_id));
-       reg_val |= 0x1 << PWRC_CPUN_CR_LDO_BYPASS_RDY_OFFSET;
+       reg_val |= 0x1U << PWRC_CPUN_CR_LDO_BYPASS_RDY_OFFSET;
        mmio_write_32(PWRC_CPUN_CR_REG(cpu_id), reg_val);
 
        /* 4. Read & Validate power ready
@@ -262,7 +262,7 @@ static int plat_marvell_cpu_powerup(u_register_t mpidr)
        do {
                reg_val = mmio_read_32(PWRC_CPUN_CR_REG(cpu_id));
                exit_loop--;
-       } while (!(reg_val & (0x1 << PWRC_CPUN_CR_LDO_BYPASS_RDY_OFFSET)) &&
+       } while (!(reg_val & (0x1U << PWRC_CPUN_CR_LDO_BYPASS_RDY_OFFSET)) &&
                 exit_loop > 0);
 
        if (exit_loop <= 0)
index c13e22adec44b39d54cb4e5462d2cc3c7ad3a68b..8a588bfb3e6035a9af0d0cfb7e629b4e7c675479 100644 (file)
@@ -41,7 +41,7 @@
 #define BD_CTRL_REG                    0x40
 
 /* Snoop Control register bit definitions */
-#define DVM_SUPPORT                    (1 << 31)
+#define DVM_SUPPORT                    (1U << 31)
 #define SNP_SUPPORT                    (1 << 30)
 #define SHAREABLE_OVWRT                        (1 << 2)
 #define DVM_EN_BIT                     (1 << 1)
index c84f2a7dbaef01662cc82241a34f634d5c7f8e64..83ee88fac134c3d3b06c76118ab85ddca515177d 100644 (file)
@@ -197,7 +197,7 @@ enum {
        MP0_CPUCFG_64BIT_SHIFT = 12,
        MP1_CPUCFG_64BIT_SHIFT = 28,
        MP0_CPUCFG_64BIT = 0xf << MP0_CPUCFG_64BIT_SHIFT,
-       MP1_CPUCFG_64BIT = 0xf << MP1_CPUCFG_64BIT_SHIFT
+       MP1_CPUCFG_64BIT = 0xfu << MP1_CPUCFG_64BIT_SHIFT
 };
 
 /* scu related */
index 78209882e110f90e8422691e5be9e35d50012217..bc9022bb433bb914fa280954275380c706c0614b 100644 (file)
@@ -180,7 +180,7 @@ INTR_PROP_DESC(MT_IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY, grp, \
 #define MTK_WDT_STATUS_SECURITY_RST         (1 << 28)
 #define MTK_WDT_STATUS_IRQ_ASSERT           (1 << 29)
 #define MTK_WDT_STATUS_SW_WDT_RST           (1 << 30)
-#define MTK_WDT_STATUS_HW_WDT_RST           (1 << 31)
+#define MTK_WDT_STATUS_HW_WDT_RST           (1U << 31)
 
 /* RGU other related */
 #define MTK_WDT_MODE_DUAL_MODE    0x0040
index ff56f927742d4b62570fe2fa4646d2d3b5aaff02..2d400e0649609302ab1420a8b8e3a756b1c4ddd8 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <arch_helpers.h>
 
-#define VERSION_OF_RENESAS             "2.0.3"
+#define VERSION_OF_RENESAS             "2.0.4"
 #define        VERSION_OF_RENESAS_MAXLEN       (128)
 
 extern const uint8_t version_of_renesas[VERSION_OF_RENESAS_MAXLEN];
index d24d71af3b4d455127c5fd229c7f03faf5a7b524..4ea753f2db8c1eeb70e224b5c31299ba1970e9e7 100644 (file)
 #define MSTP318                        (1 << 18)
 #define MSTP319                        (1 << 19)
 #define PMSR                   0x5c
-#define PMSR_L1FAEG            (1 << 31)
+#define PMSR_L1FAEG            (1U << 31)
 #define PMSR_PMEL1RX           (1 << 23)
 #define PMCTLR                 0x60
-#define PMSR_L1IATN            (1 << 31)
+#define PMSR_L1IATN            (1U << 31)
 
 static int rcar_pcie_fixup(unsigned int controller)
 {
index c215ee2400e3cc09a32c653ef6cb479b8b2204cd..a17fef9e10a77825f358da71767274f5ed365f90 100644 (file)
@@ -284,7 +284,7 @@ static inline void pm_pll_wait_lock(uint32_t pll_id)
 static inline void pll_pwr_dwn(uint32_t pll_id, uint32_t pd)
 {
        mmio_write_32(CRU_BASE + PLL_CONS(pll_id, 1),
-                     BITS_WITH_WMASK(1, 1, 15));
+                     BITS_WITH_WMASK(1U, 1U, 15));
        if (pd)
                mmio_write_32(CRU_BASE + PLL_CONS(pll_id, 1),
                              BITS_WITH_WMASK(1, 1, 14));
@@ -305,7 +305,7 @@ static __sramfunc void dpll_suspend(void)
                sram_data.dpll_con_save[i] =
                                mmio_read_32(CRU_BASE + PLL_CONS(DPLL_ID, i));
        mmio_write_32(CRU_BASE + PLL_CONS(DPLL_ID, 1),
-                     BITS_WITH_WMASK(1, 1, 15));
+                     BITS_WITH_WMASK(1U, 1U, 15));
        mmio_write_32(CRU_BASE + PLL_CONS(DPLL_ID, 1),
                      BITS_WITH_WMASK(1, 1, 14));
 }
@@ -315,7 +315,7 @@ static __sramfunc void dpll_resume(void)
        uint32_t delay = PLL_LOCKED_TIMEOUT;
 
        mmio_write_32(CRU_BASE + PLL_CONS(DPLL_ID, 1),
-                     BITS_WITH_WMASK(1, 1, 15));
+                     BITS_WITH_WMASK(1U, 1U, 15));
        mmio_write_32(CRU_BASE + PLL_CONS(DPLL_ID, 1),
                      BITS_WITH_WMASK(0, 1, 14));
        mmio_write_32(CRU_BASE + PLL_CONS(DPLL_ID, 1),
@@ -402,7 +402,7 @@ static void pm_plls_suspend(void)
        /* clk_rtc32k */
        mmio_write_32(CRU_BASE + CRU_CLKSEL_CON(38),
                      BITS_WITH_WMASK(767, 0x3fff, 0) |
-                     BITS_WITH_WMASK(2, 0x3, 14));
+                     BITS_WITH_WMASK(2U, 0x3u, 14));
 }
 
 static void pm_plls_resume(void)
@@ -411,7 +411,7 @@ static void pm_plls_resume(void)
        mmio_write_32(CRU_BASE + CRU_CLKSEL_CON(38),
                      ddr_data.clk_sel38 |
                      BITS_WMSK(0x3fff, 0) |
-                     BITS_WMSK(0x3, 14));
+                     BITS_WMSK(0x3u, 14));
 
        /* uart2 */
        mmio_write_32(CRU_BASE + CRU_CLKSEL_CON(18),
@@ -483,7 +483,7 @@ __sramfunc void  rk3328_pmic_resume(void)
        mmio_write_32(GPIO2_BASE, sram_data.pmic_sleep_gpio_save[0]);
        mmio_write_32(GPIO2_BASE + 4, sram_data.pmic_sleep_gpio_save[1]);
        mmio_write_32(GRF_BASE + PMIC_SLEEP_REG,
-                     sram_data.pmic_sleep_save | BITS_WMSK(0xffff, 0));
+                     sram_data.pmic_sleep_save | BITS_WMSK(0xffffu, 0));
        /* Resuming volt need a lot of time */
        sram_udelay(100);
 }
index 84d265476960a2fe7ffacf18f25daa00d0011489..fa98eb3aeef1d649b4eef4395ab719df3b47742c 100644 (file)
@@ -400,7 +400,7 @@ void ddr_reg_save(uint32_t pllpdstat, uint64_t base_addr)
                p_ddr_reg->dpllcon[0] = (mmio_read_32(CRU_BASE +
                                                      PLL_CONS(DPLL_ID, 0))
                                                        & 0xffff) |
-                                       (0xFFFF << 16);
+                                       (0xFFFFu << 16);
                p_ddr_reg->dpllcon[1] = (mmio_read_32(CRU_BASE +
                                                      PLL_CONS(DPLL_ID, 1))
                                                        & 0xffff);
@@ -410,7 +410,7 @@ void ddr_reg_save(uint32_t pllpdstat, uint64_t base_addr)
                p_ddr_reg->dpllcon[3] = (mmio_read_32(CRU_BASE +
                                                      PLL_CONS(DPLL_ID, 3))
                                                        & 0xffff) |
-                                       (0xFFFF << 16);
+                                       (0xFFFFu << 16);
        } else {
                ddr_get_dpll_cfg(&p_ddr_reg->dpllcon[0]);
        }
index 15912b5d395facf049a49fd0dd88503b0eb0d1fa..6663bcb1684c3723c14e8c6ec745f745eb9018c8 100644 (file)
 #define DDRPHY0_SRSTN_REQ(n)   (((0x1 << 0) << 16) | (n << 0))
 
 /* CRU_DPLL_CON2 */
-#define DPLL_STATUS_LOCK               (1 << 31)
+#define DPLL_STATUS_LOCK               (1U << 31)
 
 /* CRU_DPLL_CON3 */
 #define DPLL_POWER_DOWN                        ((0x1 << (1 + 16)) | (0 << 1))
 #define DDR_PLL_SRC_MASK               0x13
 
 /* DDR_PCTL_TREFI */
-#define DDR_UPD_REF_ENABLE             (0X1 << 31)
+#define DDR_UPD_REF_ENABLE             (0X1u << 31)
 
 uint32_t ddr_get_resume_code_size(void);
 uint32_t ddr_get_resume_data_size(void);
index 5f24e93561aeb576ac3cdb392d4f3b4f5d9a15a5..6c7a01b34aa998124168ae8635e94ef1d5e76f0c 100644 (file)
@@ -50,7 +50,7 @@ enum plls_id {
 #define PMUSRAM_S              1
 #define STIMER_S_SHIFT         6
 #define STIMER_S               1
-#define SGRF_SOC_CON7_BITS     ((0xffff << 16) | \
+#define SGRF_SOC_CON7_BITS     ((0xffffu << 16) | \
                                 (PMUSRAM_S << PMUSRAM_S_SHIFT) | \
                                 (STIMER_S << STIMER_S_SHIFT))
 
index 45fd9240ed5271da58282073611ec6c50e736b79..3b627d287f6049d92dbca8b0c63e71df91c17052 100644 (file)
@@ -504,7 +504,7 @@ static void gen_rk3399_ctl_params_f0(struct timing_related_config
                                      (pdram_timing->tmod << 8) |
                                       pdram_timing->tmrd);
 
-                       mmio_clrsetbits_32(CTL_REG(i, 59), 0xffff << 16,
+                       mmio_clrsetbits_32(CTL_REG(i, 59), 0xffffu << 16,
                                           (pdram_timing->txsr -
                                            pdram_timing->trcd) << 16);
                } else if (timing_config->dram_type == LPDDR4) {
@@ -513,7 +513,7 @@ static void gen_rk3399_ctl_params_f0(struct timing_related_config
                        mmio_write_32(CTL_REG(i, 32),
                                      (pdram_timing->tmrd << 8) |
                                      pdram_timing->tmrd);
-                       mmio_clrsetbits_32(CTL_REG(i, 59), 0xffff << 16,
+                       mmio_clrsetbits_32(CTL_REG(i, 59), 0xffffu << 16,
                                           pdram_timing->txsr << 16);
                } else {
                        mmio_write_32(CTL_REG(i, 5), pdram_timing->tinit1);
@@ -521,7 +521,7 @@ static void gen_rk3399_ctl_params_f0(struct timing_related_config
                        mmio_write_32(CTL_REG(i, 32),
                                      (pdram_timing->tmrd << 8) |
                                      pdram_timing->tmrd);
-                       mmio_clrsetbits_32(CTL_REG(i, 59), 0xffff << 16,
+                       mmio_clrsetbits_32(CTL_REG(i, 59), 0xffffu << 16,
                                           pdram_timing->txsr << 16);
                }
                mmio_write_32(CTL_REG(i, 6), pdram_timing->tinit3);
@@ -531,7 +531,7 @@ static void gen_rk3399_ctl_params_f0(struct timing_related_config
                mmio_clrsetbits_32(CTL_REG(i, 23), (0x1f << 24),
                                   (pdram_timing->cwl << 24));
                mmio_clrsetbits_32(CTL_REG(i, 24), 0x3f, pdram_timing->al);
-               mmio_clrsetbits_32(CTL_REG(i, 26), 0xffff << 16,
+               mmio_clrsetbits_32(CTL_REG(i, 26), 0xffffu << 16,
                                   (pdram_timing->trc << 24) |
                                   (pdram_timing->trrd << 16));
                mmio_write_32(CTL_REG(i, 27),
@@ -540,7 +540,7 @@ static void gen_rk3399_ctl_params_f0(struct timing_related_config
                              (pdram_timing->twtr << 8) |
                              pdram_timing->tras_min);
 
-               mmio_clrsetbits_32(CTL_REG(i, 31), 0xff << 24,
+               mmio_clrsetbits_32(CTL_REG(i, 31), 0xffu << 24,
                                   max(4, pdram_timing->trtp) << 24);
                mmio_write_32(CTL_REG(i, 33), (pdram_timing->tcke << 24) |
                                              pdram_timing->tras_max);
@@ -560,7 +560,7 @@ static void gen_rk3399_ctl_params_f0(struct timing_related_config
                              ((pdram_timing->trefi - 8) << 16) |
                              pdram_timing->trfc);
                mmio_clrsetbits_32(CTL_REG(i, 52), 0xffff, pdram_timing->txp);
-               mmio_clrsetbits_32(CTL_REG(i, 53), 0xffff << 16,
+               mmio_clrsetbits_32(CTL_REG(i, 53), 0xffffu << 16,
                                   pdram_timing->txpdll << 16);
                mmio_clrsetbits_32(CTL_REG(i, 55), 0xf << 24,
                                   pdram_timing->tcscke << 24);
@@ -571,7 +571,7 @@ static void gen_rk3399_ctl_params_f0(struct timing_related_config
                              (pdram_timing->tckehcs << 8) |
                              pdram_timing->tckelcs);
                mmio_clrsetbits_32(CTL_REG(i, 60), 0xffff, pdram_timing->txsnr);
-               mmio_clrsetbits_32(CTL_REG(i, 62), 0xffff << 16,
+               mmio_clrsetbits_32(CTL_REG(i, 62), 0xffffu << 16,
                                   (pdram_timing->tckehcmd << 24) |
                                   (pdram_timing->tckelcmd << 16));
                mmio_write_32(CTL_REG(i, 63),
@@ -601,7 +601,7 @@ static void gen_rk3399_ctl_params_f0(struct timing_related_config
                                   pdram_timing->mr[2]);
                mmio_clrsetbits_32(CTL_REG(i, 138), 0xffff,
                                   pdram_timing->mr[3]);
-               mmio_clrsetbits_32(CTL_REG(i, 139), 0xff << 24,
+               mmio_clrsetbits_32(CTL_REG(i, 139), 0xffu << 24,
                                   pdram_timing->mr11 << 24);
                mmio_write_32(CTL_REG(i, 147),
                              (pdram_timing->mr[1] << 16) |
@@ -610,20 +610,20 @@ static void gen_rk3399_ctl_params_f0(struct timing_related_config
                                   pdram_timing->mr[2]);
                mmio_clrsetbits_32(CTL_REG(i, 152), 0xffff,
                                   pdram_timing->mr[3]);
-               mmio_clrsetbits_32(CTL_REG(i, 153), 0xff << 24,
+               mmio_clrsetbits_32(CTL_REG(i, 153), 0xffu << 24,
                                   pdram_timing->mr11 << 24);
                if (timing_config->dram_type == LPDDR4) {
-                       mmio_clrsetbits_32(CTL_REG(i, 140), 0xffff << 16,
+                       mmio_clrsetbits_32(CTL_REG(i, 140), 0xffffu << 16,
                                           pdram_timing->mr12 << 16);
-                       mmio_clrsetbits_32(CTL_REG(i, 142), 0xffff << 16,
+                       mmio_clrsetbits_32(CTL_REG(i, 142), 0xffffu << 16,
                                           pdram_timing->mr14 << 16);
-                       mmio_clrsetbits_32(CTL_REG(i, 145), 0xffff << 16,
+                       mmio_clrsetbits_32(CTL_REG(i, 145), 0xffffu << 16,
                                           pdram_timing->mr22 << 16);
-                       mmio_clrsetbits_32(CTL_REG(i, 154), 0xffff << 16,
+                       mmio_clrsetbits_32(CTL_REG(i, 154), 0xffffu << 16,
                                           pdram_timing->mr12 << 16);
-                       mmio_clrsetbits_32(CTL_REG(i, 156), 0xffff << 16,
+                       mmio_clrsetbits_32(CTL_REG(i, 156), 0xffffu << 16,
                                           pdram_timing->mr14 << 16);
-                       mmio_clrsetbits_32(CTL_REG(i, 159), 0xffff << 16,
+                       mmio_clrsetbits_32(CTL_REG(i, 159), 0xffffu << 16,
                                           pdram_timing->mr22 << 16);
                }
                mmio_clrsetbits_32(CTL_REG(i, 179), 0xfff << 8,
@@ -655,7 +655,7 @@ static void gen_rk3399_ctl_params_f0(struct timing_related_config
                     << 8) | get_rdlat_adj(timing_config->dram_type,
                                           pdram_timing->cl);
                mmio_clrsetbits_32(CTL_REG(i, 284), 0xffff, tmp);
-               mmio_clrsetbits_32(CTL_REG(i, 82), 0xffff << 16,
+               mmio_clrsetbits_32(CTL_REG(i, 82), 0xffffu << 16,
                                   (4 * pdram_timing->trefi) << 16);
 
                mmio_clrsetbits_32(CTL_REG(i, 83), 0xffff,
@@ -748,13 +748,13 @@ static void gen_rk3399_ctl_params_f1(struct timing_related_config
                        tmp += pdram_timing->txsnr + (pdram_timing->tmrd * 3) +
                               pdram_timing->tmod + pdram_timing->tzqinit;
                        mmio_write_32(CTL_REG(i, 9), tmp);
-                       mmio_clrsetbits_32(CTL_REG(i, 22), 0xffff << 16,
+                       mmio_clrsetbits_32(CTL_REG(i, 22), 0xffffu << 16,
                                           pdram_timing->tdllk << 16);
                        mmio_clrsetbits_32(CTL_REG(i, 34), 0xffffff00,
                                           (pdram_timing->tmod << 24) |
                                           (pdram_timing->tmrd << 16) |
                                           (pdram_timing->trtp << 8));
-                       mmio_clrsetbits_32(CTL_REG(i, 60), 0xffff << 16,
+                       mmio_clrsetbits_32(CTL_REG(i, 60), 0xffffu << 16,
                                           (pdram_timing->txsr -
                                            pdram_timing->trcd) << 16);
                } else if (timing_config->dram_type == LPDDR4) {
@@ -764,7 +764,7 @@ static void gen_rk3399_ctl_params_f1(struct timing_related_config
                                           (pdram_timing->tmrd << 24) |
                                           (pdram_timing->tmrd << 16) |
                                           (pdram_timing->trtp << 8));
-                       mmio_clrsetbits_32(CTL_REG(i, 60), 0xffff << 16,
+                       mmio_clrsetbits_32(CTL_REG(i, 60), 0xffffu << 16,
                                           pdram_timing->txsr << 16);
                } else {
                        mmio_write_32(CTL_REG(i, 9), pdram_timing->tinit1);
@@ -773,7 +773,7 @@ static void gen_rk3399_ctl_params_f1(struct timing_related_config
                                           (pdram_timing->tmrd << 24) |
                                           (pdram_timing->tmrd << 16) |
                                           (pdram_timing->trtp << 8));
-                       mmio_clrsetbits_32(CTL_REG(i, 60), 0xffff << 16,
+                       mmio_clrsetbits_32(CTL_REG(i, 60), 0xffffu << 16,
                                           pdram_timing->txsr << 16);
                }
                mmio_write_32(CTL_REG(i, 10), pdram_timing->tinit3);
@@ -796,7 +796,7 @@ static void gen_rk3399_ctl_params_f1(struct timing_related_config
                                              pdram_timing->tras_max);
                mmio_clrsetbits_32(CTL_REG(i, 36), 0xff,
                                   max(1, pdram_timing->tckesr));
-               mmio_clrsetbits_32(CTL_REG(i, 39), (0xff << 24),
+               mmio_clrsetbits_32(CTL_REG(i, 39), (0xffu << 24),
                                   (pdram_timing->trcd << 24));
                mmio_clrsetbits_32(CTL_REG(i, 40), 0x3f, pdram_timing->twr);
                mmio_clrsetbits_32(CTL_REG(i, 42), 0x1f << 24,
@@ -809,7 +809,7 @@ static void gen_rk3399_ctl_params_f1(struct timing_related_config
                mmio_write_32(CTL_REG(i, 49),
                              ((pdram_timing->trefi - 8) << 16) |
                              pdram_timing->trfc);
-               mmio_clrsetbits_32(CTL_REG(i, 52), 0xffff << 16,
+               mmio_clrsetbits_32(CTL_REG(i, 52), 0xffffu << 16,
                                   pdram_timing->txp << 16);
                mmio_clrsetbits_32(CTL_REG(i, 54), 0xffff,
                                   pdram_timing->txpdll);
@@ -821,7 +821,7 @@ static void gen_rk3399_ctl_params_f1(struct timing_related_config
                                              pdram_timing->tcscke);
                mmio_clrsetbits_32(CTL_REG(i, 58), 0xf, pdram_timing->tzqcke);
                mmio_clrsetbits_32(CTL_REG(i, 61), 0xffff, pdram_timing->txsnr);
-               mmio_clrsetbits_32(CTL_REG(i, 64), 0xffff << 16,
+               mmio_clrsetbits_32(CTL_REG(i, 64), 0xffffu << 16,
                                   (pdram_timing->tckehcmd << 24) |
                                   (pdram_timing->tckelcmd << 16));
                mmio_write_32(CTL_REG(i, 65), (pdram_timing->tckelpd << 24) |
@@ -831,7 +831,7 @@ static void gen_rk3399_ctl_params_f1(struct timing_related_config
                mmio_clrsetbits_32(CTL_REG(i, 66), 0xfff,
                                   (pdram_timing->tcmdcke << 8) |
                                   pdram_timing->tcsckeh);
-               mmio_clrsetbits_32(CTL_REG(i, 92), (0xff << 24),
+               mmio_clrsetbits_32(CTL_REG(i, 92), (0xffu << 24),
                                   (pdram_timing->tcksre << 24));
                mmio_clrsetbits_32(CTL_REG(i, 93), 0xff,
                                   pdram_timing->tcksrx);
@@ -845,18 +845,18 @@ static void gen_rk3399_ctl_params_f1(struct timing_related_config
                                               pdram_timing->tfc_long);
                mmio_clrsetbits_32(CTL_REG(i, 127), 0xffff,
                                   pdram_timing->tvref_long);
-               mmio_clrsetbits_32(CTL_REG(i, 134), 0xffff << 16,
+               mmio_clrsetbits_32(CTL_REG(i, 134), 0xffffu << 16,
                                   pdram_timing->mr[0] << 16);
                mmio_write_32(CTL_REG(i, 135), (pdram_timing->mr[2] << 16) |
                                               pdram_timing->mr[1]);
-               mmio_clrsetbits_32(CTL_REG(i, 138), 0xffff << 16,
+               mmio_clrsetbits_32(CTL_REG(i, 138), 0xffffu << 16,
                                   pdram_timing->mr[3] << 16);
                mmio_clrsetbits_32(CTL_REG(i, 140), 0xff, pdram_timing->mr11);
-               mmio_clrsetbits_32(CTL_REG(i, 148), 0xffff << 16,
+               mmio_clrsetbits_32(CTL_REG(i, 148), 0xffffu << 16,
                                   pdram_timing->mr[0] << 16);
                mmio_write_32(CTL_REG(i, 149), (pdram_timing->mr[2] << 16) |
                                               pdram_timing->mr[1]);
-               mmio_clrsetbits_32(CTL_REG(i, 152), 0xffff << 16,
+               mmio_clrsetbits_32(CTL_REG(i, 152), 0xffffu << 16,
                                   pdram_timing->mr[3] << 16);
                mmio_clrsetbits_32(CTL_REG(i, 154), 0xff, pdram_timing->mr11);
                if (timing_config->dram_type == LPDDR4) {
@@ -907,7 +907,7 @@ static void gen_rk3399_ctl_params_f1(struct timing_related_config
                mmio_clrsetbits_32(CTL_REG(i, 84), 0xffff,
                                   (4 * pdram_timing->trefi) & 0xffff);
 
-               mmio_clrsetbits_32(CTL_REG(i, 84), 0xffff << 16,
+               mmio_clrsetbits_32(CTL_REG(i, 84), 0xffffu << 16,
                                   ((2 * pdram_timing->trefi) & 0xffff) << 16);
 
                if ((timing_config->dram_type == LPDDR3) ||
@@ -936,12 +936,12 @@ static void gen_rk3399_ctl_params_f1(struct timing_related_config
                mmio_clrsetbits_32(CTL_REG(i, 215), 0x3f << 16,
                                   (tmp & 0x3f) << 16);
 
-               mmio_clrsetbits_32(CTL_REG(i, 275), 0xff << 24,
+               mmio_clrsetbits_32(CTL_REG(i, 275), 0xffu << 24,
                                   (get_pi_tdfi_phy_rdlat(pdram_timing,
                                                          timing_config) &
                                    0xff) << 24);
 
-               mmio_clrsetbits_32(CTL_REG(i, 284), 0xffff << 16,
+               mmio_clrsetbits_32(CTL_REG(i, 284), 0xffffu << 16,
                                   ((2 * pdram_timing->trefi) & 0xffff) << 16);
 
                mmio_clrsetbits_32(CTL_REG(i, 289), 0xffff,
@@ -973,7 +973,7 @@ static void gen_rk3399_ctl_params_f1(struct timing_related_config
                        tmp = tmp1 - 2;
                }
 
-               mmio_clrsetbits_32(CTL_REG(i, 314), 0xff << 24, tmp << 24);
+               mmio_clrsetbits_32(CTL_REG(i, 314), 0xffu << 24, tmp << 24);
 
                /* CTL_314 TDFI_RDCSLAT_F1:RW:16:8 */
                if ((timing_config->freq <= TDFI_LAT_THRESHOLD_FREQ) &&
@@ -1036,7 +1036,7 @@ static void gen_rk3399_pi_params_f0(struct timing_related_config *timing_config,
                tmp = 2 * pdram_timing->trefi;
                mmio_clrsetbits_32(PI_REG(i, 3), 0xffff, tmp);
                /* PI_07 PI_TDFI_PHYUPD_RESP_F0:RW:16:16 */
-               mmio_clrsetbits_32(PI_REG(i, 7), 0xffff << 16, tmp << 16);
+               mmio_clrsetbits_32(PI_REG(i, 7), 0xffffu << 16, tmp << 16);
 
                /* PI_42 PI_TDELAY_RDWR_2_BUS_IDLE_F0:RW:0:8 */
                if (timing_config->dram_type == LPDDR4)
@@ -1060,14 +1060,14 @@ static void gen_rk3399_pi_params_f0(struct timing_related_config *timing_config,
                mmio_clrsetbits_32(PI_REG(i, 43), 0x7f << 16,
                                   (pdram_timing->cl * 2) << 16);
                /* PI_46 PI_TREF_F0:RW:16:16 */
-               mmio_clrsetbits_32(PI_REG(i, 46), 0xffff << 16,
+               mmio_clrsetbits_32(PI_REG(i, 46), 0xffffu << 16,
                                   pdram_timing->trefi << 16);
                /* PI_46 PI_TRFC_F0:RW:0:10 */
                mmio_clrsetbits_32(PI_REG(i, 46), 0x3ff, pdram_timing->trfc);
                /* PI_66 PI_TODTL_2CMD_F0:RW:24:8 */
                if (timing_config->dram_type == LPDDR3) {
                        tmp = get_pi_todtoff_max(pdram_timing, timing_config);
-                       mmio_clrsetbits_32(PI_REG(i, 66), 0xff << 24,
+                       mmio_clrsetbits_32(PI_REG(i, 66), 0xffu << 24,
                                           tmp << 24);
                }
                /* PI_72 PI_WR_TO_ODTH_F0:RW:16:6 */
@@ -1148,19 +1148,19 @@ static void gen_rk3399_pi_params_f0(struct timing_related_config *timing_config,
                /* PI_133 PI_MR1_DATA_F0_1:RW+:0:16 */
                mmio_clrsetbits_32(PI_REG(i, 133), 0xffff, pdram_timing->mr[1]);
                /* PI_140 PI_MR1_DATA_F0_2:RW+:16:16 */
-               mmio_clrsetbits_32(PI_REG(i, 140), 0xffff << 16,
+               mmio_clrsetbits_32(PI_REG(i, 140), 0xffffu << 16,
                                   pdram_timing->mr[1] << 16);
                /* PI_148 PI_MR1_DATA_F0_3:RW+:0:16 */
                mmio_clrsetbits_32(PI_REG(i, 148), 0xffff, pdram_timing->mr[1]);
                /* PI_126 PI_MR2_DATA_F0_0:RW+:0:16 */
                mmio_clrsetbits_32(PI_REG(i, 126), 0xffff, pdram_timing->mr[2]);
                /* PI_133 PI_MR2_DATA_F0_1:RW+:16:16 */
-               mmio_clrsetbits_32(PI_REG(i, 133), 0xffff << 16,
+               mmio_clrsetbits_32(PI_REG(i, 133), 0xffffu << 16,
                                   pdram_timing->mr[2] << 16);
                /* PI_141 PI_MR2_DATA_F0_2:RW+:0:16 */
                mmio_clrsetbits_32(PI_REG(i, 141), 0xffff, pdram_timing->mr[2]);
                /* PI_148 PI_MR2_DATA_F0_3:RW+:16:16 */
-               mmio_clrsetbits_32(PI_REG(i, 148), 0xffff << 16,
+               mmio_clrsetbits_32(PI_REG(i, 148), 0xffffu << 16,
                                   pdram_timing->mr[2] << 16);
                /* PI_156 PI_TFC_F0:RW:0:10 */
                mmio_clrsetbits_32(PI_REG(i, 156), 0x3ff,
@@ -1177,10 +1177,10 @@ static void gen_rk3399_pi_params_f0(struct timing_related_config *timing_config,
                /* PI_158 PI_TRP_F0:RW:0:8 */
                mmio_clrsetbits_32(PI_REG(i, 158), 0xff, pdram_timing->trp);
                /* PI_157 PI_TRTP_F0:RW:24:8 */
-               mmio_clrsetbits_32(PI_REG(i, 157), 0xff << 24,
+               mmio_clrsetbits_32(PI_REG(i, 157), 0xffu << 24,
                                   pdram_timing->trtp << 24);
                /* PI_159 PI_TRAS_MIN_F0:RW:24:8 */
-               mmio_clrsetbits_32(PI_REG(i, 159), 0xff << 24,
+               mmio_clrsetbits_32(PI_REG(i, 159), 0xffu << 24,
                                   pdram_timing->tras_min << 24);
                /* PI_159 PI_TRAS_MAX_F0:RW:0:17 */
                tmp = pdram_timing->tras_max * 99 / 100;
@@ -1237,7 +1237,7 @@ static void gen_rk3399_pi_params_f1(struct timing_related_config *timing_config,
                mmio_clrsetbits_32(PI_REG(i, 44), 0x7f << 8,
                                   (pdram_timing->cl * 2) << 8);
                /* PI_47 PI_TREF_F1:RW:16:16 */
-               mmio_clrsetbits_32(PI_REG(i, 47), 0xffff << 16,
+               mmio_clrsetbits_32(PI_REG(i, 47), 0xffffu << 16,
                                   pdram_timing->trefi << 16);
                /* PI_47 PI_TRFC_F1:RW:0:10 */
                mmio_clrsetbits_32(PI_REG(i, 47), 0x3ff, pdram_timing->trfc);
@@ -1278,10 +1278,10 @@ static void gen_rk3399_pi_params_f1(struct timing_related_config *timing_config,
                mmio_clrsetbits_32(PI_REG(i, 73), 0x3f << 16, tmp << 16);
                /*P I_89 PI_RDLAT_ADJ_F1:RW:24:8 */
                tmp = get_pi_rdlat_adj(pdram_timing);
-               mmio_clrsetbits_32(PI_REG(i, 89), 0xff << 24, tmp << 24);
+               mmio_clrsetbits_32(PI_REG(i, 89), 0xffu << 24, tmp << 24);
                /* PI_90 PI_WRLAT_ADJ_F1:RW:24:8 */
                tmp = get_pi_wrlat_adj(pdram_timing, timing_config);
-               mmio_clrsetbits_32(PI_REG(i, 90), 0xff << 24, tmp << 24);
+               mmio_clrsetbits_32(PI_REG(i, 90), 0xffu << 24, tmp << 24);
                /* PI_91 PI_TDFI_WRCSLAT_F1:RW:24:8 */
                tmp1 = tmp;
                if (tmp1 == 0)
@@ -1290,7 +1290,7 @@ static void gen_rk3399_pi_params_f1(struct timing_related_config *timing_config,
                        tmp = tmp1 - 1;
                else
                        tmp = tmp1 - 5;
-               mmio_clrsetbits_32(PI_REG(i, 91), 0xff << 24, tmp << 24);
+               mmio_clrsetbits_32(PI_REG(i, 91), 0xffu << 24, tmp << 24);
                /*PI_96 PI_TDFI_CALVL_CAPTURE_F1:RW:16:10 */
                /* tadr=20ns */
                tmp1 = 20000 / (1000000 / pdram_timing->mhz) + 1;
@@ -1333,12 +1333,12 @@ static void gen_rk3399_pi_params_f1(struct timing_related_config *timing_config,
                mmio_clrsetbits_32(PI_REG(i, 150), 0xffff << 8,
                                   pdram_timing->mr[1] << 8);
                /* PI_128 PI_MR2_DATA_F1_0:RW+:16:16 */
-               mmio_clrsetbits_32(PI_REG(i, 128), 0xffff << 16,
+               mmio_clrsetbits_32(PI_REG(i, 128), 0xffffu << 16,
                                   pdram_timing->mr[2] << 16);
                /* PI_136 PI_MR2_DATA_F1_1:RW+:0:16 */
                mmio_clrsetbits_32(PI_REG(i, 136), 0xffff, pdram_timing->mr[2]);
                /* PI_143 PI_MR2_DATA_F1_2:RW+:16:16 */
-               mmio_clrsetbits_32(PI_REG(i, 143), 0xffff << 16,
+               mmio_clrsetbits_32(PI_REG(i, 143), 0xffffu << 16,
                                   pdram_timing->mr[2] << 16);
                /* PI_151 PI_MR2_DATA_F1_3:RW+:0:16 */
                mmio_clrsetbits_32(PI_REG(i, 151), 0xffff, pdram_timing->mr[2]);
@@ -1351,7 +1351,7 @@ static void gen_rk3399_pi_params_f1(struct timing_related_config *timing_config,
                /* PI_162 PI_TWTR_F1:RW:0:6 */
                mmio_clrsetbits_32(PI_REG(i, 162), 0x3f, pdram_timing->twtr);
                /* PI_161 PI_TRCD_F1:RW:24:8 */
-               mmio_clrsetbits_32(PI_REG(i, 161), 0xff << 24,
+               mmio_clrsetbits_32(PI_REG(i, 161), 0xffu << 24,
                                   pdram_timing->trcd << 24);
                /* PI_161 PI_TRP_F1:RW:16:8 */
                mmio_clrsetbits_32(PI_REG(i, 161), 0xff << 16,
@@ -1360,7 +1360,7 @@ static void gen_rk3399_pi_params_f1(struct timing_related_config *timing_config,
                mmio_clrsetbits_32(PI_REG(i, 161), 0xff << 8,
                                   pdram_timing->trtp << 8);
                /* PI_163 PI_TRAS_MIN_F1:RW:24:8 */
-               mmio_clrsetbits_32(PI_REG(i, 163), 0xff << 24,
+               mmio_clrsetbits_32(PI_REG(i, 163), 0xffu << 24,
                                   pdram_timing->tras_min << 24);
                /* PI_163 PI_TRAS_MAX_F1:RW:0:17 */
                mmio_clrsetbits_32(PI_REG(i, 163), 0x1ffff,
@@ -1765,7 +1765,7 @@ uint32_t exit_low_power(void)
                    0x40) {
                        while (mmio_read_32(CTL_REG(i, 200)) & 0x1)
                                ;
-                       mmio_clrsetbits_32(CTL_REG(i, 93), 0xff << 24,
+                       mmio_clrsetbits_32(CTL_REG(i, 93), 0xffu << 24,
                                           0x69 << 24);
                        while (((mmio_read_32(CTL_REG(i, 100)) >> 24) & 0x7f) !=
                               0x40)
index 8bc66e1bca5c91729b3129e26b832c5b91dc77ad..7f9fad10e28307cec5f0131df33a7bad60d471eb 100644 (file)
@@ -172,7 +172,7 @@ static __pmusramfunc void override_write_leveling_value(uint32_t ch)
                mmio_clrsetbits_32(PHY_REG(ch, 8 + (128 * byte)), 0x1 << 16,
                                   1 << 16);
                mmio_clrsetbits_32(PHY_REG(ch, 63 + (128 * byte)),
-                                  0xffff << 16,
+                                  0xffffu << 16,
                                   0x200 << 16);
        }
 
@@ -656,7 +656,7 @@ __pmusramfunc static void pmusram_restore_pll(int pll_id, uint32_t *src)
        mmio_write_32(CRU_BASE + CRU_PLL_CON(pll_id, 3), src[3] | REG_SOC_WMSK);
 
        while ((mmio_read_32(CRU_BASE + CRU_PLL_CON(pll_id, 2)) &
-               (1 << 31)) == 0x0)
+               (1U << 31)) == 0x0)
                ;
 }
 
index d919fa1d2ad299e943a434b8f346c6e3ec8a77c4..cad76ac85a872a560d2d38d55e6fb4fff74d3a1c 100644 (file)
@@ -45,10 +45,10 @@ void m0_configure_execute_addr(uintptr_t addr)
        /* set the execute address for M0 */
        mmio_write_32(SGRF_BASE + SGRF_PMU_CON(3),
                      BITS_WITH_WMASK((addr >> 12) & 0xffff,
-                                     0xffff, 0));
+                                     0xffffu, 0));
        mmio_write_32(SGRF_BASE + SGRF_PMU_CON(7),
                      BITS_WITH_WMASK((addr >> 28) & 0xf,
-                                     0xf, 0));
+                                     0xfu, 0));
 }
 
 void m0_start(void)
index 1b7f69989ebe1d1344f50a7fae2bb488fa8fcdd0..a06fe2adb5925b2819336a9fdeeb24edc1578232 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -7,7 +7,7 @@
 #ifndef SYNQUACER_PLAT_LD_S__
 #define SYNQUACER_PLAT_LD_S__
 
-#include <xlat_tables_defs.h>
+#include <lib/xlat_tables/xlat_tables_defs.h>
 
 #define SPM_SHIM_EXCEPTIONS_VMA                SP_DRAM
 
index 84c8020bb8c196605a4a3591ee87075f0e4f8e8c..6c93a4ca276fcd5dfedb90dd729211611dd83a73 100644 (file)
@@ -198,8 +198,8 @@ The FVP models used are Version 11.6 Build 45, unless otherwise stated.
 -  ``FVP_Base_Cortex-A76x4``
 -  ``FVP_Base_Cortex-A76AEx4``
 -  ``FVP_Base_Cortex-A76AEx8``
+-  ``FVP_Base_Cortex-A77x4`` (Version 11.7 build 36)
 -  ``FVP_Base_Neoverse-N1x4``
--  ``FVP_Base_Deimos``
 -  ``FVP_CSS_SGI-575`` (Version 11.3 build 42)
 -  ``FVP_CSS_SGM-775`` (Version 11.3 build 42)
 -  ``FVP_RD_E1Edge`` (Version 11.3 build 42)
index ec821bae4eb3e4f5d1dd5d465574ec4366db6592..c82b58ae8fb8be8148b7431de0cad8a0920756fb 100644 (file)
@@ -17,7 +17,7 @@
  * full 64 bit values in the argument registers if invoked from Aarch64
  * mode. This violates the SMC Calling Convention, but since this
  * convention only coveres API towards Normal World it's something that
- * only concerns the OP-TEE Dispatcher in ARM Trusted Firmware and OP-TEE
+ * only concerns the OP-TEE Dispatcher in Trusted Firmware-A and OP-TEE
  * OS at Secure EL1.
  */