Skip to contentSkip to conversation

Improve Rockchip SDRAM types support configuration

PATCH In review Massimo Pegorer 3 participants 13 messages Nov 16 – Nov 20 Arm Rockchip

lore
Share & tools
lore
#0 lore raw

v3 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 and RV1126 configurations to select one of the RAM_ROCKCHIP_XXX 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 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.

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

---
Changes in v3:
- Split 1/4 of v2 into 3 different patches as follow:
-- 1/4 only add SoC guards to Rockchip SDRAM config options.
-- 2/4 new DDR3 config option and raise error if no SDRAM type is selected. -- 3/4 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 (3):
ram: rockchip: improve sdram type configs selection
ram: rockchip: add DDR3 sdram type config option
ram: rockchip: raise error when configuration is unsupported

 drivers/ram/rockchip/Kconfig        | 24 ++++++++++++++++--------
 drivers/ram/rockchip/sdram_px30.c   | 11 ++++++++++-
 drivers/ram/rockchip/sdram_rv1126.c | 10 +++++++++-
 3 files changed, 35 insertions(+), 10 deletions(-)

---
base-commit: 701db9119cefeed95b77df90359cf96f78a5823f
change-id: 20260828-ddr-multi-2c4fd64344c8

Best regards,

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

PATCH v3 1/3 ram: rockchip: improve sdram type configs selection

Not all the SDRAM types configuration options named in the Kconfig are supported by each of the Rockchip SoCs: improve clarity adding SoC dependencies to the options.

---
 drivers/ram/rockchip/Kconfig | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/ram/rockchip/Kconfig +8 -8
index d707d09c1c8..74422947452 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
 	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
Reviewed-by on v3 1/3
#2 lore raw

Re: [PATCH v3 1/3] ram: rockchip: improve sdram type configs selection

Hi Massimo,

Quoted 4 lines · Massimo Pegorer

Not all the SDRAM types configuration options named in the Kconfig are supported by each of the Rockchip SoCs: improve clarity adding SoC dependencies to the options.

Considering what I said[1], I'm wondering if we shouldn't simply report what the driver (seems to) supports even if it doesn't actually use #ifdefery and the symbol state has no impact on what will make it into the final binary. I haven't decided yet, so this is an open question rather than a suggestion, and this applies to the "thought: " comments below.

[1] https://lore.kernel.org/u-boot/[email protected]/

Quoted 10 lines
---
  drivers/ram/rockchip/Kconfig | 16 ++++++++--------
  1 file changed, 8 insertions(+), 8 deletions(-)
drivers/ram/rockchip/Kconfig +0 -0
index d707d09c1c8..74422947452 100644

drivers/ram/rockchip/Kconfig config RAM_ROCKCHIP_DEBUG · line 29

Quoted 4 lines
drivers/ram/rockchip/Kconfig +1 -0
@@ -26,26 +26,26 @@ config RAM_ROCKCHIP_DEBUG
 
  config RAM_ROCKCHIP_DDR4
  	bool "DDR4 support for Rockchip SoCs"
+	depends on ROCKCHIP_PX30 || ROCKCHIP_RV1126

thought: add ROCKCHIP_RK3328?

drivers/ram/rockchip/Kconfig config RAM_ROCKCHIP_DEBUG · line 35

Quoted 8 lines
drivers/ram/rockchip/Kconfig +2 -2
  	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

thought: add ROCKCHIP_RK322X?

drivers/ram/rockchip/Kconfig config RAM_ROCKCHIP_DEBUG · line 41

Quoted 8 lines
drivers/ram/rockchip/Kconfig +2 -2
  	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

thought: add ROCKCHIP_RK3066 || ROCKCHIP_RK3188 || ROCKCHIP_RK322X || ROCKCHIP_RK3288 || ROCKCHIP_RK3328 || ROCKCHIP_RK3399 || ROCKCHIP_RV1126?

Please remove the Reviewed-by if there's a v4 and we decide to go for more SoCs in the depends part of the Kconfig symbol, thanks!

Quentin

