device/dram: Add kconfig options for memory types

Currently, we're building support for all memory types into every board,
and letting the linker remove anything that isn't needed. This is okay,
but it'd be nice to be able to build in just what's actually needed.

This change adds options to specify both what is used and what is not.
By doing it that way, the default values don't change, but platforms can
start removing support for memory types that are not needed.  When all
platforms (SoCs, CPUs and/or Northbridge chips) specify what memory
types they support, the defaults on the options to use a particular
memory type can be set to no, and the options not to use a memory type
can be removed.

Signed-off-by: Martin Roth <gaumless@gmail.com>
Change-Id: I07c98a702e0d67c5ad7bd9b8a4ff24c9288ab569
Reviewed-on: https://review.coreboot.org/c/coreboot/+/68992
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Eric Lai <eric_lai@quanta.corp-partner.google.com>
diff --git a/src/device/Kconfig b/src/device/Kconfig
index c0ba3d1..60ee047 100644
--- a/src/device/Kconfig
+++ b/src/device/Kconfig
@@ -953,4 +953,6 @@
 	help
 	  Provides xHCI utility functions.
 
+source "src/device/dram/Kconfig"
+
 endmenu
diff --git a/src/device/dram/Kconfig b/src/device/dram/Kconfig
new file mode 100644
index 0000000..7bb1dab
--- /dev/null
+++ b/src/device/dram/Kconfig
@@ -0,0 +1,57 @@
+## SPDX-License-Identifier: GPL-2.0-only
+
+# Short-term plan: Start adding 'USE_' and "NO_" options to each chip.
+#
+# Long-term plan: Every SoC or chipset should select the memory types they
+# use. When they all select their memory, the 'no_' options can be removed
+# and the defaults for all memory types can be set to n.
+
+config NO_DDR5
+	bool
+
+config NO_LPDDR4
+	bool
+
+config NO_DDR4
+	bool
+
+config NO_DDR3
+	bool
+
+config NO_DDR2
+	bool
+
+config USE_DDR5
+	bool
+	default n if NO_DDR5
+	default y
+	help
+	  system supports DDR5 memory
+
+config USE_LPDDR4
+	bool
+	default n if NO_LPDDR4
+	default y
+	help
+	  system supports LPDDR4 memory
+
+config USE_DDR4
+	bool
+	default n if NO_DDR4
+	default y
+	help
+	  system supports DDR4 memory
+
+config USE_DDR3
+	bool
+	default n if NO_DDR3
+	default y
+	help
+	  system supports DDR3 memory
+
+config USE_DDR2
+	bool
+	default n if NO_DDR2
+	default y
+	help
+	  system supports DDR2 memory
diff --git a/src/device/dram/Makefile.inc b/src/device/dram/Makefile.inc
index 31dfb91..fc472ea 100644
--- a/src/device/dram/Makefile.inc
+++ b/src/device/dram/Makefile.inc
@@ -1,3 +1,18 @@
-romstage-y += ddr5.c lpddr4.c ddr4.c ddr3.c ddr2.c ddr_common.c
 
-ramstage-y += ddr5.c lpddr4.c ddr4.c ddr3.c ddr2.c ddr_common.c spd.c
+romstage-y += ddr_common.c
+ramstage-y += ddr_common.c spd.c
+
+romstage-$(CONFIG_USE_DDR5) += ddr5.c
+ramstage-$(CONFIG_USE_DDR5) += ddr5.c
+
+romstage-$(CONFIG_USE_LPDDR4) += lpddr4.c
+ramstage-$(CONFIG_USE_LPDDR4) += lpddr4.c
+
+romstage-$(CONFIG_USE_DDR4) += ddr4.c
+ramstage-$(CONFIG_USE_DDR4) += ddr4.c
+
+romstage-$(CONFIG_USE_DDR3) += ddr3.c
+ramstage-$(CONFIG_USE_DDR3) += ddr3.c
+
+romstage-$(CONFIG_USE_DDR2) += ddr2.c
+ramstage-$(CONFIG_USE_DDR2) += ddr2.c