All of lore.kernel.org
 help / color / mirror / Atom feed
From: Massimo Pegorer <massimo.pegorer+oss@gmail.com>
To: Simon Glass <sjg@chromium.org>, u-boot@lists.u-boot-project.org
Cc: Quentin Schulz <u-boot@0leil.net>,
	 Kever Yang <kever.yang@rock-chips.com>,
	Tom Rini <trini@konsulko.com>,
	 Massimo Pegorer <massimo.pegorer+oss@gmail.com>
Subject: [PATCH 2/2] ram: rockchip: px30: allow multiple DDR types selection
Date: Sat, 29 Aug 2026 19:03:12 +0200	[thread overview]
Message-ID: <20260829-ddr-multi-v1-2-c0c7837aed20@gmail.com> (raw)
In-Reply-To: <20260829-ddr-multi-v1-0-c0c7837aed20@gmail.com>

Allow the inclusion of more than one DDR parameters set in the PX30
SDRAM driver. The driver applies included sets in a predefined order
(DDR4, LPDDR2, LPDDR3, DDR3), stopping at the first one that makes
SDRAM initialization function to complete with success.

The default fallback behaviour is preserved: if no DDR configuration
option is selected, DDR3 parameters set is included.

Due to limited PX30 TPL maximum size, including support for more than
one DDR type requires disabling some configuration options such as
CONFIG_RAM_ROCKCHIP_DEBUG.

Signed-off-by: Massimo Pegorer <massimo.pegorer+oss@gmail.com>
---
 drivers/ram/rockchip/Kconfig      | 67 +++++++++++++++++++++++++++++++--------
 drivers/ram/rockchip/sdram_px30.c | 35 ++++++++++++--------
 2 files changed, 74 insertions(+), 28 deletions(-)

diff --git a/drivers/ram/rockchip/Kconfig b/drivers/ram/rockchip/Kconfig
index 61a3193b3f5..d74980402ad 100644
--- a/drivers/ram/rockchip/Kconfig
+++ b/drivers/ram/rockchip/Kconfig
@@ -24,38 +24,77 @@ config RAM_ROCKCHIP_DEBUG
 	  This is an option for developers to understand the ram drivers
 	  initialization, configurations and etc.
 
+config RAM_ROCKCHIP_DDR3
+	bool "DDR3 support for Rockchip SoCs"
+	depends on ROCKCHIP_PX30
+	help
+	  Enable DDR3 sdram support on Rockchip SoCs.
+
+	  Note that enabling support for multiple DDR/LPDDR types may cause TPL
+	  to exceed its maximum size constraint (TPL_MAX_SIZE), depending on
+	  other configuration options selection (such as RAM_ROCKCHIP_DEBUG).
+
+	  The driver applies selected sdram parameters sets in the following
+	  order - DDR4 LPDDR2 LPDDR3 DDR3 - stopping at first set that makes
+	  sdram_init_detect() to complete successfully.
+
+	  If no DDR/LPDDR option is selected, DDR3 sdram support is enabled by
+	  default for backward compatibility with existing board configurations.
+	  Therefore this option is only useful for multiple DDR/LPDDR types
+	  selection.
+
 config RAM_ROCKCHIP_DDR4
 	bool "DDR4 support for Rockchip SoCs"
-	depends on ROCKCHIP_PX30 || ROCKCHIP_RV1126
+	depends on ROCKCHIP_PX30
 	help
-	  This enables DDR4 sdram support instead of the default DDR3 support
-	  on Rockchip SoCs.
+	  Enable DDR4 sdram support on Rockchip SoCs.
 
-	  Note that even if multiple DDR/LPDDR types are selected, support is
-	  enabled only for the selected one that comes first in the following
-	  list: LPDDR4, DDR4, LPDDR2, LPDDR3, DDR3.
+	  Note that enabling support for multiple DDR/LPDDR types may cause TPL
+	  to exceed its maximum size constraint (TPL_MAX_SIZE), depending on
+	  other configuration options selection (such as RAM_ROCKCHIP_DEBUG).
+
+	  The driver applies selected sdram parameters sets in the following
+	  order - DDR4 LPDDR2 LPDDR3 DDR3 - stopping at first set that makes
+	  sdram_init_detect() to complete successfully.
 
 config RAM_ROCKCHIP_LPDDR2
 	bool "LPDDR2 support for Rockchip SoCs"
 	depends on ROCKCHIP_PX30
 	help
-	  This enables LPDDR2 sdram support instead of the default DDR3 support
-	  on Rockchip SoCs.
+	  Enable LPDDR2 sdram support on Rockchip SoCs.
 
-	  Note that even if multiple DDR/LPDDR types are selected, support is
-	  enabled only for the selected one that comes first in the following
-	  list: LPDDR4, DDR4, LPDDR2, LPDDR3, DDR3.
+	  Note that enabling support for multiple DDR/LPDDR types may cause TPL
+	  to exceed its maximum size constraint (TPL_MAX_SIZE), depending on
+	  other configuration options selection (such as RAM_ROCKCHIP_DEBUG).
+
+	  The driver applies selected sdram parameters sets in the following
+	  order - DDR4 LPDDR2 LPDDR3 DDR3 - stopping at first set that makes
+	  sdram_init_detect() to complete successfully.
 
 config RAM_ROCKCHIP_LPDDR3
 	bool "LPDDR3 support for Rockchip SoCs"
 	depends on ROCKCHIP_PX30
 	help
