arm: keystone: Move cmd_ddr3 to a common place
authorLokesh Vutla <lokeshvutla@ti.com>
Fri, 29 Dec 2017 06:17:49 +0000 (11:47 +0530)
committerTom Rini <trini@konsulko.com>
Fri, 19 Jan 2018 20:49:26 +0000 (15:49 -0500)
Move cmd_ddr3 to cmd/ti in order to make
it build for non-keystone TI platforms.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
[trini: Rename to ddr3.c not cmd_ddr3.c]
Signed-off-by: Tom Rini <trini@konsulko.com>
arch/arm/mach-keystone/Kconfig
arch/arm/mach-keystone/Makefile
arch/arm/mach-keystone/cmd_ddr3.c [deleted file]
cmd/Kconfig
cmd/Makefile
cmd/ti/Kconfig [new file with mode: 0644]
cmd/ti/Makefile [new file with mode: 0644]
cmd/ti/ddr3.c [new file with mode: 0644]

index cababdba527762decbd51442a9eb142c1dcd7dc5..d24596eccb0dfd7a94ef6622242e005907c5c21a 100644 (file)
@@ -7,16 +7,19 @@ choice
 config TARGET_K2HK_EVM
        bool "TI Keystone 2 Kepler/Hawking EVM"
        select SPL_BOARD_INIT if SPL
+       select CMD_DDR3
        imply DM_I2C
 
 config TARGET_K2E_EVM
        bool "TI Keystone 2 Edison EVM"
        select SPL_BOARD_INIT if SPL
+       select CMD_DDR3
        imply DM_I2C
 
 config TARGET_K2L_EVM
        bool "TI Keystone 2 Lamar EVM"
        select SPL_BOARD_INIT if SPL
+       select CMD_DDR3
        imply DM_I2C
 
 config TARGET_K2G_EVM
@@ -24,6 +27,7 @@ config TARGET_K2G_EVM
         select BOARD_LATE_INIT
        select SPL_BOARD_INIT if SPL
         select TI_I2C_BOARD_DETECT
+       select CMD_DDR3
        imply DM_I2C
 
 endchoice
index 8253a3bcc11685c21fdab9aaca44373860008625..3e076e12eca623282f8572c71be80542414a6d88 100644 (file)
@@ -13,7 +13,6 @@ ifndef CONFIG_SPL_BUILD
 obj-y  += cmd_clock.o
 obj-y  += cmd_mon.o
 obj-y  += cmd_poweroff.o
-obj-y  += cmd_ddr3.o
 endif
 obj-y  += msmc.o
 obj-y  += ddr3.o