#3 lore raw

Re: [PATCH v3 1/3] ram: rockchip: improve sdram type configs selection

Hi Quentin,

Il giorno mar 17 nov 2026 alle ore 17:29 Quentin Schulz <[email protected]> ha scritto:

Quoted 16 lines

Hi Massimo,

Quoted 4 lines · Massimo Pegorer

Not all the SDRAM types configuration options named in the Kconfig are supported by each of the Rockchip SoCs: improve clarity adding SoC dependencies to the options.

Considering what I said[1], I'm wondering if we shouldn't simply report what the driver (seems to) supports even if it doesn't actually use #ifdefery and the symbol state has no impact on what will make it into the final binary. I haven't decided yet, so this is an open question rather than a suggestion, and this applies to the "thought: " comments below.

Quoted 2 lines

[1]
https://lore.kernel.org/u-boot/[email protected]/

Happy to discuss and share opinions: hope others will join, too!

I would start from: "What is the purpose for?"

I expect a config option value to change the final result of the build. And I would prefer not to see any config option that is not relevant to what I'm going to build, at all.

As an example, if I'm building U-Boot for RK3328, what should happen if I choose DDR3 or DDR4 or LPDDR3 or none or any combination of them? The compiled driver will be the same in all cases. Would you like to raise an error if none or more than one is selected? Or instead, should the ROCKCHIP_RK3328 config option select all of them? In any case, the DRAM params will be defined by the Device Tree, and everything will work even if they do not match the selected option.

In the end, the only purpose I see here is information and documentation. I do not think that doing this type of documentation through config options is the best way.

But let me know your reasoning, please.

Thanks. Regards,
Massimo

Quoted 47 lines
Quoted 11 lines
---
  drivers/ram/rockchip/Kconfig | 16 ++++++++--------
  1 file changed, 8 insertions(+), 8 deletions(-)
drivers/ram/rockchip/Kconfig +0 -0
index d707d09c1c8..74422947452 100644

drivers/ram/rockchip/Kconfig config RAM_ROCKCHIP_DEBUG · line 29

Quoted 4 lines
drivers/ram/rockchip/Kconfig +1 -0
@@ -26,26 +26,26 @@ config RAM_ROCKCHIP_DEBUG
 
  config RAM_ROCKCHIP_DDR4
      bool "DDR4 support for Rockchip SoCs"
+     depends on ROCKCHIP_PX30 || ROCKCHIP_RV1126

thought: add ROCKCHIP_RK3328?

drivers/ram/rockchip/Kconfig config RAM_ROCKCHIP_DEBUG · line 35

Quoted 8 lines
drivers/ram/rockchip/Kconfig +2 -2
      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

thought: add ROCKCHIP_RK322X?

drivers/ram/rockchip/Kconfig config RAM_ROCKCHIP_DEBUG · line 41

Quoted 8 lines
drivers/ram/rockchip/Kconfig +2 -2
      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

thought: add ROCKCHIP_RK3066 || ROCKCHIP_RK3188 || ROCKCHIP_RK322X || ROCKCHIP_RK3288 || ROCKCHIP_RK3328 || ROCKCHIP_RK3399 || ROCKCHIP_RV1126?

Please remove the Reviewed-by if there's a v4 and we decide to go for more SoCs in the depends part of the Kconfig symbol, thanks!

Quentin

#4 lore raw

Re: [PATCH v3 1/3] ram: rockchip: improve sdram type configs selection

Hi Massimo,

Quoted 27 lines · Massimo Pegorer

Hi Quentin,

Il giorno mar 17 nov 2026 alle ore 17:29 Quentin Schulz <[email protected]> ha scritto:

Quoted 16 lines

Hi Massimo,

Quoted 4 lines · Massimo Pegorer

Not all the SDRAM types configuration options named in the Kconfig are supported by each of the Rockchip SoCs: improve clarity adding SoC dependencies to the options.