-	  This enables LPDDR3 sdram support instead of the default DDR3 support
+	  Enable LPDDR3 sdram support on Rockchip SoCs.
+
+	  Note that enabling support for multiple DDR/LPDDR types may cause TPL
+	  to exceed its maximum size constraint (TPL_MAX_SIZE), depending on
+	  other configuration options selection (such as RAM_ROCKCHIP_DEBUG).
+
+	  The driver applies selected sdram parameters sets in the following
+	  order - DDR4 LPDDR2 LPDDR3 DDR3 - stopping at first set that makes
+	  sdram_init_detect() to complete successfully.
+
+config RAM_ROCKCHIP_DDR4
+	bool "DDR4 support for Rockchip SoCs"
+	depends on ROCKCHIP_RV1126
+	help
+	  This enables DDR4 sdram support instead of the default DDR3 support
 	  on Rockchip SoCs.
 
 	  Note that even if multiple DDR/LPDDR types are selected, support is
 	  enabled only for the selected one that comes first in the following
-	  list: LPDDR4, DDR4, LPDDR2, LPDDR3, DDR3.
+	  list: LPDDR4, DDR4, DDR3.
 
 config RAM_ROCKCHIP_LPDDR4
 	depends on ROCKCHIP_RV1126
@@ -66,7 +105,7 @@ config RAM_ROCKCHIP_LPDDR4
 
 	  Note that even if multiple DDR/LPDDR types are selected, support is
 	  enabled only for the selected one that comes first in the following
-	  list: LPDDR4, DDR4, LPDDR2, LPDDR3, DDR3.
+	  list: LPDDR4, DDR4, DDR3.
 
 config RAM_ROCKCHIP_LPDDR4
 	bool "LPDDR4 support for Rockchip SoCs"
diff --git a/drivers/ram/rockchip/sdram_px30.c b/drivers/ram/rockchip/sdram_px30.c
index 37e62120504..ac9f5827d1d 100644
--- a/drivers/ram/rockchip/sdram_px30.c
+++ b/drivers/ram/rockchip/sdram_px30.c
@@ -126,11 +126,17 @@ struct dram_info dram_info;
 struct px30_sdram_params sdram_configs[] = {
 #if defined(CONFIG_RAM_ROCKCHIP_DDR4)
 #include	"sdram-px30-ddr4-detect-333.inc"
-#elif defined(CONFIG_RAM_ROCKCHIP_LPDDR2)
+#endif
+#if defined(CONFIG_RAM_ROCKCHIP_LPDDR2)
 #include	"sdram-px30-lpddr2-detect-333.inc"
-#elif defined(CONFIG_RAM_ROCKCHIP_LPDDR3)
+#endif
+#if defined(CONFIG_RAM_ROCKCHIP_LPDDR3)
 #include	"sdram-px30-lpddr3-detect-333.inc"
-#else
+#endif
+#if defined(CONFIG_RAM_ROCKCHIP_DDR3) ||         \
+	(!defined(CONFIG_RAM_ROCKCHIP_DDR4) &&   \
+	 !defined(CONFIG_RAM_ROCKCHIP_LPDDR2) && \
+	 !defined(CONFIG_RAM_ROCKCHIP_LPDDR3))
 #include	"sdram-px30-ddr3-detect-333.inc"
 #endif
 };
@@ -682,19 +688,11 @@ out:
 	return ret;
 }
 
-struct px30_sdram_params
-		*get_default_sdram_config(void)
-{
-	sdram_configs[0].skew = &skew;
-
-	return &sdram_configs[0];
-}
-
 /* return: 0 = success, other = fail */
 int sdram_init(void)
 {
 	struct px30_sdram_params *sdram_params;
-	int ret = 0;
+	int ret, i = 0;
 
 	dram_info.phy = (void *)DDR_PHY_BASE_ADDR;
 	dram_info.pctl = (void *)DDRC_BASE_ADDR;
@@ -704,12 +702,21 @@ int sdram_init(void)
 	dram_info.ddr_grf = (void *)DDR_GRF_BASE_ADDR;
 	dram_info.pmugrf = (void *)PMUGRF_BASE_ADDR;
 
-	sdram_params = get_default_sdram_config();
-	ret = sdram_init_detect(&dram_info, sdram_params);
+	do {
+		sdram_configs[i].skew = &skew;
+		sdram_params = &sdram_configs[i];
+		ret = sdram_init_detect(&dram_info, sdram_params);
+	} while (ret && ++i < ARRAY_SIZE(sdram_configs));
 
 	if (ret)
 		goto error;
 
+	if (ARRAY_SIZE(sdram_configs) > 1) {
+		printascii("Applied sdram config: ");
+		printdec(i);
+		printascii("\n");
+	}
+
 	sdram_print_ddr_info(&sdram_params->ch.cap_info, &sdram_params->base, 0);
 
 	printascii("out\n");

-- 
2.34.1


      parent reply	other threads:[~2026-08-29 22:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-29 17:03 [PATCH 0/2] Support multiple DDR configs in PX30 TPL Massimo Pegorer
2026-08-29 17:03 ` [PATCH 1/2] ram: rockchip: improve ddr type configs selection Massimo Pegorer
2026-08-29 17:03 ` Massimo Pegorer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260829-ddr-multi-v1-2-c0c7837aed20@gmail.com \
    --to=massimo.pegorer+oss@gmail.com \
    --cc=kever.yang@rock-chips.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@0leil.net \
    --cc=u-boot@lists.u-boot-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.