Skip to contentSkip to conversation

arm64: imx8mp: Fold inline ECC into spl.c on DH i.MX8MP DHCOM SoM

PATCH New Marek Vasut 1 participant 4 messages Apr 1

Subsystems (2)
lore
Share & tools
lore

Marek Vasut

author maintainer
#0 lore raw

PATCH 1/4 arm64: imx8mp: Fold inline ECC into spl.c on DH i.MX8MP DHCOM SoM

The inline ECC configuration is identical for 2 GiB DRAM variants and 4 GiB DRAM variants of the SoM, no matter the rank count. Fold the ECC configuration directly into spl.c to simplify the upcoming deduplication. No functional change.

---
Cc: Fabio Estevam <[email protected]>
Cc: Peng Fan <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 board/dhelectronics/dh_imx8mp/lpddr4_timing.h |  4 ---
 .../dh_imx8mp/lpddr4_timing_2G_32.c           | 14 ----------
 .../dh_imx8mp/lpddr4_timing_4G_32.c           | 14 ----------
 board/dhelectronics/dh_imx8mp/spl.c           | 26 +++++++++++++++++++
 4 files changed, 26 insertions(+), 32 deletions(-)
board/dhelectronics/dh_imx8mp/lpddr4_timing.h +0 -4
index c4d51174a33..f8078051f2f 100644
@@ -9,10 +9,6 @@
 extern struct dram_timing_info dh_imx8mp_dhcom_dram_timing_16g_x32;
 extern struct dram_timing_info dh_imx8mp_dhcom_dram_timing_32g_x32;
 
-typedef void (*scrub_func_t)(void);
-extern void dh_imx8mp_dhcom_dram_scrub_16g_x32(void);
-extern void dh_imx8mp_dhcom_dram_scrub_32g_x32(void);
-
 u8 dh_get_memcfg(void);
 
 #define DDRC_ECCCFG0_ECC_MODE_MASK	0x7
board/dhelectronics/dh_imx8mp/lpddr4_timing_2G_32.c +0 -14
index add7a0bf23b..3cb868311f3 100644
@@ -1853,17 +1853,3 @@ struct dram_timing_info dh_imx8mp_dhcom_dram_timing_16g_x32 = {
 	.ddrphy_pie_num = ARRAY_SIZE(ddr_phy_pie),
 	.fsp_table = { 3600, 400, 100, },
 };
-
-#if IS_ENABLED(CONFIG_IMX8M_DRAM_INLINE_ECC)
-void dh_imx8mp_dhcom_dram_scrub_16g_x32(void)
-{
-	ddrc_inline_ecc_scrub(0x0,0x3ffffff);
-	ddrc_inline_ecc_scrub(0x4000000,0x7ffffff);
-	ddrc_inline_ecc_scrub(0x8000000,0xbffffff);
-	ddrc_inline_ecc_scrub(0xc000000,0xfffffff);
-	ddrc_inline_ecc_scrub(0x10000000,0x13ffffff);
-	ddrc_inline_ecc_scrub(0x14000000,0x17ffffff);
-	ddrc_inline_ecc_scrub(0x18000000,0x1bffffff);
-	ddrc_inline_ecc_scrub_end(0x0,0x1fffffff);
-}
-#endif
board/dhelectronics/dh_imx8mp/lpddr4_timing_4G_32.c +0 -14
index 41b078f6e9f..3a475076e75 100644
@@ -1857,17 +1857,3 @@ struct dram_timing_info dh_imx8mp_dhcom_dram_timing_32g_x32 = {
 	.ddrphy_pie_num = ARRAY_SIZE(ddr_phy_pie),
 	.fsp_table = { 3600, 400, 100, },
 };