Considering what I said[1], I'm wondering if we shouldn't simply report what the driver (seems to) supports even if it doesn't actually use #ifdefery and the symbol state has no impact on what will make it into the final binary. I haven't decided yet, so this is an open question rather than a suggestion, and this applies to the "thought: " comments below.

Quoted 2 lines

[1]
https://lore.kernel.org/u-boot/[email protected]/

Happy to discuss and share opinions: hope others will join, too!

I would start from: "What is the purpose for?"

Quoted 8 lines

I expect a config option value to change the final result of the build. And I would prefer not to see any config option that is not relevant to what I'm going to build, at all.

As an example, if I'm building U-Boot for RK3328, what should happen if I choose DDR3 or DDR4 or LPDDR3 or none or any combination of them? The compiled driver will be the same in all cases. Would you like to raise an error if none or more than one is selected? Or instead, should the ROCKCHIP_RK3328 config

If none, yes. If more than one, then no as the driver currently supports multiple (just configured via the Device Tree instead of detecting which DRAM is populated) and there's no ifdefery so no point in failing.

Quoted 10 lines

option select all of them? In any case, the DRAM params will be defined by the Device Tree, and everything will work even if they do not match the selected option.

In the end, the only purpose I see here is information and documentation. I do not think that doing this type of documentation through config options is the best way.

But let me know your reasoning, please.

Mostly informative right now, however we could also decide to use that as a way to trim down the DRAM drivers with support only for what the user requested. If the DTS then doesn't match what's in the driver, of course DRAM init won't work. There are a few if blocks we could avoid in drivers/ram/rockchip/sdram_common.c for example.

Cheers,
Quentin

#5 lore raw

PATCH v3 2/3 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 and RV1126 sdram drivers' fallback behaviour, which consists of using DDR3 sdram parameters when no RAM_ROCKCHIP_XXX 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 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_rv1126.c | 4 +++-
 3 files changed, 14 insertions(+), 2 deletions(-)
drivers/ram/rockchip/Kconfig +8 -0
index 74422947452..f51ae6a4542 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_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..bdb9cc9031d 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 suitable DRAM type CONFIG_RAM_ROCKCHIP option"
 #endif
 };
 
drivers/ram/rockchip/sdram_rv1126.c +3 -1
index b371f597d23..3d7cd076a51 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 suitable DRAM type CONFIG_RAM_ROCKCHIP option"
 #endif
 };
 
Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH v3 2/3] ram: rockchip: add DDR3 sdram type config option

Hi Massimo,

Quoted 20 lines · Massimo Pegorer

Add new RAM_ROCKCHIP_DDR3 sdram type configuration option and drop the PX30 and RV1126 sdram drivers' fallback behaviour, which consists of using DDR3 sdram parameters when no RAM_ROCKCHIP_XXX 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 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_rv1126.c | 4 +++-
  3 files changed, 14 insertions(+), 2 deletions(-)
drivers/ram/rockchip/Kconfig +0 -0
index 74422947452..f51ae6a4542 100644

drivers/ram/rockchip/Kconfig config RAM_ROCKCHIP_DEBUG · line 29

Quoted 6 lines
drivers/ram/rockchip/Kconfig +3 -0
@@ -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_RV1126

Same remark/question/thought as the previous patch wrt currently unlisted SoCs:

thought: add ROCKCHIP_RK3036 || ROCKCHIP_RK3368 || ROCKCHIP_RK3066 || ROCKCHIP_RK3188 || ROCKCHIP_RK322X || ROCKCHIP_RK3288 || ROCKCHIP_RK3328 || ROCKCHIP_RK3399?

Quoted 13 lines
drivers/ram/rockchip/Kconfig +5 -0
+	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 +0 -0
index 37e62120504..bdb9cc9031d 100644

drivers/ram/rockchip/sdram_px30.c struct px30_sdram_params sdram_configs[] = { · line 136

Quoted 8 lines
drivers/ram/rockchip/sdram_px30.c +3 -1
@@ -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 suitable DRAM type CONFIG_RAM_ROCKCHIP option"

issue: misleading Kconfig symbol

We already have a CONFIG_RAM_ROCKCHIP option and it must be enabled for the build system to even be able to compile this file. This means that the user will be told "look at this option" and it's already enabled. I would suggest instead:

Please select a DRAM type via a CONFIG_RAM_ROCKCHIP_* option

what do you think?

Quoted 17 lines
drivers/ram/rockchip/sdram_px30.c +0 -0
  #endif
  };
 
