Skip to contentSkip to conversation

Improve Rockchip SDRAM types support configuration

PATCH New Massimo Pegorer 1 participant 5 messages Nov 27 Arm Rockchip

lore
Share & tools
lore
#0 lore raw

v4 cover Improve Rockchip SDRAM types support configuration

This series splits from [1] as preliminary to a next series related to support of multiple SDRAM types at a time in Rockchip PX30 SoC TPL.

The first patch improves clarity of SDRAM type support selection for Rockchip SoCs at Kconfig level. Not all the SDRAM type config options named in the Kconfig are supported by each of the Rockchip SoCs.

The second patch adds RAM_ROCKCHIP_DDR3 option, forcing PX30 RK3399 and RV1126 configurations to select at least one of the RAM_ROCKCHIP_XXX SDRAM type options, dropping the fallback behaviour of using DDR3 parameters set when no option is selected, adopted by these SoCs
drivers: now, if none is selected, a compile-time error is raised, instead.

The third patch raises an error if more than one RAM_ROCKCHIP_XXX SDRAM type option is selected when compiling PX30 or RV1126: these drivers support just one type at a time. Drop previous approach of choosing one type among the selected based on a debatable and embedded order, not evident at configuration level. A compile-time error arises also when compiling for RK3399 and the LPDDR4 option is not the only one selected.

The fourth patch extends RK3399 SDRAM driver to include support for DDR3 LPDDR3 and LPDDR4 at the same time. This introduces minor behavioural changes and TPL size increase (buildman report). Instead, the first three patches do not introduce any change in the built binary artifacts.

All RK3399 configurations have been built selecting all the SDRAM config options for testing: no TPL size error arised at build time. I do not have any RK3399 board, therefore I did not run any test on hardware.

[1] https://patch.msgid.link/[email protected]

---
Changes in v4:
- 1/4 add to LPDDR3 option depends on RK3399 too
- 2/4 add the RK3399 case in the SDRAM type handling
- 3/4 raise error for RK3399 with LPDDR4 + DDR3 and/or LPDDR3
- 4/4 (new) support RK3399 LPDDR4 + DDR3 and/or LPDDR3 case
- Link to v3: https://patch.msgid.link/[email protected]

Changes in v3:
- Split 1/4 of v2 into 3 different patches as follow:
-- 1/3 only add SoC guards to Rockchip SDRAM config options.
-- 2/3 new DDR3 config option and raise error if no SDRAM type is selected. -- 3/3 raise error if more than one SDRAM type is selected.
- Drop useless replacing of defined() with IS_ENABLED().
- Drop PX30 multi SDRAM support (2/4 of v2) for another series.
- Drop TPL size optimizations (3/4 and 4/4 of v2) for another series.
- Align cover-letter description with updated series contents.
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Update and reword cover letter.
- Do not duplicate config options based on SoC.
- Add SDRAM config option for DDR3 explicit selection.
- Raise compile time error if no SDRAM type is selected.
- Raise compile time error if more than one type is selected but the driver does not support more than one at a time.
- Change order to alphabetical one, as the most trivial option.
- Slightly optimize sdram driver debugging code.
- Add config option for size-constrained driver debugging.
- Link to v1: https://patch.msgid.link/[email protected]

To: [email protected]
To: Quentin Schulz <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: Massimo Pegorer <[email protected]>

---
Massimo Pegorer (4):
ram: rockchip: improve SDRAM type config selection
ram: rockchip: add DDR3 SDRAM type config option
ram: rockchip: raise error when configuration is unsupported
ram: rockchip: rk3399: support multiple SDRAM types at a time

 drivers/ram/rockchip/Kconfig        | 24 ++++++++++++------
 drivers/ram/rockchip/sdram_px30.c   | 11 ++++++++-
 drivers/ram/rockchip/sdram_rk3399.c | 49 +++++++++++++++++++++++++++++--------
 drivers/ram/rockchip/sdram_rv1126.c | 10 +++++++-
 4 files changed, 74 insertions(+), 20 deletions(-)

---
base-commit: a1ce46a6689641dd83d725edbfc3f5719abf3a94
change-id: 20260828-ddr-multi-2c4fd64344c8

Best regards,

Signature · 1 line
Massimo Pegorer <[email protected]>
#1 lore raw

PATCH v4 1/4 ram: rockchip: improve SDRAM type config selection

The PX30 RK3399 and RV1126 SoC SDRAM drivers' code has compile-time options based on SDRAM type, and selected through Kconfig options. However, not all three SoCs support all the SDRAM type configuration options named in the Kconfig: improve clarity adding SoC dependencies to each option.