diff --git a/arch/arm/mach-keystone/cmd_ddr3.c b/arch/arm/mach-keystone/cmd_ddr3.c
deleted file mode 100644 (file)
index d3eab07..0000000
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
- * Keystone2: DDR3 test commands
- *
- * (C) Copyright 2012-2014
- *     Texas Instruments Incorporated, <www.ti.com>
- *
- * SPDX-License-Identifier:     GPL-2.0+
- */
-
-#include <asm/arch/hardware.h>
-#include <asm/arch/ddr3.h>
-#include <common.h>
-#include <command.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-#define DDR_MIN_ADDR           CONFIG_SYS_SDRAM_BASE
-#define STACKSIZE              (512 << 10)     /* 512 KiB */
-
-#define DDR_REMAP_ADDR         0x80000000
-#define ECC_START_ADDR1                ((DDR_MIN_ADDR - DDR_REMAP_ADDR) >> 17)
-
-#define ECC_END_ADDR1          (((gd->start_addr_sp - DDR_REMAP_ADDR - \
-                                STACKSIZE) >> 17) - 2)
-
-#define DDR_TEST_BURST_SIZE    1024
-
-static int ddr_memory_test(u32 start_address, u32 end_address, int quick)
-{
-       u32 index_start, value, index;
-
-       index_start = start_address;
-
-       while (1) {
-               /* Write a pattern */
-               for (index = index_start;
-                               index < index_start + DDR_TEST_BURST_SIZE;
-                               index += 4)
-                       __raw_writel(index, index);
-
-               /* Read and check the pattern */
-               for (index = index_start;
-                               index < index_start + DDR_TEST_BURST_SIZE;
-                               index += 4) {
-                       value = __raw_readl(index);
-                       if (value != index) {
-                               printf("ddr_memory_test: Failed at address index = 0x%x value = 0x%x *(index) = 0x%x\n",
-                                      index, value, __raw_readl(index));
-
-                               return -1;
-                       }
-               }
-
-               index_start += DDR_TEST_BURST_SIZE;
-               if (index_start >= end_address)
-                       break;
-
-               if (quick)
-                       continue;
-
-               /* Write a pattern for complementary values */
-               for (index = index_start;
-                    index < index_start + DDR_TEST_BURST_SIZE;
-                    index += 4)
-                       __raw_writel((u32)~index, index);
-
-               /* Read and check the pattern */
-               for (index = index_start;
-                    index < index_start + DDR_TEST_BURST_SIZE;
-                    index += 4) {
-                       value = __raw_readl(index);
-                       if (value != ~index) {
-                               printf("ddr_memory_test: Failed at address index = 0x%x value = 0x%x *(index) = 0x%x\n",
-                                      index, value, __raw_readl(index));
-
-                               return -1;
-                       }
-               }
-
-               index_start += DDR_TEST_BURST_SIZE;
-               if (index_start >= end_address)
-                       break;
-
-               /* Write a pattern */
-               for (index = index_start;
-                    index < index_start + DDR_TEST_BURST_SIZE;
-                    index += 2)
-                       __raw_writew((u16)index, index);
-
-               /* Read and check the pattern */
-               for (index = index_start;
-                    index < index_start + DDR_TEST_BURST_SIZE;
-                    index += 2) {
-                       value = __raw_readw(index);
-                       if (value != (u16)index) {
-                               printf("ddr_memory_test: Failed at address index = 0x%x value = 0x%x *(index) = 0x%x\n",
-                                      index, value, __raw_readw(index));
-
-                               return -1;
-                       }
-               }
-
-               index_start += DDR_TEST_BURST_SIZE;
-               if (index_start >= end_address)
-                       break;
-
-               /* Write a pattern */
-               for (index = index_start;
-                    index < index_start + DDR_TEST_BURST_SIZE;
-                    index += 1)
-                       __raw_writeb((u8)index, index);
-
-               /* Read and check the pattern */
-               for (index = index_start;
-                    index < index_start + DDR_TEST_BURST_SIZE;
-                    index += 1) {
-                       value = __raw_readb(index);
-                       if (value != (u8)index) {
-                               printf("ddr_memory_test: Failed at address index = 0x%x value = 0x%x *(index) = 0x%x\n",
-                                      index, value, __raw_readb(index));
-
-                               return -1;
-                       }
-               }
-
-               index_start += DDR_TEST_BURST_SIZE;
-               if (index_start >= end_address)
-                       break;
-       }
-
-       puts("ddr memory test PASSED!\n");
-       return 0;
-}
-
-static int ddr_memory_compare(u32 address1, u32 address2, u32 size)
-{
-       u32 index, value, index2, value2;
-
-       for (index = address1, index2 = address2;
-            index < address1 + size;
-            index += 4, index2 += 4) {
-               value = __raw_readl(index);
-               value2 = __raw_readl(index2);
-
-               if (value != value2) {
-                       printf("ddr_memory_test: Compare failed at address = 0x%x value = 0x%x, address2 = 0x%x value2 = 0x%x\n",
-                              index, value, index2, value2);
-
-                       return -1;
-               }
-       }
-
-       puts("ddr memory compare PASSED!\n");
-       return 0;
-}
-
-static int ddr_memory_ecc_err(u32 base, u32 address, u32 ecc_err)
-{
-       u32 value1, value2, value3;
-
-       puts("Disabling DDR ECC ...\n");
-       ddr3_disable_ecc(base);
-
-       value1 = __raw_readl(address);
-       value2 = value1 ^ ecc_err;
-       __raw_writel(value2, address);
-
-       value3 = __raw_readl(address);
-       printf("ECC err test, addr 0x%x, read data 0x%x, wrote data 0x%x, err pattern: 0x%x, read after write data 0x%x\n",
-              address, value1, value2, ecc_err, value3);
-
-       __raw_writel(ECC_START_ADDR1 | (ECC_END_ADDR1 << 16),
-                    base + KS2_DDR3_ECC_ADDR_RANGE1_OFFSET);
-
-       puts("Enabling DDR ECC ...\n");
-       ddr3_enable_ecc(base, 1);
-
-       value1 = __raw_readl(address);
-       printf("ECC err test, addr 0x%x, read data 0x%x\n", address, value1);
-
-       ddr3_check_ecc_int(base);
-       return 0;
-}
-
-static int do_ddr_test(cmd_tbl_t *cmdtp,
-                      int flag, int argc, char * const argv[])
-{
-       u32 start_addr, end_addr, size, ecc_err;
-
-       if ((argc == 4) && (strncmp(argv[1], "ecc_err", 8) == 0)) {
-               if (!ddr3_ecc_support_rmw(KS2_DDR3A_EMIF_CTRL_BASE)) {
-                       puts("ECC RMW isn't supported for this SOC\n");
-                       return 1;
-               }
-
-               start_addr = simple_strtoul(argv[2], NULL, 16);
-               ecc_err = simple_strtoul(argv[3], NULL, 16);
-
-               if ((start_addr < CONFIG_SYS_SDRAM_BASE) ||
-                   (start_addr > (CONFIG_SYS_SDRAM_BASE +
-                    CONFIG_MAX_RAM_BANK_SIZE - 1))) {
-                       puts("Invalid address!\n");
-                       return cmd_usage(cmdtp);
-               }
-
-               ddr_memory_ecc_err(KS2_DDR3A_EMIF_CTRL_BASE,
-                                  start_addr, ecc_err);
-               return 0;
-       }
-
-       if (!(((argc == 4) && (strncmp(argv[1], "test", 5) == 0)) ||
-             ((argc == 5) && (strncmp(argv[1], "compare", 8) == 0))))
-               return cmd_usage(cmdtp);
-
-       start_addr = simple_strtoul(argv[2], NULL, 16);
-       end_addr = simple_strtoul(argv[3], NULL, 16);
-
-       if ((start_addr < CONFIG_SYS_SDRAM_BASE) ||
-           (start_addr > (CONFIG_SYS_SDRAM_BASE +
-            CONFIG_MAX_RAM_BANK_SIZE - 1)) ||
-           (end_addr < CONFIG_SYS_SDRAM_BASE) ||
-           (end_addr > (CONFIG_SYS_SDRAM_BASE +
-            CONFIG_MAX_RAM_BANK_SIZE - 1)) || (start_addr >= end_addr)) {
-               puts("Invalid start or end address!\n");
-               return cmd_usage(cmdtp);
-       }
-
-       puts("Please wait ...\n");
-       if (argc == 5) {
-               size = simple_strtoul(argv[4], NULL, 16);
-               ddr_memory_compare(start_addr, end_addr, size);
-       } else {
-               ddr_memory_test(start_addr, end_addr, 0);
-       }
-
-       return 0;
-}
-
-U_BOOT_CMD(ddr,        5, 1, do_ddr_test,
-          "DDR3 test",
-          "test <start_addr in hex> <end_addr in hex> - test DDR from start\n"
-          "    address to end address\n"
-          "ddr compare <start_addr in hex> <end_addr in hex> <size in hex> -\n"
-          "    compare DDR data of (size) bytes from start address to end\n"
-          "    address\n"
-          "ddr ecc_err <addr in hex> <bit_err in hex> - generate bit errors\n"
-          "    in DDR data at <addr>, the command will read a 32-bit data\n"
-          "    from <addr>, and write (data ^ bit_err) back to <addr>\n"
-);
index 83dc778e46f13060570ad41a3a439ee8367a381c..faa8bc62b5495b7e978ddf2fcf5cbcffd68aa916 100644 (file)
@@ -1184,6 +1184,8 @@ config CMD_UUID
 
 endmenu
 