drivers/ram/rockchip/sdram_rv1126.c +1 -1
index b371f597d23..3d7cd076a51 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"

drivers/ram/rockchip/sdram_rv1126.c struct rv1126_sdram_params sdram_configs[] = { · line 95

Quoted 5 lines
drivers/ram/rockchip/sdram_rv1126.c +2 -0
@@ -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 suitable DRAM type CONFIG_RAM_ROCKCHIP option"

issue: misleading Kconfig symbol

See above for suggestion.

Cheers,
Quentin

#7 lore raw

Re: [PATCH v3 2/3] ram: rockchip: add DDR3 sdram type config option

Hi Quentin,

Il giorno mar 17 nov 2026 alle ore 17:35 Quentin Schulz <[email protected]> ha scritto:

Quoted 62 lines

Hi Massimo,

Quoted 20 lines · Massimo Pegorer

Add new RAM_ROCKCHIP_DDR3 sdram type configuration option and drop the PX30 and RV1126 sdram drivers' fallback behaviour, which consists of using DDR3 sdram parameters when no RAM_ROCKCHIP_XXX 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 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_rv1126.c | 4 +++-
  3 files changed, 14 insertions(+), 2 deletions(-)
drivers/ram/rockchip/Kconfig +0 -0
index 74422947452..f51ae6a4542 100644

drivers/ram/rockchip/Kconfig config RAM_ROCKCHIP_DEBUG · line 29

Quoted 6 lines
drivers/ram/rockchip/Kconfig +3 -0
@@ -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_RV1126

Same remark/question/thought as the previous patch wrt currently unlisted SoCs:

thought: add ROCKCHIP_RK3036 || ROCKCHIP_RK3368 || ROCKCHIP_RK3066 || ROCKCHIP_RK3188 || ROCKCHIP_RK322X || ROCKCHIP_RK3288 || ROCKCHIP_RK3328 || ROCKCHIP_RK3399?

Quoted 13 lines
drivers/ram/rockchip/Kconfig +5 -0
+     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 +0 -0
index 37e62120504..bdb9cc9031d 100644

drivers/ram/rockchip/sdram_px30.c struct px30_sdram_params sdram_configs[] = { · line 136

Quoted 8 lines
drivers/ram/rockchip/sdram_px30.c +3 -1
@@ -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 suitable DRAM type CONFIG_RAM_ROCKCHIP option"

issue: misleading Kconfig symbol

Quoted 8 lines

We already have a CONFIG_RAM_ROCKCHIP option and it must be enabled for the build system to even be able to compile this file. This means that the user will be told "look at this option" and it's already enabled. I would suggest instead:

Please select a DRAM type via a CONFIG_RAM_ROCKCHIP_* option

what do you think?

Totally agree. The intention of the message was something like "Please select the config option prefixed with CONFIG_RAM_ROCKCHIP and related to the DRAM type needed by your build". Your proposal is certainly less prone to misunderstanding (unfortunately, RAM_ROCKCHIP_DEBUG also matches the expression).

I will fix in v4 with your suggestion. Thanks.

Regards,
Massimo

Quoted 30 lines
Quoted 18 lines
drivers/ram/rockchip/sdram_px30.c +0 -0
  #endif
  };
 
drivers/ram/rockchip/sdram_rv1126.c +1 -1
index b371f597d23..3d7cd076a51 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"

drivers/ram/rockchip/sdram_rv1126.c struct rv1126_sdram_params sdram_configs[] = { · line 95

Quoted 5 lines
drivers/ram/rockchip/sdram_rv1126.c +2 -0
@@ -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 suitable DRAM type CONFIG_RAM_ROCKCHIP option"

issue: misleading Kconfig symbol

See above for suggestion.

Cheers,
Quentin

#8 lore raw

PATCH v3 3/3 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.

---
 drivers/ram/rockchip/sdram_px30.c   | 7 +++++++
 drivers/ram/rockchip/sdram_rv1126.c | 6 ++++++
 2 files changed, 13 insertions(+)
drivers/ram/rockchip/sdram_px30.c +7 -0
index bdb9cc9031d..14d8f2e293a 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_rv1126.c +6 -0
index 3d7cd076a51..518ce307cc1 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
Reviewed-by on v3 3/3
#9 lore raw

Re: [PATCH v3 3/3] ram: rockchip: raise error when configuration is unsupported

Hi Massimo,

Quoted 7 lines · 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.

If we add ROCKCHIP_RK3399 to the depends of RAM_ROCKCHIP_LPDDR3/RAM_ROCKCHIP_DDR3 and RAM_ROCKCHIP_LPDDR4, I think we should add a similar check in the rk3399 driver to refuse to build if there's LPDDR4 and either of RAM_ROCKCHIP_LPDDR3/RAM_ROCKCHIP_DDR3 enabled. What do you think?

Thanks!
Quentin

#10 lore raw

Re: [PATCH v3 3/3] ram: rockchip: raise error when configuration is unsupported

Hi Quentin,

Il giorno mar 17 nov 2026 alle ore 17:40 Quentin Schulz <[email protected]> ha scritto:

Quoted 12 lines

Hi Massimo,

Quoted 7 lines · 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.

Quoted 7 lines

If we add ROCKCHIP_RK3399 to the depends of RAM_ROCKCHIP_LPDDR3/RAM_ROCKCHIP_DDR3 and RAM_ROCKCHIP_LPDDR4, I think we should add a similar check in the rk3399 driver to refuse to build if there's LPDDR4 and either of RAM_ROCKCHIP_LPDDR3/RAM_ROCKCHIP_DDR3 enabled. What do you think?

Unfortunately I did not come to a clean solution for the RK3399 sdram driver "singularity". At least, not enough clear for my taste. So I left untouched, open to discussion.

Let's suppose we also have ROCKCHIP_RK3399 in the dependencies of RAM_ROCKCHIP_LPDDR3 and RAM_ROCKCHIP_DDR3, something like:

config RAM_ROCKCHIP_DDR3

        depends on ROCKCHIP_PX30 || ROCKCHIP_RK3399 || ROCKCHIP_RV1126

config RAM_ROCKCHIP_LPDDR3

        depends on ROCKCHIP_PX30 || ROCKCHIP_RK3399

Some compile-time checks in the source code can easily be added to raise an error if LPDDR4 is selected but it is not the only one, or if none is selected.

The point that annoys me is that, in RK3399's case, the two options RAM_ROCKCHIP_DDR3 and RAM_ROCKCHIP_LPDDR3 are the same thing, in the end. If it would be possible to have their values coordinated, I would be happy, but I do not think it is. Using the Kconfig 'select' statement will force one to be true when the other is selected. But unfortunately, this does not work when unselecting options. So, if one is selected but the other is not, what should we do in this case: raise an error, or silently ignore it since it does not affect the build?

An alternative could be to use an RK3399-specific config option, something like RAM_ROCKCHIP_DDR3_LPDDR3 but... ...it's quite disgusting.

Let me know what do you think.

Regards,
Massimo

Quoted 3 lines

Thanks!
Quentin

#11 lore raw

Re: [PATCH v3 3/3] ram: rockchip: raise error when configuration is unsupported

Hi Massimo,

Quoted 40 lines · Massimo Pegorer

Hi Quentin,

Il giorno mar 17 nov 2026 alle ore 17:40 Quentin Schulz <[email protected]> ha scritto:

Quoted 12 lines

Hi Massimo,

Quoted 7 lines · 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.

Quoted 7 lines

If we add ROCKCHIP_RK3399 to the depends of RAM_ROCKCHIP_LPDDR3/RAM_ROCKCHIP_DDR3 and RAM_ROCKCHIP_LPDDR4, I think we should add a similar check in the rk3399 driver to refuse to build if there's LPDDR4 and either of RAM_ROCKCHIP_LPDDR3/RAM_ROCKCHIP_DDR3 enabled. What do you think?

Unfortunately I did not come to a clean solution for the RK3399 sdram driver "singularity". At least, not enough clear for my taste. So I left untouched, open to discussion.

Let's suppose we also have ROCKCHIP_RK3399 in the dependencies of RAM_ROCKCHIP_LPDDR3 and RAM_ROCKCHIP_DDR3, something like:

config RAM_ROCKCHIP_DDR3

         depends on ROCKCHIP_PX30 || ROCKCHIP_RK3399 || ROCKCHIP_RV1126

config RAM_ROCKCHIP_LPDDR3

         depends on ROCKCHIP_PX30 || ROCKCHIP_RK3399

Some compile-time checks in the source code can easily be added to raise an error if LPDDR4 is selected but it is not the only one, or if none is selected.

Quoted 9 lines

The point that annoys me is that, in RK3399's case, the two options RAM_ROCKCHIP_DDR3 and RAM_ROCKCHIP_LPDDR3 are the same thing, in the end. If it would be possible to have their values coordinated, I would be happy, but I do not think it is. Using the Kconfig 'select' statement will force one to be true when the other is selected. But unfortunately, this does not work when unselecting options. So, if one is selected but the other is not, what should we do in this case: raise an error, or silently ignore it since it does not affect the build?

I think it's fine if we have DDR3/LPDDR3 selected but will use LPDDR3/DDR3 based on Device Tree. We can make them really mean something by gating LPDDR3-/DDR3-specific code, but I'm not sure it's that worth it right now. Something worth investigating if we need to shed some bytes in TPL/SPL.

Quoted 3 lines

An alternative could be to use an RK3399-specific config option, something like RAM_ROCKCHIP_DDR3_LPDDR3 but... ...it's quite disgusting.

Nope, don't want to go this route :)

Another option is to make the RK3399 driver capable of handling LPDDR3/DDR3 AND LPDDR4 at the same time (no autodetection of the populated DRAM type, still read the type from Device Tree), then it becomes less of a headache. You can have LPDDR3/DDR3, and/or LPDDR4, and it gets easier in the Kconfig symbols.

I quickly came up with (didn't test aside building):

"""

drivers/ram/rockchip/sdram_rk3399.c +1 -1
index 6fa8f268770d..22d196f1bec7 100644
@@ -1632,7 +1632,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)
+#if defined(CONFIG_RAM_ROCKCHIP_LPDDR3) || defined(CONFIG_RAM_ROCKCHIP_DDR3)
 static int data_training_first(struct dram_info *dram, u32 channel, u8 

rank,
struct rk3399_sdram_params *params)
{
@@ -1723,7 +1723,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
+
+#if defined(CONFIG_RAM_ROCKCHIP_LPDDR4)

struct rk3399_sdram_params dfs_cfgs_lpddr4[] = { #include "sdram-rk3399-lpddr4-400.inc"
@@ -2964,9 +2966,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;
@@ -3067,19 +3071,23 @@ 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_LPDDR3) || defined(CONFIG_RAM_ROCKCHIP_DDR3) +static const struct sdram_rk3399_ops rk3399_lpddr3_ddr3_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)
{
@@ -3098,7 +3106,21 @@ static int rk3399_dmc_init(struct udevice *dev)
return ret;
#endif

- priv->ops = &rk3399_ops;
+#if defined(CONFIG_RAM_ROCKCHIP_LPDDR4)
+ if (params->base.dramtype == LPDDR4)
+ priv->ops = &rk3399_lpddr4_ops;
+#endif
+#if defined(CONFIG_RAM_ROCKCHIP_LPDDR3) || defined(CONFIG_RAM_ROCKCHIP_DDR3)
+ if (params->base.dramtype == LPDDR3 || params->base.dramtype == DDR3)
+ priv->ops = &rk3399_lpddr3_ddr3_ops;
+#endif
+
+ if (priv->ops == NULL) {
+ 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);
"""

Of course, we need to update the existing defconfigs to reflect that change as !LPDDR4 used to mean LPDDR3/DDR3 but not anymore. An intermediary step could be to have DDR3/LPDDR3 default y if !LPDDR4 so we avoid changing the defconfigs with the driver patch, and then remove the default y in a follow-up commit by making the rk3399 defconfigs enable the appropriate one (easy to find based on the Device Tree they include).

Finally, with the above diff, you can technically build the RK3399 driver without any of LPDDR3/DDR3/DDR4 enabled, which can be remediated by an ifdef check at the top like you've done for PX30/RV1126, just that we *want* to check that their sum is NOT 0, anything else would be fine.

What do you think?

Cheers,
Quentin

#12 lore raw

Re: [PATCH v3 3/3] ram: rockchip: raise error when configuration is unsupported

Hi Quentin,

Il giorno gio 19 nov 2026 alle ore 16:14 Quentin Schulz ha scritto:

Quoted 63 lines

Hi Massimo,

Quoted 40 lines · Massimo Pegorer

Hi Quentin,

Il giorno mar 17 nov 2026 alle ore 17:40 Quentin Schulz <[email protected]> ha scritto:

Quoted 12 lines

Hi Massimo,

Quoted 7 lines · 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.

Quoted 7 lines

If we add ROCKCHIP_RK3399 to the depends of RAM_ROCKCHIP_LPDDR3/RAM_ROCKCHIP_DDR3 and RAM_ROCKCHIP_LPDDR4, I think we should add a similar check in the rk3399 driver to refuse to build if there's LPDDR4 and either of RAM_ROCKCHIP_LPDDR3/RAM_ROCKCHIP_DDR3 enabled. What do you think?

Unfortunately I did not come to a clean solution for the RK3399 sdram driver "singularity". At least, not enough clear for my taste. So I left untouched, open to discussion.

Let's suppose we also have ROCKCHIP_RK3399 in the dependencies of RAM_ROCKCHIP_LPDDR3 and RAM_ROCKCHIP_DDR3, something like:

config RAM_ROCKCHIP_DDR3

         depends on ROCKCHIP_PX30 || ROCKCHIP_RK3399 || ROCKCHIP_RV1126

config RAM_ROCKCHIP_LPDDR3

         depends on ROCKCHIP_PX30 || ROCKCHIP_RK3399

Some compile-time checks in the source code can easily be added to raise an error if LPDDR4 is selected but it is not the only one, or if none is selected.

Quoted 9 lines

The point that annoys me is that, in RK3399's case, the two options RAM_ROCKCHIP_DDR3 and RAM_ROCKCHIP_LPDDR3 are the same thing, in the end. If it would be possible to have their values coordinated, I would be happy, but I do not think it is. Using the Kconfig 'select' statement will force one to be true when the other is selected. But unfortunately, this does not work when unselecting options. So, if one is selected but the other is not, what should we do in this case: raise an error, or silently ignore it since it does not affect the build?

I think it's fine if we have DDR3/LPDDR3 selected but will use LPDDR3/DDR3 based on Device Tree. We can make them really mean something by gating LPDDR3-/DDR3-specific code, but I'm not sure it's that worth it right now. Something worth investigating if we need to shed some bytes in TPL/SPL.

Quoted 3 lines

An alternative could be to use an RK3399-specific config option, something like RAM_ROCKCHIP_DDR3_LPDDR3 but... ...it's quite disgusting.

Quoted 5 lines

Nope, don't want to go this route :)

Another option is to make the RK3399 driver capable of handling LPDDR3/DDR3 AND LPDDR4 at the same time (no autodetection of the populated DRAM type, still read the type from Device Tree), then it

This (driver capable of handling all types at the same time) seems to me the most reasonable due to the fact that, indeed, the SDRAM type and parameters are read from the Device Tree.

Quoted 112 lines

becomes less of a headache. You can have LPDDR3/DDR3, and/or LPDDR4, and it gets easier in the Kconfig symbols.

I quickly came up with (didn't test aside building):

"""

drivers/ram/rockchip/sdram_rk3399.c +1 -1
index 6fa8f268770d..22d196f1bec7 100644
@@ -1632,7 +1632,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)
+#if defined(CONFIG_RAM_ROCKCHIP_LPDDR3) ||
 defined(CONFIG_RAM_ROCKCHIP_DDR3)
  static int data_training_first(struct dram_info *dram, u32 channel, u8

rank,
struct rk3399_sdram_params *params)
{

drivers/ram/rockchip/sdram_rk3399.c +16 -8
@@ -1723,7 +1723,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
+
+#if defined(CONFIG_RAM_ROCKCHIP_LPDDR4)
 
  struct rk3399_sdram_params dfs_cfgs_lpddr4[] = {
  #include "sdram-rk3399-lpddr4-400.inc"
@@ -2964,9 +2966,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;
@@ -3067,19 +3071,23 @@ 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_LPDDR3) ||
 defined(CONFIG_RAM_ROCKCHIP_DDR3)
+static const struct sdram_rk3399_ops rk3399_lpddr3_ddr3_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)
  {
drivers/ram/rockchip/sdram_rk3399.c +15 -1
@@ -3098,7 +3106,21 @@ static int rk3399_dmc_init(struct udevice *dev)
                return ret;
  #endif
 
-       priv->ops = &rk3399_ops;
+#if defined(CONFIG_RAM_ROCKCHIP_LPDDR4)
+       if (params->base.dramtype == LPDDR4)
+               priv->ops = &rk3399_lpddr4_ops;
+#endif
+#if defined(CONFIG_RAM_ROCKCHIP_LPDDR3) ||
 defined(CONFIG_RAM_ROCKCHIP_DDR3)
+       if (params->base.dramtype == LPDDR3 || params->base.dramtype == DDR3)
+               priv->ops = &rk3399_lpddr3_ddr3_ops;
+#endif
+
+       if (priv->ops == NULL) {
+               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);

"""

Of course, we need to update the existing defconfigs to reflect that change as !LPDDR4 used to mean LPDDR3/DDR3 but not anymore. An intermediary step could be to have DDR3/LPDDR3 default y if !LPDDR4 so we avoid changing the defconfigs with the driver patch, and then remove the default y in a follow-up commit by making the rk3399 defconfigs enable the appropriate one (easy to find based on the Device Tree they include).

Quoted 6 lines

Finally, with the above diff, you can technically build the RK3399 driver without any of LPDDR3/DDR3/DDR4 enabled, which can be remediated by an ifdef check at the top like you've done for PX30/RV1126, just that we *want* to check that their sum is NOT 0, anything else would be fine.

What do you think?

I look at the RK3399 driver code and at its repository history to provide a well-founded answer and... honestly, it seems to me a mess. The driver was born to support all SDRAM types at the same time. Then the LPDDR4 config option was added by commit b6cf08949d4 because "Supporting LPDDR4 code support in RK3399 would increases the size of SPL/TPL", and the related ifdeffery followed. But a lot of LPDDR4 code was already there, and has been left in the common area, instead of being reorganized properly. Seems everybody added on top, instead of looking to redesign the driver.

What happens if the driver is built for LPDDR4 only and the value of dramtype read from Device Tree is DDR3 or LPDDR3? Or vice versa? The simplest thing I would expect is for the driver to print an error and stop. It doesn't. Instead, it goes on, without happy ending I suppose.

Another example: looking here and there I came across the gstride_type variable in the calculate_stride() function: is it there something magic I cannot understand? I see a local variable initialized and then used for comparisons, which are all necessarily false.

In the end, I wouldn't touch it. But if you prefer, I can integrate in this series the changes you suggested above, adding the defaults y if !LPDDR4 and the check for NOT 0.

Regards,
Massimo

Quoted 3 lines

Cheers,
Quentin