---
 drivers/ram/rockchip/Kconfig | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/ram/rockchip/Kconfig +8 -8
index d707d09c1c8..fc948e82993 100644
@@ -26,26 +26,26 @@ config RAM_ROCKCHIP_DEBUG
 
 config RAM_ROCKCHIP_DDR4
 	bool "DDR4 support for Rockchip SoCs"
+	depends on ROCKCHIP_PX30 || ROCKCHIP_RV1126
 	help
-	  This enables DDR4 sdram support instead of the default DDR3 support
-	  on Rockchip SoCs.
+	  Enable DDR4 sdram support on Rockchip SoCs.
 
 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.
 
 config RAM_ROCKCHIP_LPDDR3
 	bool "LPDDR3 support for Rockchip SoCs"
+	depends on ROCKCHIP_PX30 || ROCKCHIP_RK3399
 	help
-	  This enables LPDDR3 sdram support instead of the default DDR3 support
-	  on Rockchip SoCs.
+	  Enable LPDDR3 sdram support on Rockchip SoCs.
 
 config RAM_ROCKCHIP_LPDDR4
+	depends on ROCKCHIP_RK3399 || ROCKCHIP_RV1126
 	bool "LPDDR4 support for Rockchip SoCs"
 	help
-	  This enables LPDDR4 sdram code support for the platforms based
-	  on Rockchip SoCs.
+	  Enable LPDDR4 sdram support on Rockchip SoCs.
 
 endif # RAM_ROCKCHIP
Signature · 1 line
2.34.1
#2 lore raw

PATCH v4 2/4 ram: rockchip: add DDR3 SDRAM type config option

In reply to Massimo Pegorer

Add new RAM_ROCKCHIP_DDR3 SDRAM type configuration option and drop the PX30 RK3399 and RV1126 SDRAM drivers' fallback behaviour, which consists of assuming DDR3 as default type when no RAM_ROCKCHIP_XXX type config option is selected. Instead, the drivers code now raises a compile-time error if none is selected. The default value of RAM_ROCKCHIP_DDR3 is true if all other RAM_ROCKCHIP_XXX SDRAM type options are false: this preserves the overall default behaviour avoiding impacts on defconfigs.

---
 drivers/ram/rockchip/Kconfig        |  8 ++++++++
 drivers/ram/rockchip/sdram_px30.c   |  4 +++-
 drivers/ram/rockchip/sdram_rk3399.c | 14 ++++++++++++--
 drivers/ram/rockchip/sdram_rv1126.c |  4 +++-
 4 files changed, 26 insertions(+), 4 deletions(-)
drivers/ram/rockchip/Kconfig +8 -0
index fc948e82993..0d4470c8ede 100644
@@ -24,6 +24,14 @@ 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 || ROCKCHIP_RK3399 || ROCKCHIP_RV1126
+	default y if !RAM_ROCKCHIP_DDR4 && !RAM_ROCKCHIP_LPDDR2 && \
+		!RAM_ROCKCHIP_LPDDR3 && !RAM_ROCKCHIP_LPDDR4
+	help
+	  Enable DDR3 sdram support on Rockchip SoCs.
+
 config RAM_ROCKCHIP_DDR4
 	bool "DDR4 support for Rockchip SoCs"
 	depends on ROCKCHIP_PX30 || ROCKCHIP_RV1126
drivers/ram/rockchip/sdram_px30.c +3 -1
index 37e62120504..0b6d3723409 100644
@@ -130,8 +130,10 @@ struct px30_sdram_params sdram_configs[] = {
 #include	"sdram-px30-lpddr2-detect-333.inc"
 #elif defined(CONFIG_RAM_ROCKCHIP_LPDDR3)
 #include	"sdram-px30-lpddr3-detect-333.inc"
-#else
+#elif defined(CONFIG_RAM_ROCKCHIP_DDR3)
 #include	"sdram-px30-ddr3-detect-333.inc"
+#else
+#error "Please select a DRAM type via a CONFIG_RAM_ROCKCHIP_* option"
 #endif
 };
 
drivers/ram/rockchip/sdram_rk3399.c +12 -2
index 6fa8f268770..5bc6f3a39fd 100644
@@ -26,6 +26,12 @@
 #include <linux/err.h>
 #include <time.h>
 