+source "cmd/ti/Kconfig"
+
 config CMD_BOOTSTAGE
        bool "Enable the 'bootstage' command"
        depends on BOOTSTAGE
index ce65cef8ce68e95f5abe6135906a5ba83d7667c4..5ab47cbbf12d1a0674c6e7e9fde16b6948624adc 100644 (file)
@@ -159,6 +159,7 @@ endif # !CONFIG_SPL_BUILD
 obj-y += nvedit.o
 
 obj-$(CONFIG_ARCH_MVEBU) += mvebu/
+obj-$(CONFIG_TI_COMMON_CMD_OPTIONS) += ti/
 
 filechk_data_gz = (echo "static const char data_gz[] ="; cat $< | scripts/bin2c; echo ";")
 
diff --git a/cmd/ti/Kconfig b/cmd/ti/Kconfig
new file mode 100644 (file)
index 0000000..efeff0d
--- /dev/null
@@ -0,0 +1,10 @@
+menu "TI specific command line interface"
+
+config CMD_DDR3
+       bool "command for verifying DDR features"
+       help
+          Support for testing ddr3 on TI platforms. This command
+          supports memory verification, memory comapre and ecc
+          verification if supported.
+
+endmenu
diff --git a/cmd/ti/Makefile b/cmd/ti/Makefile
new file mode 100644 (file)
index 0000000..7dba66f
--- /dev/null
@@ -0,0 +1,10 @@
+# Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+#
+# SPDX-License-Identifier:     GPL-2.0+
+#
+
+obj- += dummy.o
+
+ifndef CONFIG_SPL_BUILD
+obj-$(CONFIG_CMD_DDR3) += ddr3.o
+endif
diff --git a/cmd/ti/ddr3.c b/cmd/ti/ddr3.c
new file mode 100644 (file)
index 0000000..b6435a4
--- /dev/null
@@ -0,0 +1,248 @@
+/*
+ * EMIF: DDR3 test commands
+ *
+ * Copyright (C) 2012-2017 Texas Instruments Incorporated, <www.ti.com>
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <asm/arch/hardware.h>
+#include <asm/arch/ddr3.h>
+#include <common.h>
+#include <command.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define DDR_MIN_ADDR           CONFIG_SYS_SDRAM_BASE
+#define STACKSIZE              (512 << 10)     /* 512 KiB */
+
+#define DDR_REMAP_ADDR         0x80000000
+#define ECC_START_ADDR1                ((DDR_MIN_ADDR - DDR_REMAP_ADDR) >> 17)
+
+#define ECC_END_ADDR1          (((gd->start_addr_sp - DDR_REMAP_ADDR - \
+                                STACKSIZE) >> 17) - 2)
+
+#define DDR_TEST_BURST_SIZE    1024
+
+static int ddr_memory_test(u32 start_address, u32 end_address, int quick)
+{
+       u32 index_start, value, index;
+
+       index_start = start_address;
+
+       while (1) {
+               /* Write a pattern */
+               for (index = index_start;
+                               index < index_start + DDR_TEST_BURST_SIZE;
+                               index += 4)
+                       __raw_writel(index, index);
+
+               /* Read and check the pattern */
+               for (index = index_start;
+                               index < index_start + DDR_TEST_BURST_SIZE;
+                               index += 4) {
+                       value = __raw_readl(index);
+                       if (value != index) {
+                               printf("ddr_memory_test: Failed at address index = 0x%x value = 0x%x *(index) = 0x%x\n",
+                                      index, value, __raw_readl(index));
+
+                               return -1;
+                       }
+               }
+
+               index_start += DDR_TEST_BURST_SIZE;
+               if (index_start >= end_address)
+                       break;
+
+               if (quick)
+                       continue;
+
+               /* Write a pattern for complementary values */
+               for (index = index_start;
+                    index < index_start + DDR_TEST_BURST_SIZE;
+                    index += 4)
+                       __raw_writel((u32)~index, index);
+
+               /* Read and check the pattern */
+               for (index = index_start;
+                    index < index_start + DDR_TEST_BURST_SIZE;
+                    index += 4) {
+                       value = __raw_readl(index);
+                       if (value != ~index) {
+                               printf("ddr_memory_test: Failed at address index = 0x%x value = 0x%x *(index) = 0x%x\n",
+                                      index, value, __raw_readl(index));
+
+                               return -1;
+                       }
+               }
+
+               index_start += DDR_TEST_BURST_SIZE;
+               if (index_start >= end_address)
+                       break;
+
+               /* Write a pattern */
+               for (index = index_start;
+                    index < index_start + DDR_TEST_BURST_SIZE;
+                    index += 2)
+                       __raw_writew((u16)index, index);
+
+               /* Read and check the pattern */
+               for (index = index_start;
+                    index < index_start + DDR_TEST_BURST_SIZE;
+                    index += 2) {
+                       value = __raw_readw(index);
+                       if (value != (u16)index) {
+                               printf("ddr_memory_test: Failed at address index = 0x%x value = 0x%x *(index) = 0x%x\n",
+                                      index, value, __raw_readw(index));
+
+                               return -1;
+                       }
+               }
+
+               index_start += DDR_TEST_BURST_SIZE;
+               if (index_start >= end_address)
+                       break;
+
+               /* Write a pattern */
+               for (index = index_start;
+                    index < index_start + DDR_TEST_BURST_SIZE;
+                    index += 1)
+                       __raw_writeb((u8)index, index);
+
+               /* Read and check the pattern */
+               for (index = index_start;
+                    index < index_start + DDR_TEST_BURST_SIZE;
+                    index += 1) {
+                       value = __raw_readb(index);
+                       if (value != (u8)index) {
+                               printf("ddr_memory_test: Failed at address index = 0x%x value = 0x%x *(index) = 0x%x\n",
+                                      index, value, __raw_readb(index));
+
+                               return -1;
+                       }
+               }
+
+               index_start += DDR_TEST_BURST_SIZE;
+               if (index_start >= end_address)
+                       break;
+       }
+
+       puts("ddr memory test PASSED!\n");
+       return 0;
+}
+
+static int ddr_memory_compare(u32 address1, u32 address2, u32 size)
+{
+       u32 index, value, index2, value2;
+
+       for (index = address1, index2 = address2;
+            index < address1 + size;
+            index += 4, index2 += 4) {
+               value = __raw_readl(index);
+               value2 = __raw_readl(index2);
+
+               if (value != value2) {
+                       printf("ddr_memory_test: Compare failed at address = 0x%x value = 0x%x, address2 = 0x%x value2 = 0x%x\n",
+                              index, value, index2, value2);
+
+                       return -1;
+               }
+       }
+
+       puts("ddr memory compare PASSED!\n");
+       return 0;
+}
+
+static int ddr_memory_ecc_err(u32 base, u32 address, u32 ecc_err)
+{
+       u32 value1, value2, value3;
+
+       puts("Disabling DDR ECC ...\n");
+       ddr3_disable_ecc(base);
+
+       value1 = __raw_readl(address);
+       value2 = value1 ^ ecc_err;
+       __raw_writel(value2, address);
+
+       value3 = __raw_readl(address);
+       printf("ECC err test, addr 0x%x, read data 0x%x, wrote data 0x%x, err pattern: 0x%x, read after write data 0x%x\n",
+              address, value1, value2, ecc_err, value3);
+
+       __raw_writel(ECC_START_ADDR1 | (ECC_END_ADDR1 << 16),
+                    base + KS2_DDR3_ECC_ADDR_RANGE1_OFFSET);
+
+       puts("Enabling DDR ECC ...\n");
+       ddr3_enable_ecc(base, 1);
+
+       value1 = __raw_readl(address);
+       printf("ECC err test, addr 0x%x, read data 0x%x\n", address, value1);
+
+       ddr3_check_ecc_int(base);
+       return 0;
+}
+
+static int do_ddr_test(cmd_tbl_t *cmdtp,
+                      int flag, int argc, char * const argv[])
+{
+       u32 start_addr, end_addr, size, ecc_err;
+
+       if ((argc == 4) && (strncmp(argv[1], "ecc_err", 8) == 0)) {
+               if (!ddr3_ecc_support_rmw(KS2_DDR3A_EMIF_CTRL_BASE)) {
+                       puts("ECC RMW isn't supported for this SOC\n");
+                       return 1;
+               }
+
+               start_addr = simple_strtoul(argv[2], NULL, 16);
+               ecc_err = simple_strtoul(argv[3], NULL, 16);
+
+               if ((start_addr < CONFIG_SYS_SDRAM_BASE) ||
+                   (start_addr > (CONFIG_SYS_SDRAM_BASE +
+                    CONFIG_MAX_RAM_BANK_SIZE - 1))) {
+                       puts("Invalid address!\n");
+                       return cmd_usage(cmdtp);
+               }
+
+               ddr_memory_ecc_err(KS2_DDR3A_EMIF_CTRL_BASE,
+                                  start_addr, ecc_err);
+               return 0;
+       }
+
+       if (!(((argc == 4) && (strncmp(argv[1], "test", 5) == 0)) ||
+             ((argc == 5) && (strncmp(argv[1], "compare", 8) == 0))))
+               return cmd_usage(cmdtp);
+
+       start_addr = simple_strtoul(argv[2], NULL, 16);
+       end_addr = simple_strtoul(argv[3], NULL, 16);
+
+       if ((start_addr < CONFIG_SYS_SDRAM_BASE) ||
+           (start_addr > (CONFIG_SYS_SDRAM_BASE +
+            CONFIG_MAX_RAM_BANK_SIZE - 1)) ||
+           (end_addr < CONFIG_SYS_SDRAM_BASE) ||
+           (end_addr > (CONFIG_SYS_SDRAM_BASE +
+            CONFIG_MAX_RAM_BANK_SIZE - 1)) || (start_addr >= end_addr)) {
+               puts("Invalid start or end address!\n");
+               return cmd_usage(cmdtp);
+       }
+
+       puts("Please wait ...\n");
+       if (argc == 5) {
+               size = simple_strtoul(argv[4], NULL, 16);
+               ddr_memory_compare(start_addr, end_addr, size);
+       } else {
+               ddr_memory_test(start_addr, end_addr, 0);
+       }
+
+       return 0;
+}
+
+U_BOOT_CMD(ddr,        5, 1, do_ddr_test,
+          "DDR3 test",
+          "test <start_addr in hex> <end_addr in hex> - test DDR from start\n"
+          "    address to end address\n"
+          "ddr compare <start_addr in hex> <end_addr in hex> <size in hex> -\n"
+          "    compare DDR data of (size) bytes from start address to end\n"
+          "    address\n"
+          "ddr ecc_err <addr in hex> <bit_err in hex> - generate bit errors\n"
+          "    in DDR data at <addr>, the command will read a 32-bit data\n"
+          "    from <addr>, and write (data ^ bit_err) back to <addr>\n"
+);