-
-#if IS_ENABLED(CONFIG_IMX8M_DRAM_INLINE_ECC)
-void dh_imx8mp_dhcom_dram_scrub_32g_x32(void)
-{
-	ddrc_inline_ecc_scrub(0x0,0x7ffffff);
-	ddrc_inline_ecc_scrub(0x8000000,0xfffffff);
-	ddrc_inline_ecc_scrub(0x10000000,0x17ffffff);
-	ddrc_inline_ecc_scrub(0x18000000,0x1fffffff);
-	ddrc_inline_ecc_scrub(0x20000000,0x27ffffff);
-	ddrc_inline_ecc_scrub(0x28000000,0x2fffffff);
-	ddrc_inline_ecc_scrub(0x30000000,0x37ffffff);
-	ddrc_inline_ecc_scrub_end(0x0,0x3fffffff);
-}
-#endif
board/dhelectronics/dh_imx8mp/spl.c +26 -0
index 727e1ff3774..d8a928639b2 100644
@@ -139,6 +139,32 @@ static void spl_dram_init(void)
 }
 
 #if IS_ENABLED(CONFIG_IMX8M_DRAM_INLINE_ECC)
+static void dh_imx8mp_dhcom_dram_scrub_16g_x32(void)
+{
+	ddrc_inline_ecc_scrub(0x0,0x3ffffff);
+	ddrc_inline_ecc_scrub(0x4000000,0x7ffffff);
+	ddrc_inline_ecc_scrub(0x8000000,0xbffffff);
+	ddrc_inline_ecc_scrub(0xc000000,0xfffffff);
+	ddrc_inline_ecc_scrub(0x10000000,0x13ffffff);
+	ddrc_inline_ecc_scrub(0x14000000,0x17ffffff);
+	ddrc_inline_ecc_scrub(0x18000000,0x1bffffff);
+	ddrc_inline_ecc_scrub_end(0x0,0x1fffffff);
+}
+
+static void dh_imx8mp_dhcom_dram_scrub_32g_x32(void)
+{
+	ddrc_inline_ecc_scrub(0x0,0x7ffffff);
+	ddrc_inline_ecc_scrub(0x8000000,0xfffffff);
+	ddrc_inline_ecc_scrub(0x10000000,0x17ffffff);
+	ddrc_inline_ecc_scrub(0x18000000,0x1fffffff);
+	ddrc_inline_ecc_scrub(0x20000000,0x27ffffff);
+	ddrc_inline_ecc_scrub(0x28000000,0x2fffffff);
+	ddrc_inline_ecc_scrub(0x30000000,0x37ffffff);
+	ddrc_inline_ecc_scrub_end(0x0,0x3fffffff);
+}
+
+typedef void (*scrub_func_t)(void);
+
 static const scrub_func_t dram_scrub_fn[8] = {
 	NULL,					/* 512 MiB */
 	NULL,					/* 1024 MiB */
Signature · 1 line
2.53.0
author maintainer
#1 lore raw

PATCH 2/4 arm64: imx8mp: Deduplicate DRAM size tables on DH i.MX8MP DHCOM SoM

The DRAM size tables are shared by SPL and U-Boot proper, deduplicate those tables into lpddr4_timing.h . No functional change.

---
Cc: Fabio Estevam <[email protected]>
Cc: Peng Fan <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 board/dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c | 3 +--
 board/dhelectronics/dh_imx8mp/lpddr4_timing.h     | 4 ++++
 board/dhelectronics/dh_imx8mp/spl.c               | 3 +--
 3 files changed, 6 insertions(+), 4 deletions(-)
board/dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c +1 -2
index 3fe98d36f5b..3424be10936 100644
@@ -28,12 +28,11 @@ int mach_cpu_init(void)
 
 int board_phys_sdram_size(phys_size_t *size)
 {
-	const u16 memsz[] = { 512, 1024, 1536, 2048, 3072, 4096, 6144, 8192 };
 	const u8 ecc = readl(DDRC_ECCCFG0(0)) & DDRC_ECCCFG0_ECC_MODE_MASK;
 	u8 memcfg = dh_get_memcfg();
 
 	/* 896 kiB, i.e. 1 MiB without 12.5% reserved for in-band ECC */
-	*size = (u64)memsz[memcfg] * (SZ_1M - (ecc ? (SZ_1M / 8) : 0));
+	*size = (u64)dh_imx8mp_dhcom_dram_size[memcfg] * (SZ_1M - (ecc ? (SZ_1M / 8) : 0));
 
 	return 0;
 }
board/dhelectronics/dh_imx8mp/lpddr4_timing.h +4 -0
index f8078051f2f..0f9f47bbe11 100644
@@ -6,6 +6,10 @@
 #ifndef __LPDDR4_TIMING_H__
 #define __LPDDR4_TIMING_H__
 
+static const u16 dh_imx8mp_dhcom_dram_size[] = {
+	512, 1024, 1536, 2048, 3072, 4096, 6144, 8192
+};
+
 extern struct dram_timing_info dh_imx8mp_dhcom_dram_timing_16g_x32;
 extern struct dram_timing_info dh_imx8mp_dhcom_dram_timing_32g_x32;
 
board/dhelectronics/dh_imx8mp/spl.c +1 -2
index d8a928639b2..ece790da66a 100644
@@ -117,11 +117,10 @@ static struct dram_timing_info *dram_timing_info[8] = {
 
 static void spl_dram_init(void)
 {
-	const u16 size[] = { 512, 1024, 1536, 2048, 3072, 4096, 6144, 8192 };
 	u8 memcfg = dh_get_memcfg();
 	int i;
 
-	printf("DDR:   %d MiB [0x%x]\n", size[memcfg], memcfg);
+	printf("DDR:   %d MiB [0x%x]\n", dh_imx8mp_dhcom_dram_size[memcfg], memcfg);
 
 	if (!dram_timing_info[memcfg]) {
 		printf("Unsupported DRAM strapping, trying lowest supported. MEMCFG=0x%x\n",
Signature · 1 line
2.53.0
author maintainer
#2 lore raw

PATCH 3/4 arm64: imx8mp: Deduplicate 2G and 4G 2r DRAM timings on DH i.MX8MP DHCOM SoM

In reply to Marek Vasut

The 2 GiB and 4 GiB 2-rank DRAM timings on i.MX8MP DHCOM are very similar. Instead of carrying around two copies of almost identical timing tables, implement a patch of the 2 GiB table to convert it into 4 GiB 2-rank table and pass the result to DRAM initialization code. This saves us 13640 Bytes in SPL, and frees up space for more DRAM initialization tables.

---
Cc: Fabio Estevam <[email protected]>
Cc: Peng Fan <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 board/dhelectronics/dh_imx8mp/Makefile        |    2 +-
 board/dhelectronics/dh_imx8mp/lpddr4_timing.h |    5 +-
 .../dh_imx8mp/lpddr4_timing_2G_32.c           |   57 +
 .../dh_imx8mp/lpddr4_timing_4G_32.c           | 1859 -----------------
 board/dhelectronics/dh_imx8mp/spl.c           |   31 +-
 5 files changed, 79 insertions(+), 1875 deletions(-)
 delete mode 100644 board/dhelectronics/dh_imx8mp/lpddr4_timing_4G_32.c
board/dhelectronics/dh_imx8mp/Makefile +1 -1
index 7bc8dc21e64..12fb7b71ab6 100644
@@ -5,7 +5,7 @@
 #
 
 ifdef CONFIG_XPL_BUILD
-obj-y += spl.o lpddr4_timing_2G_32.o lpddr4_timing_4G_32.o
+obj-y += spl.o lpddr4_timing_2G_32.o
 else
 obj-y += imx8mp_dhcom_pdk2.o
 endif
board/dhelectronics/dh_imx8mp/lpddr4_timing.h +4 -1
index 0f9f47bbe11..ef899dc0678 100644
@@ -11,7 +11,10 @@ static const u16 dh_imx8mp_dhcom_dram_size[] = {
 };
 
 extern struct dram_timing_info dh_imx8mp_dhcom_dram_timing_16g_x32;
-extern struct dram_timing_info dh_imx8mp_dhcom_dram_timing_32g_x32;
+static __maybe_unused struct dram_timing_info *dh_imx8mp_dhcom_dram_timing =
+	&dh_imx8mp_dhcom_dram_timing_16g_x32;
+void dh_imx8mp_dhcom_dram_patch_16g_x32_to_16g_x32(void);
+void dh_imx8mp_dhcom_dram_patch_16g_x32_to_32g_x32_2r(void);
 
 u8 dh_get_memcfg(void);
 
board/dhelectronics/dh_imx8mp/lpddr4_timing_2G_32.c +57 -0

60 lines not on this page · raw message

board/dhelectronics/dh_imx8mp/lpddr4_timing_4G_32.c deleted +0 -1859

1,859 lines not on this page · raw message

board/dhelectronics/dh_imx8mp/spl.c +17 -14
index ece790da66a..8b9dddab79a 100644
@@ -104,15 +104,17 @@ static int dh_imx8mp_board_power_init(void)
 	return 0;
 }
 
-static struct dram_timing_info *dram_timing_info[8] = {
-	NULL,					/* 512 MiB */
-	NULL,					/* 1024 MiB */
-	NULL,					/* 1536 MiB */
-	&dh_imx8mp_dhcom_dram_timing_16g_x32,	/* 2048 MiB */
-	NULL,					/* 3072 MiB */
-	&dh_imx8mp_dhcom_dram_timing_32g_x32,	/* 4096 MiB */
-	NULL,					/* 6144 MiB */
-	NULL,					/* 8192 MiB */
+typedef void (*patch_func_t)(void);
+
+static const patch_func_t dram_patch_fn[8] = {
+	NULL,							/* 512 MiB */
+	NULL,							/* 1024 MiB */
+	NULL,							/* 1536 MiB */
+	dh_imx8mp_dhcom_dram_patch_16g_x32_to_16g_x32,		/* 2048 MiB */
+	NULL,							/* 3072 MiB */
+	dh_imx8mp_dhcom_dram_patch_16g_x32_to_32g_x32_2r,	/* 4096 MiB 2-rank */
+	NULL,							/* 6144 MiB */
+	NULL,							/* 8192 MiB */
 };
 
 static void spl_dram_init(void)
@@ -122,15 +124,16 @@ static void spl_dram_init(void)
 
 	printf("DDR:   %d MiB [0x%x]\n", dh_imx8mp_dhcom_dram_size[memcfg], memcfg);
 
-	if (!dram_timing_info[memcfg]) {
+	if (!dram_patch_fn[memcfg]) {
 		printf("Unsupported DRAM strapping, trying lowest supported. MEMCFG=0x%x\n",
 		       memcfg);
-		for (i = 0; i < ARRAY_SIZE(dram_timing_info); i++)
-			if (dram_timing_info[i])	/* Configuration found */
+		for (i = 0; i < ARRAY_SIZE(dram_patch_fn); i++)
+			if (dram_patch_fn[i])	/* Configuration found */
 				break;
 	}
 
-	ddr_init(dram_timing_info[memcfg]);
+	dram_patch_fn[memcfg]();
+	ddr_init(dh_imx8mp_dhcom_dram_timing);
 
 	printf("DDR:   Inline ECC %sabled\n",
 	       (readl(DDRC_ECCCFG0(0)) & DDRC_ECCCFG0_ECC_MODE_MASK) ?
@@ -170,7 +173,7 @@ static const scrub_func_t dram_scrub_fn[8] = {
 	NULL,					/* 1536 MiB */
 	dh_imx8mp_dhcom_dram_scrub_16g_x32,	/* 2048 MiB */
 	NULL,					/* 3072 MiB */
-	dh_imx8mp_dhcom_dram_scrub_32g_x32,	/* 4096 MiB */
+	dh_imx8mp_dhcom_dram_scrub_32g_x32,	/* 4096 MiB 2-rank */
 	NULL,					/* 6144 MiB */
 	NULL,					/* 8192 MiB */
 };
Signature · 1 line
2.53.0
author maintainer
#3 lore raw

PATCH 4/4 arm64: imx8mp: Add 4G 1r DRAM timings on DH i.MX8MP DHCOM SoM

In reply to Marek Vasut

Introduce timing patch which converts 2 GiB DRAM timings to 4 GiB 1-rank timings. This is a new configuration which carries IS43LQ32K01B DRAM part. The 512 MiB SoM strapping that was never used is repurposed for this part.

---
Cc: Fabio Estevam <[email protected]>
Cc: Peng Fan <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 board/dhelectronics/dh_imx8mp/lpddr4_timing.h |   3 +-
 .../dh_imx8mp/lpddr4_timing_2G_32.c           | 138 ++++++++++++++++++
 board/dhelectronics/dh_imx8mp/spl.c           |   4 +-
 3 files changed, 142 insertions(+), 3 deletions(-)
board/dhelectronics/dh_imx8mp/lpddr4_timing.h +2 -1
index ef899dc0678..5dc841a7f5a 100644
@@ -7,7 +7,7 @@
 #define __LPDDR4_TIMING_H__
 
 static const u16 dh_imx8mp_dhcom_dram_size[] = {
-	512, 1024, 1536, 2048, 3072, 4096, 6144, 8192
+	4096, 1024, 1536, 2048, 3072, 4096, 6144, 8192
 };
 
 extern struct dram_timing_info dh_imx8mp_dhcom_dram_timing_16g_x32;
@@ -15,6 +15,7 @@ static __maybe_unused struct dram_timing_info *dh_imx8mp_dhcom_dram_timing =
 	&dh_imx8mp_dhcom_dram_timing_16g_x32;
 void dh_imx8mp_dhcom_dram_patch_16g_x32_to_16g_x32(void);
 void dh_imx8mp_dhcom_dram_patch_16g_x32_to_32g_x32_2r(void);
+void dh_imx8mp_dhcom_dram_patch_16g_x32_to_32g_x32_1r(void);
 
 u8 dh_get_memcfg(void);
 
board/dhelectronics/dh_imx8mp/lpddr4_timing_2G_32.c +138 -0

141 lines not on this page · raw message

board/dhelectronics/dh_imx8mp/spl.c +2 -2
index 8b9dddab79a..aab8550023e 100644
@@ -107,7 +107,7 @@ static int dh_imx8mp_board_power_init(void)
 typedef void (*patch_func_t)(void);
 
 static const patch_func_t dram_patch_fn[8] = {
-	NULL,							/* 512 MiB */
+	dh_imx8mp_dhcom_dram_patch_16g_x32_to_32g_x32_1r,	/* 4096 MiB 1-rank */
 	NULL,							/* 1024 MiB */
 	NULL,							/* 1536 MiB */
 	dh_imx8mp_dhcom_dram_patch_16g_x32_to_16g_x32,		/* 2048 MiB */
@@ -168,7 +168,7 @@ static void dh_imx8mp_dhcom_dram_scrub_32g_x32(void)
 typedef void (*scrub_func_t)(void);
 
 static const scrub_func_t dram_scrub_fn[8] = {
-	NULL,					/* 512 MiB */
+	dh_imx8mp_dhcom_dram_scrub_32g_x32,	/* 4096 MiB 1-rank */
 	NULL,					/* 1024 MiB */
 	NULL,					/* 1536 MiB */
 	dh_imx8mp_dhcom_dram_scrub_16g_x32,	/* 2048 MiB */
Signature · 1 line
2.53.0