+#if !defined(CONFIG_RAM_ROCKCHIP_DDR3) && \
+	!defined(CONFIG_RAM_ROCKCHIP_LPDDR3) && \
+	!defined(CONFIG_RAM_ROCKCHIP_LPDDR4)
+#error "Please select a DRAM type via a CONFIG_RAM_ROCKCHIP_* option"
+#endif
+
 #define PRESET_SGRF_HOLD(n)	((0x1 << (6 + 16)) | ((n) << 6))
 #define PRESET_GPIO0_HOLD(n)	((0x1 << (7 + 16)) | ((n) << 7))
 #define PRESET_GPIO1_HOLD(n)	((0x1 << (8 + 16)) | ((n) << 8))
@@ -1632,7 +1638,9 @@ static void set_ddr_stride(struct rk3399_pmusgrf_regs *pmusgrf, u32 stride)
 	rk_clrsetreg(&pmusgrf->soc_con4, 0x1f << 10, stride << 10);
 }
 
-#if !defined(CONFIG_RAM_ROCKCHIP_LPDDR4)
+#if !defined(CONFIG_RAM_ROCKCHIP_LPDDR4) && \
+	(defined(CONFIG_RAM_ROCKCHIP_DDR3) || \
+	 defined(CONFIG_RAM_ROCKCHIP_LPDDR3))
 static int data_training_first(struct dram_info *dram, u32 channel, u8 rank,
 			       struct rk3399_sdram_params *params)
 {
@@ -3068,7 +3076,9 @@ static int conv_of_plat(struct udevice *dev)
 #endif
 
 static const struct sdram_rk3399_ops rk3399_ops = {
-#if !defined(CONFIG_RAM_ROCKCHIP_LPDDR4)
+#if !defined(CONFIG_RAM_ROCKCHIP_LPDDR4) && \
+	(defined(CONFIG_RAM_ROCKCHIP_DDR3) || \
+	 defined(CONFIG_RAM_ROCKCHIP_LPDDR3))
 	.data_training_first = data_training_first,
 	.set_rate_index = switch_to_phy_index1,
 	.modify_param = modify_param,
drivers/ram/rockchip/sdram_rv1126.c +3 -1
index b371f597d23..2d101d6af3a 100644
@@ -83,7 +83,7 @@ struct rv1126_sdram_params sdram_configs[] = {
 # include	"sdram-rv1126-ddr4-detect-784.inc"
 # include	"sdram-rv1126-ddr4-detect-924.inc"
 # include	"sdram-rv1126-ddr4-detect-1056.inc"
-#else
+#elif defined(CONFIG_RAM_ROCKCHIP_DDR3)
 # include	"sdram-rv1126-ddr3-detect-328.inc"
 # include	"sdram-rv1126-ddr3-detect-396.inc"
 # include	"sdram-rv1126-ddr3-detect-528.inc"
@@ -91,6 +91,8 @@ struct rv1126_sdram_params sdram_configs[] = {
 # include	"sdram-rv1126-ddr3-detect-784.inc"
 # include	"sdram-rv1126-ddr3-detect-924.inc"
 # include	"sdram-rv1126-ddr3-detect-1056.inc"
+#else
+#error "Please select a DRAM type via a CONFIG_RAM_ROCKCHIP_* option"
 #endif
 };
 
Signature · 1 line
2.34.1
#3 lore raw

PATCH v4 3/4 ram: rockchip: raise error when configuration is unsupported

In reply to Massimo Pegorer

The PX30 and RV1126 SDRAM drivers support more SDRAM types but only one type at a time, really. The type to support is selected through RAM_ROCKCHIP_XXX configuration options: raise a compile-time error if more than one of these options is selected, instead of relying on a debatable and embedded priority order to choose the one to support among the selected.

The RK3399 SDRAM driver supports DDR3 and LPDDR3 types, or alternatively, LPDDR4 type, but not all of them at the same time. Raise a compile-time error if RAM_ROCKCHIP_LPDDR4 config option is selected together with DDR3 and/or LPDDR3 options, instead of silently ignoring the DDR3/LPDDR3 selections and prioritizing LPDDR4 support.

---
 drivers/ram/rockchip/sdram_px30.c   | 7 +++++++
 drivers/ram/rockchip/sdram_rk3399.c | 6 ++++++
 drivers/ram/rockchip/sdram_rv1126.c | 6 ++++++
 3 files changed, 19 insertions(+)
drivers/ram/rockchip/sdram_px30.c +7 -0
index 0b6d3723409..139e6eab060 100644
@@ -123,6 +123,13 @@ u32 addrmap[][8] = {
 
 struct dram_info dram_info;
 
+#if defined(CONFIG_RAM_ROCKCHIP_DDR3) + \
+	defined(CONFIG_RAM_ROCKCHIP_DDR4) + \
+	defined(CONFIG_RAM_ROCKCHIP_LPDDR2) + \
+	defined(CONFIG_RAM_ROCKCHIP_LPDDR3) > 1
+#error "This driver only supports one DRAM configuration at a time"
+#endif
+
 struct px30_sdram_params sdram_configs[] = {
 #if defined(CONFIG_RAM_ROCKCHIP_DDR4)
 #include	"sdram-px30-ddr4-detect-333.inc"
drivers/ram/rockchip/sdram_rk3399.c +6 -0
index 5bc6f3a39fd..3daad319a57 100644
@@ -26,6 +26,12 @@
 #include <linux/err.h>
 #include <time.h>
 
+#if defined(CONFIG_RAM_ROCKCHIP_LPDDR4) && \
+	(defined(CONFIG_RAM_ROCKCHIP_DDR3) || \
+	 defined(CONFIG_RAM_ROCKCHIP_LPDDR3))
+#error "This driver only supports DDR3/LPDDR3 or LPDDR4 at a time"
+#endif
+
 #if !defined(CONFIG_RAM_ROCKCHIP_DDR3) && \
 	!defined(CONFIG_RAM_ROCKCHIP_LPDDR3) && \
 	!defined(CONFIG_RAM_ROCKCHIP_LPDDR4)
drivers/ram/rockchip/sdram_rv1126.c +6 -0
index 2d101d6af3a..c914e976bc7 100644
@@ -66,6 +66,12 @@ struct dram_info {
 
 struct dram_info dram_info;
 
+#if defined(CONFIG_RAM_ROCKCHIP_DDR3) + \
+	defined(CONFIG_RAM_ROCKCHIP_DDR4) + \
+	defined(CONFIG_RAM_ROCKCHIP_LPDDR4) > 1
+#error "This driver only supports one DRAM configuration at a time"
+#endif
+
 struct rv1126_sdram_params sdram_configs[] = {
 #if defined(CONFIG_RAM_ROCKCHIP_LPDDR4)
 # include	"sdram-rv1126-lpddr4-detect-328.inc"
Signature · 1 line
2.34.1
#4 lore raw

PATCH v4 4/4 ram: rockchip: rk3399: support multiple SDRAM types at a time

In reply to Massimo Pegorer

Allow the SDRAM driver to have DDR3/LPDDR3 and LPDDR4 support built-in at the same time. The driver chooses how to initialize the controller based on the SDRAM type property value read from the Device Tree.

This introduces the following behavioral change: if the driver is built with LPDDR4 support only and the Device Tree reports a DDR3 or LPDDR3 SDRAM type, the driver refuses to initialize the controller and return immediately. The same applies when only DDR3/LPDDR3 support is built-in and the Device Tree reports LPDDR4. Previously, the driver would have tried to initialize the controller in any case, even when the Device Tree was reporting an unsupported SDRAM type.

The average TPL size increase for RK3399 board configurations is 80.3 bytes with maximum of 86 bytes (buildman report).

---
 drivers/ram/rockchip/sdram_rk3399.c | 53 +++++++++++++++++++++++--------------
 1 file changed, 33 insertions(+), 20 deletions(-)
drivers/ram/rockchip/sdram_rk3399.c +33 -20
index 3daad319a57..2386332c498 100644
@@ -26,12 +26,6 @@
 #include <linux/err.h>
 #include <time.h>
 
-#if defined(CONFIG_RAM_ROCKCHIP_LPDDR4) && \
-	(defined(CONFIG_RAM_ROCKCHIP_DDR3) || \
-	 defined(CONFIG_RAM_ROCKCHIP_LPDDR3))
-#error "This driver only supports DDR3/LPDDR3 or LPDDR4 at a time"
-#endif
-
 #if !defined(CONFIG_RAM_ROCKCHIP_DDR3) && \
 	!defined(CONFIG_RAM_ROCKCHIP_LPDDR3) && \
 	!defined(CONFIG_RAM_ROCKCHIP_LPDDR4)
@@ -1644,9 +1638,7 @@ static void set_ddr_stride(struct rk3399_pmusgrf_regs *pmusgrf, u32 stride)
 	rk_clrsetreg(&pmusgrf->soc_con4, 0x1f << 10, stride << 10);
 }
 
-#if !defined(CONFIG_RAM_ROCKCHIP_LPDDR4) && \
-	(defined(CONFIG_RAM_ROCKCHIP_DDR3) || \
-	 defined(CONFIG_RAM_ROCKCHIP_LPDDR3))
+#if defined(CONFIG_RAM_ROCKCHIP_DDR3) || defined(CONFIG_RAM_ROCKCHIP_LPDDR3)
 static int data_training_first(struct dram_info *dram, u32 channel, u8 rank,
 			       struct rk3399_sdram_params *params)
 {
@@ -1737,7 +1729,9 @@ void modify_param(const struct chan_info *chan,
 	clrsetbits_le32(&denali_pi_params[76], 0x1 << 24, 0x1 << 24);
 	clrsetbits_le32(&denali_pi_params[77], 0x1, 0x1);
 }
-#else
+#endif /* CONFIG_RAM_ROCKCHIP_DDR3 || CONFIG_RAM_ROCKCHIP_LPDDR3 */
+
+#if defined(CONFIG_RAM_ROCKCHIP_LPDDR4)
 
 struct rk3399_sdram_params dfs_cfgs_lpddr4[] = {
 #include "sdram-rk3399-lpddr4-400.inc"
@@ -2978,9 +2972,11 @@ static int sdram_init(struct dram_info *dram,
 	}
 
 #if defined(CONFIG_RAM_ROCKCHIP_LPDDR4)
-	/* LPDDR4 needs to be trained at 400MHz */
-	lpddr4_set_rate(dram, params, 0);
-	params->base.ddr_freq = dfs_cfgs_lpddr4[0].base.ddr_freq / MHz;
+	if (dramtype == LPDDR4) {
+		/* LPDDR4 needs to be trained at 400MHz */
+		lpddr4_set_rate(dram, params, 0);
+		params->base.ddr_freq = dfs_cfgs_lpddr4[0].base.ddr_freq / MHz;
+	}
 #endif
 
 	params->base.num_channels = 0;
@@ -3081,21 +3077,23 @@ static int conv_of_plat(struct udevice *dev)
 }
 #endif
 
-static const struct sdram_rk3399_ops rk3399_ops = {
-#if !defined(CONFIG_RAM_ROCKCHIP_LPDDR4) && \
-	(defined(CONFIG_RAM_ROCKCHIP_DDR3) || \
-	 defined(CONFIG_RAM_ROCKCHIP_LPDDR3))
+#if defined(CONFIG_RAM_ROCKCHIP_DDR3) || defined(CONFIG_RAM_ROCKCHIP_LPDDR3)
+static const struct sdram_rk3399_ops rk3399_ddr3_lpddr3_ops = {
 	.data_training_first = data_training_first,
 	.set_rate_index = switch_to_phy_index1,
 	.modify_param = modify_param,
 	.get_phy_index_params = get_phy_index_params,
-#else
+};
+#endif
+
+#if defined(CONFIG_RAM_ROCKCHIP_LPDDR4)
+static const struct sdram_rk3399_ops rk3399_lpddr4_ops = {
 	.data_training_first = lpddr4_mr_detect,
 	.set_rate_index = lpddr4_set_rate,
 	.modify_param = lpddr4_modify_param,
 	.get_phy_index_params = lpddr4_get_phy_index_params,
-#endif
 };
+#endif
 
 static int rk3399_dmc_init(struct udevice *dev)
 {
@@ -3114,7 +3112,22 @@ static int rk3399_dmc_init(struct udevice *dev)
 		return ret;
 #endif
 
-	priv->ops = &rk3399_ops;
+#if defined(CONFIG_RAM_ROCKCHIP_DDR3) || defined(CONFIG_RAM_ROCKCHIP_LPDDR3)
+	if (params->base.dramtype == DDR3 || params->base.dramtype == LPDDR3)
+		priv->ops = &rk3399_ddr3_lpddr3_ops;
+#endif
+
+#if defined(CONFIG_RAM_ROCKCHIP_LPDDR4)
+	if (params->base.dramtype == LPDDR4)
+		priv->ops = &rk3399_lpddr4_ops;
+#endif
+
+	if (!priv->ops) {
+		printf("no ops found for requested dramtype (%d)\n",
+		       params->base.dramtype);
+		return -EINVAL;
+	}
+
 	priv->cic = syscon_get_first_range(ROCKCHIP_SYSCON_CIC);
 	priv->grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
 	priv->pmu = syscon_get_first_range(ROCKCHIP_SYSCON_PMU);
Signature · 1 line
2.34.1